diff --git a/lib/routes-deprecated/iplay/home.js b/lib/routes-deprecated/iplay/home.js deleted file mode 100644 index f879546e9b..0000000000 --- a/lib/routes-deprecated/iplay/home.js +++ /dev/null @@ -1,26 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const util = require('./utils'); - -module.exports = async (ctx) => { - const url = `https://www.iplaysoft.com/`; - const response = await got({ - method: 'get', - url, - headers: { - Referer: url, - }, - }); - - const $ = cheerio.load(response.data); - const list = $('#postlist .entry').get(); - - const result = await util.ProcessFeed(list, ctx.cache); - - ctx.state.data = { - title: $('title').text().split('-')[0], - link: url, - description: $('meta[name="description"]').attr('content'), - item: result, - }; -}; diff --git a/lib/routes-deprecated/iplay/utils.js b/lib/routes-deprecated/iplay/utils.js deleted file mode 100644 index 01a698d58d..0000000000 --- a/lib/routes-deprecated/iplay/utils.js +++ /dev/null @@ -1,57 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const url = require('url'); - -async function load(link) { - const response = await got.get(link); - const $ = cheerio.load(response.data); - // 处理日期 - const datestr = $('.entry-meta li') - .text() - .match(/生产日期:异次纪元 ([\S\s]*?秒)/)[1] - .match(/(\d{1,2})/gm); - for (let i = 1; i < datestr.length; i++) { - datestr[i] = datestr[i].padStart(2, '0'); - } - const date = new Date('20' + datestr[0] + '-' + datestr[1] + '-' + datestr[2] + ' ' + datestr[3] + ':' + datestr[4] + ':' + datestr[5]); - const timeZone = 8; - const serverOffset = date.getTimezoneOffset() / 60; - const pubDate = new Date(date.getTime() - 60 * 60 * 1000 * (timeZone + serverOffset)).toUTCString(); - // 提取详情 - let description = $('.entry-content').html(); - // 去除data-srcset,srcset,将data-src替换成src以正常显示图片 - description = description.replaceAll(/(data-){0,1}srcset="[\S\s]*?"/g, ''); - description = description.replaceAll('data-src', 'src'); - return { description, pubDate }; -} - -const ProcessFeed = (list, caches) => { - const host = 'https://www.iplaysoft.com/'; - return Promise.all( - list.map(async (item) => { - const $ = cheerio.load(item); - const $title = $('.entry-title a'); - // 还原相对链接为绝对链接 - const itemUrl = url.resolve(host, $title.attr('href')); - - // 列表上提取到的信息 - const single = { - title: $title.text(), - link: itemUrl, - // author: $('.nickname').text(), - guid: itemUrl, - }; - - // 使用tryGet方法从缓存获取内容。 - // 当缓存中无法获取到链接内容的时候,则使用load方法加载文章内容。 - const other = await caches.tryGet(itemUrl, () => load(itemUrl)); - - // 合并解析后的结果集作为该篇文章最终的输出结果 - return Object.assign({}, single, other); - }) - ); -}; - -module.exports = { - ProcessFeed, -}; diff --git a/lib/routes/iplaysoft/index.ts b/lib/routes/iplaysoft/index.ts new file mode 100644 index 0000000000..53b4721bc1 --- /dev/null +++ b/lib/routes/iplaysoft/index.ts @@ -0,0 +1,68 @@ +import cache from '@/utils/cache'; +import { load } from 'cheerio'; +import { parseDate } from '@/utils/parse-date'; +import { DataItem, Route } from '@/types'; +import ofetch from '@/utils/ofetch'; +import parser from '@/utils/rss-parser'; + +export const route: Route = { + path: '/', + categories: ['program-update'], + example: '/iplaysoft', + parameters: {}, + features: { + requireConfig: false, + requirePuppeteer: false, + antiCrawler: false, + supportBT: false, + supportPodcast: false, + supportScihub: false, + }, + radar: [ + { + source: ['www.iplaysoft.com'], + }, + ], + name: '全部文章', + maintainers: ['williamgateszhao'], + handler, +}; + +async function handler(ctx) { + const feed = await parser.parseURL('https://www.iplaysoft.com/feed/atom'); + const filteredItems = feed.items + .filter((item) => item?.link && item?.pubDate && new URL(item.link).hostname.match(/.*\.iplaysoft\.com$/)) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 20) as DataItem[]; + + const items: DataItem[] = await Promise.all( + filteredItems.map( + (item) => + cache.tryGet(item.link as string, async () => { + const response = await ofetch(item.link as string); + const $ = load(response); + const content = $('.entry-content'); + content + .find('div') + .filter((_index, element) => { + const style = $(element).attr('style'); + return style !== undefined && style.includes('overflow:hidden'); + }) + .remove(); + return { + title: item.title, + description: content.html(), + link: item.link, + author: item.author, + pubDate: parseDate(item.pubDate as string), + } as DataItem; + }) as Promise + ) + ); + + return { + title: '异次元软件世界', + link: 'https://www.iplaysoft.com', + language: 'zh-CN', + item: items, + }; +} diff --git a/lib/routes/iplaysoft/namespace.ts b/lib/routes/iplaysoft/namespace.ts new file mode 100644 index 0000000000..5ef84363be --- /dev/null +++ b/lib/routes/iplaysoft/namespace.ts @@ -0,0 +1,6 @@ +import type { Namespace } from '@/types'; + +export const namespace: Namespace = { + name: '异次元软件世界', + url: 'www.iplaysoft.com', +};