From 2ae299f978908f1c95220ef6de5da5583b4462e7 Mon Sep 17 00:00:00 2001 From: Tony Date: Wed, 1 Feb 2023 17:06:25 +0000 Subject: [PATCH] fix(route): iqiyi album (#11753) --- docs/multimedia.md | 12 ++++-- lib/router.js | 4 +- lib/routes/iqiyi/dongman.js | 42 --------------------- lib/v2/iqiyi/album.js | 62 +++++++++++++++++++++++++++++++ lib/v2/iqiyi/maintainer.js | 4 ++ lib/v2/iqiyi/radar.js | 24 ++++++++++++ lib/v2/iqiyi/router.js | 4 ++ lib/v2/iqiyi/templates/album.art | 1 + lib/{routes => v2}/iqiyi/video.js | 0 9 files changed, 106 insertions(+), 47 deletions(-) delete mode 100644 lib/routes/iqiyi/dongman.js create mode 100644 lib/v2/iqiyi/album.js create mode 100644 lib/v2/iqiyi/maintainer.js create mode 100644 lib/v2/iqiyi/radar.js create mode 100644 lib/v2/iqiyi/router.js create mode 100644 lib/v2/iqiyi/templates/album.art rename lib/{routes => v2}/iqiyi/video.js (100%) diff --git a/docs/multimedia.md b/docs/multimedia.md index 852477256..44ec929c9 100644 --- a/docs/multimedia.md +++ b/docs/multimedia.md @@ -1211,11 +1211,17 @@ JavDB 有多个备用域名,本路由默认使用永久域名 + -### 动漫 +### 剧集 - + + +::: tip 提示 +可抓取內容根据服务器所在地区而定 +::: + + ## 哔嘀影视 diff --git a/lib/router.js b/lib/router.js index 317c6dbe1..12ea0f83a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -176,8 +176,8 @@ router.get('/geektime/news', lazyloadRouteHandler('./routes/geektime/news')); router.get('/qdaily/:type/:id', lazyloadRouteHandler('./routes/qdaily/index')); // 爱奇艺 -router.get('/iqiyi/dongman/:id', lazyloadRouteHandler('./routes/iqiyi/dongman')); -router.get('/iqiyi/user/video/:uid', lazyloadRouteHandler('./routes/iqiyi/video')); +// router.get('/iqiyi/dongman/:id', lazyloadRouteHandler('./routes/iqiyi/dongman')); +// router.get('/iqiyi/user/video/:uid', lazyloadRouteHandler('./routes/iqiyi/video')); // 南方周末 router.get('/infzm/:id', lazyloadRouteHandler('./routes/infzm/news')); diff --git a/lib/routes/iqiyi/dongman.js b/lib/routes/iqiyi/dongman.js deleted file mode 100644 index d7f7de0fd..000000000 --- a/lib/routes/iqiyi/dongman.js +++ /dev/null @@ -1,42 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -module.exports = async (ctx) => { - const id = ctx.params.id; - - const response = await got({ - method: 'get', - url: `http://www.iqiyi.com/${id}.html`, - headers: { - Host: 'www.iqiyi.com', - Referer: `http://www.iqiyi.com/${id}.html`, - }, - }); - - const data = response.data; - const $ = cheerio.load(data); - const description = $('.episodeIntro-brief').text(); - const list = $('li[data-albumlist-elem="playItem"]'); - - ctx.state.data = { - title: $('title').text().split('-')[0], - link: `http://www.iqiyi.com/${id}.html`, - description, - item: - list && - list - .map((index, item) => { - const episode = $(item).find('p.site-piclist_info_title a').text().trim(); - const describe = $(item).find('p.site-piclist_info_describe a').text(); - const title = `${episode}-${describe}`; - - return { - title, - description: ``, - link: $(item).find('.site-piclist_pic .site-piclist_pic_link').attr('href'), - }; - }) - .get() - .reverse(), - }; -}; diff --git a/lib/v2/iqiyi/album.js b/lib/v2/iqiyi/album.js new file mode 100644 index 000000000..a928bd50d --- /dev/null +++ b/lib/v2/iqiyi/album.js @@ -0,0 +1,62 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const { id } = ctx.params; + + const { data: response } = await got(`https://www.iq.com/album/${id}`); + + const $ = cheerio.load(response); + const nextData = JSON.parse($('#__NEXT_DATA__').text()); + const { album } = nextData.props.initialState; + + const { + data: { data: baseInfo }, + } = await got(`https://pcw-api.iqiyi.com/album/album/baseinfo/${album.videoAlbumInfo.albumId}`); + + if (Object.keys(album.cacheAlbumList).length === 0) { + throw Error(`${baseInfo.name} is not available in this server region.`); + } + + let pos = 1; + let hasMore = false; + let epgs = []; + do { + const { + data: { data }, + // eslint-disable-next-line no-await-in-loop + } = await got(`https://pcw-api.iq.com/api/v2/episodeListSource/${album.videoAlbumInfo.albumId}`, { + searchParams: { + platformId: 3, + modeCode: 'intl', + langCode: 'zh_cn', + endOrder: album.videoAlbumInfo.maxOrder, + startOrder: pos, + }, + }); + epgs = [...epgs, ...data.epg]; + pos = data.pos; + hasMore = data.hasMore; + } while (hasMore); + + const items = epgs.map((item) => ({ + title: item.name, + description: art(path.join(__dirname, 'templates/album.art'), { + item, + }), + link: `https://www.iq.com/play/${item.playLocSuffix}`, + pubDate: parseDate(item.initIssueTime), + })); + + ctx.state.data = { + title: baseInfo.name, + description: baseInfo.description, + image: album.videoAlbumInfo.albumFocus1024, + link: `https://www.iq.com/album/${album.videoAlbumInfo.albumLocSuffix}`, + item: items, + allowEmpty: true, + }; +}; diff --git a/lib/v2/iqiyi/maintainer.js b/lib/v2/iqiyi/maintainer.js new file mode 100644 index 000000000..c66416882 --- /dev/null +++ b/lib/v2/iqiyi/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/album/:id': ['TonyRL'], + '/user/video/:uid': ['talengu'], +}; diff --git a/lib/v2/iqiyi/radar.js b/lib/v2/iqiyi/radar.js new file mode 100644 index 000000000..6bc0f95db --- /dev/null +++ b/lib/v2/iqiyi/radar.js @@ -0,0 +1,24 @@ +module.exports = { + 'iq.com': { + _name: '爱奇艺', + '.': [ + { + title: '剧集', + docs: 'https://docs.rsshub.app/multimedia.html#ai-qi-yi', + source: ['/album/:id'], + target: '/iqiyi/:category/:id', + }, + ], + }, + 'iqiyi.com': { + _name: '爱奇艺', + '.': [ + { + title: '用户视频', + docs: 'https://docs.rsshub.app/multimedia.html#ai-qi-yi', + source: ['/u/:uid/*'], + target: '/iqiyi/user/video/:uid', + }, + ], + }, +}; diff --git a/lib/v2/iqiyi/router.js b/lib/v2/iqiyi/router.js new file mode 100644 index 000000000..126505fcb --- /dev/null +++ b/lib/v2/iqiyi/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/album/:id', require('./album')); + router.get('/user/video/:uid', require('./video')); +}; diff --git a/lib/v2/iqiyi/templates/album.art b/lib/v2/iqiyi/templates/album.art new file mode 100644 index 000000000..14b1e8dd5 --- /dev/null +++ b/lib/v2/iqiyi/templates/album.art @@ -0,0 +1 @@ + diff --git a/lib/routes/iqiyi/video.js b/lib/v2/iqiyi/video.js similarity index 100% rename from lib/routes/iqiyi/video.js rename to lib/v2/iqiyi/video.js