From 5ef2466ce2a5f1dbacec6af26b1f819ec7599f16 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sat, 27 Nov 2021 17:12:20 +0800 Subject: [PATCH] fix(route): JavDB (#8578) --- docs/multimedia.md | 32 ++++++++--- lib/router.js | 16 +++--- lib/routes/javdb/utils.js | 82 ---------------------------- lib/{routes => v2}/javdb/actors.js | 4 +- lib/{routes => v2}/javdb/index.js | 6 +- lib/v2/javdb/maintainer.js | 10 ++++ lib/{routes => v2}/javdb/makers.js | 4 +- lib/v2/javdb/radar.js | 49 +++++++++++++++++ lib/{routes => v2}/javdb/rankings.js | 4 +- lib/v2/javdb/router.js | 10 ++++ lib/{routes => v2}/javdb/search.js | 6 +- lib/{routes => v2}/javdb/series.js | 4 +- lib/{routes => v2}/javdb/tags.js | 4 +- lib/v2/javdb/utils.js | 73 +++++++++++++++++++++++++ 14 files changed, 191 insertions(+), 113 deletions(-) delete mode 100644 lib/routes/javdb/utils.js rename lib/{routes => v2}/javdb/actors.js (77%) rename lib/{routes => v2}/javdb/index.js (83%) create mode 100644 lib/v2/javdb/maintainer.js rename lib/{routes => v2}/javdb/makers.js (79%) create mode 100644 lib/v2/javdb/radar.js rename lib/{routes => v2}/javdb/rankings.js (70%) create mode 100644 lib/v2/javdb/router.js rename lib/{routes => v2}/javdb/search.js (77%) rename lib/{routes => v2}/javdb/series.js (79%) rename lib/{routes => v2}/javdb/tags.js (75%) create mode 100644 lib/v2/javdb/utils.js diff --git a/docs/multimedia.md b/docs/multimedia.md index 247288f2d..7d0062cf7 100644 --- a/docs/multimedia.md +++ b/docs/multimedia.md @@ -379,9 +379,27 @@ BT 之家的域名会变更,本路由以 为默认 ## JavDB +::: tip 提示 + +JavDB 有多个备用域名,本路由以 为默认域名,若该域名无法访问,可以通过在路由后方加上 `?domain=<域名>` 指定路由访问的域名。如指定域名为 ,则在所有 JavDB 路由后加上 `?domain=javdb.com` 即可,此时路由为 [`/javdb?domain=javdb.com`](https://rsshub.app/javdb?domain=javdb.com) + +如果加入了 **分類** 参数,直接在分類参数后加入 `?domain=<域名>` 即可。如指定分類 URL 为 并指定域名为 ,即在 `/javdb/tags/c2=5&c10=1` 后加上 `?domain=javdb.com`,此时路由为 [`/javdb/tags/c2=5&c10=1?domain=javdb.com`](https://rsshub.app/javdb/tags/c2=5&c10=1?domain=javdb.com) + +**排行榜**、**搜索**、**演員**、**片商** 参数同适用于 **分類** 参数的上述规则 + +::: + +::: tip 提示 + +你可以通过指定 `limit` 参数来获取特定数量的条目,即可以通过在路由后方加上 `?limit=25`,默认为单次获取 20 个条目,即默认 `?limit=20` + +因为该站有反爬检测,所以不应将此值调整过高 + +::: + ### 主页 - + 分类 @@ -405,7 +423,7 @@ BT 之家的域名会变更,本路由以 为默认 ### 分類 - + ::: tip 提示 @@ -425,7 +443,7 @@ BT 之家的域名会变更,本路由以 为默认 ### 排行榜 - + 分类 @@ -443,7 +461,7 @@ BT 之家的域名会变更,本路由以 为默认 ### 搜索 - + | 全部 | 可播放 | 單體作品 | 演員 | 片商 | 導演 | 系列 | 番號 | 可下載 | 字幕 | 預覽圖 | | ---- | -------- | -------- | ----- | ----- | -------- | ------ | ---- | -------- | ----- | ------- | @@ -453,7 +471,7 @@ BT 之家的域名会变更,本路由以 为默认 ### 演員 - + | 全部 | 可播放 | 單體作品 | 可下載 | 含字幕 | | ---- | ------ | -------- | ------ | ------ | @@ -465,7 +483,7 @@ BT 之家的域名会变更,本路由以 为默认 ### 系列 - + | 全部 | 可播放 | 單體作品 | 可下載 | 字幕 | 預覽圖 | | ---- | -------- | -------- | -------- | ----- | ------- | @@ -477,7 +495,7 @@ BT 之家的域名会变更,本路由以 为默认 ### 片商 - + | 全部 | 可播放 | 單體作品 | 可下載 | 字幕 | 預覽圖 | | ---- | -------- | -------- | -------- | ----- | ------- | diff --git a/lib/router.js b/lib/router.js index 8b1855994..3be263790 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3443,14 +3443,14 @@ router.get('/mercari/:type/:id', lazyloadRouteHandler('./routes/mercari/index')) router.get('/notefolio/:caty?/:order?/:time?/:query?', lazyloadRouteHandler('./routes/notefolio/index')); // JavDB -router.get('/javdb/home/:category?/:sort?/:filter?', lazyloadRouteHandler('./routes/javdb')); -router.get('/javdb/search/:keyword?/:filter?', lazyloadRouteHandler('./routes/javdb/search')); -router.get('/javdb/tags/:query?/:caty?', lazyloadRouteHandler('./routes/javdb/tags')); -router.get('/javdb/actors/:id/:filter?', lazyloadRouteHandler('./routes/javdb/actors')); -router.get('/javdb/makers/:id/:filter?', lazyloadRouteHandler('./routes/javdb/makers')); -router.get('/javdb/series/:id/:filter?', lazyloadRouteHandler('./routes/javdb/series')); -router.get('/javdb/rankings/:caty?/:time?', lazyloadRouteHandler('./routes/javdb/rankings')); -router.get('/javdb/:category?/:sort?/:filter?', lazyloadRouteHandler('./routes/javdb')); +// router.get('/javdb/home/:category?/:sort?/:filter?', lazyloadRouteHandler('./routes/javdb')); +// router.get('/javdb/search/:keyword?/:filter?', lazyloadRouteHandler('./routes/javdb/search')); +// router.get('/javdb/tags/:query?/:caty?', lazyloadRouteHandler('./routes/javdb/tags')); +// router.get('/javdb/actors/:id/:filter?', lazyloadRouteHandler('./routes/javdb/actors')); +// router.get('/javdb/makers/:id/:filter?', lazyloadRouteHandler('./routes/javdb/makers')); +// router.get('/javdb/series/:id/:filter?', lazyloadRouteHandler('./routes/javdb/series')); +// router.get('/javdb/rankings/:caty?/:time?', lazyloadRouteHandler('./routes/javdb/rankings')); +// router.get('/javdb/:category?/:sort?/:filter?', lazyloadRouteHandler('./routes/javdb')); // World Economic Forum router.get('/weforum/report/:lang?/:year?/:platform?', lazyloadRouteHandler('./routes/weforum/report')); diff --git a/lib/routes/javdb/utils.js b/lib/routes/javdb/utils.js deleted file mode 100644 index a38ea0c67..000000000 --- a/lib/routes/javdb/utils.js +++ /dev/null @@ -1,82 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); - -let rootUrl = 'https://javdb.com'; - -module.exports = { - ProcessItems: async (ctx, currentUrl, title) => { - let data; - - try { - const response = await got({ - method: 'get', - url: `${rootUrl}${currentUrl}`, - }); - data = response.data; - } catch (err) { - rootUrl = rootUrl.replace('javdb', 'javdb7'); - const response = await got({ - method: 'get', - url: `${rootUrl}${currentUrl}`, - }); - data = response.data; - } - - const $ = cheerio.load(data); - - $('.tags').remove(); - - const list = $('.grid-item a') - .slice(0, 15) - .map((_, item) => { - item = $(item); - return { - title: item.text(), - link: `${rootUrl}${item.attr('href')}`, - pubDate: Date.parse(item.find('.meta').text()), - }; - }) - .get(); - - const items = await Promise.all( - list.map((item) => - ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); - - item.enclosure_url = content('#magnets-content button[data-clipboard-text]').eq(0).attr('data-clipboard-text'); - item.enclosure_type = 'application/x-bittorrent'; - - content('icon, .review-buttons, .copy-to-clipboard').remove(); - content('#modal-review-watched, #modal-save-list').remove(); - content('.video-cover').eq(1).remove(); - - content('img.video-cover').attr('src', content(this).parent().attr('href')); - - content('.preview-images img').each(function () { - content(this).removeAttr('data-src'); - content(this).attr('src', content(this).parent().attr('href')); - }); - - content('#preview-video').css('display', 'block'); - - item.description = content('.movie-info-panel .columns').html() + content('#magnets-content').html() + content('.preview-images').html(); - - return item; - }) - ) - ); - - const htmlTitle = $('title').text(); - const subject = htmlTitle.indexOf('|') === -1 ? '' : htmlTitle.split('|')[0]; - - return { - title: subject === '' ? title : `${subject} - ${title}`, - link: `${rootUrl}${currentUrl}`, - item: items, - }; - }, -}; diff --git a/lib/routes/javdb/actors.js b/lib/v2/javdb/actors.js similarity index 77% rename from lib/routes/javdb/actors.js rename to lib/v2/javdb/actors.js index cdd349407..ed4db8cbb 100644 --- a/lib/routes/javdb/actors.js +++ b/lib/v2/javdb/actors.js @@ -2,9 +2,9 @@ const utils = require('./utils'); module.exports = async (ctx) => { const id = ctx.params.id; - const filter = ctx.params.filter || ''; + const filter = ctx.params.filter ?? ''; - const currentUrl = `/actors/${id}?t=${filter}`; + const currentUrl = `/actors/${id}${filter ? `?t=${filter}` : ''}`; const filters = { '': '', diff --git a/lib/routes/javdb/index.js b/lib/v2/javdb/index.js similarity index 83% rename from lib/routes/javdb/index.js rename to lib/v2/javdb/index.js index de8771983..fdc13900f 100644 --- a/lib/routes/javdb/index.js +++ b/lib/v2/javdb/index.js @@ -1,9 +1,9 @@ const utils = require('./utils'); module.exports = async (ctx) => { - const category = ctx.params.caty || 'censored'; - const sort = ctx.params.sort || '2'; - const filter = ctx.params.filter || '1'; + const category = ctx.params.category ?? 'censored'; + const sort = ctx.params.sort ?? '2'; + const filter = ctx.params.filter ?? '1'; const currentUrl = `${category === 'censored' ? '' : category}?vft=${filter}&vst=${sort}`; diff --git a/lib/v2/javdb/maintainer.js b/lib/v2/javdb/maintainer.js new file mode 100644 index 000000000..da4b193a0 --- /dev/null +++ b/lib/v2/javdb/maintainer.js @@ -0,0 +1,10 @@ +module.exports = { + '/home/:category?/:sort?/:filter?': ['nczitzk'], + '/search/:keyword?/:filter?': ['nczitzk'], + '/tags/:query?/:category?': ['nczitzk'], + '/actors/:id/:filter?': ['nczitzk'], + '/makers/:id/:filter?': ['nczitzk'], + '/series/:id/:filter?': ['nczitzk'], + '/rankings/:category?/:time?': ['nczitzk'], + '/:category?/:sort?/:filter?': ['nczitzk'], +}; diff --git a/lib/routes/javdb/makers.js b/lib/v2/javdb/makers.js similarity index 79% rename from lib/routes/javdb/makers.js rename to lib/v2/javdb/makers.js index d66154dfa..77a6b1b57 100644 --- a/lib/routes/javdb/makers.js +++ b/lib/v2/javdb/makers.js @@ -2,9 +2,9 @@ const utils = require('./utils'); module.exports = async (ctx) => { const id = ctx.params.id; - const filter = ctx.params.filter || ''; + const filter = ctx.params.filter ?? ''; - const currentUrl = `/makers/${id}?f=${filter}`; + const currentUrl = `/makers/${id}${filter ? `?f=${filter}` : ''}`; const filters = { '': '', diff --git a/lib/v2/javdb/radar.js b/lib/v2/javdb/radar.js new file mode 100644 index 000000000..37b475bd2 --- /dev/null +++ b/lib/v2/javdb/radar.js @@ -0,0 +1,49 @@ +module.exports = { + 'javdb.com': { + _name: 'JavDB', + '.': [ + { + title: '主页', + docs: 'https://docs.rsshub.app/multimedia.html#javdb-zhu-ye', + source: ['/'], + target: '/javdb', + }, + { + title: '分類', + docs: 'https://docs.rsshub.app/multimedia.html#javdb-fen-lei', + source: ['/tags/:category', '/'], + target: (params, url) => `/javdb/tags/:category/${new URL(url).searchParams.toString()}`, + }, + { + title: '排行榜', + docs: 'https://docs.rsshub.app/multimedia.html#javdb-pai-hang-bang', + source: ['/rankings/:category', '/'], + target: (params, url) => `/javdb/rankings/:category/${new URL(url).searchParams.get('period') ?? ''}`, + }, + { + title: '搜索', + docs: 'https://docs.rsshub.app/multimedia.html#javdb-sou-suo', + source: ['/search', '/'], + target: (params, url) => `/javdb/search/${new URL(url).searchParams.toString()}`, + }, + { + title: '演員', + docs: 'https://docs.rsshub.app/multimedia.html#javdb-yan-yuan', + source: ['/actors/:id', '/'], + target: (params, url) => `/javdb/actors/:id/${new URL(url).searchParams.toString()}`, + }, + { + title: '系列', + docs: 'https://docs.rsshub.app/multimedia.html#javdb-xi-lie', + source: ['/series/:id', '/'], + target: (params, url) => `/javdb/series/:id/${new URL(url).searchParams.toString()}`, + }, + { + title: '片商', + docs: 'https://docs.rsshub.app/multimedia.html#javdb-pian-shang', + source: ['/makers/:id', '/'], + target: (params, url) => `/javdb/makers/:id/${new URL(url).searchParams.toString()}`, + }, + ], + }, +}; diff --git a/lib/routes/javdb/rankings.js b/lib/v2/javdb/rankings.js similarity index 70% rename from lib/routes/javdb/rankings.js rename to lib/v2/javdb/rankings.js index 890462b93..1bd05dbe3 100644 --- a/lib/routes/javdb/rankings.js +++ b/lib/v2/javdb/rankings.js @@ -1,8 +1,8 @@ const utils = require('./utils'); module.exports = async (ctx) => { - const category = ctx.params.category || 'censored'; - const time = ctx.params.time || 'daily'; + const category = ctx.params.category ?? 'censored'; + const time = ctx.params.time ?? 'daily'; const currentUrl = `/rankings/video_${category}?period=${time}`; diff --git a/lib/v2/javdb/router.js b/lib/v2/javdb/router.js new file mode 100644 index 000000000..ef9ea370f --- /dev/null +++ b/lib/v2/javdb/router.js @@ -0,0 +1,10 @@ +module.exports = function (router) { + router.get('/home/:category?/:sort?/:filter?', require('./index')); + router.get('/search/:keyword?/:filter?', require('./search')); + router.get('/tags/:query?/:category?', require('./tags')); + router.get('/actors/:id/:filter?', require('./actors')); + router.get('/makers/:id/:filter?', require('./makers')); + router.get('/series/:id/:filter?', require('./series')); + router.get('/rankings/:category?/:time?', require('./rankings')); + router.get('/:category?/:sort?/:filter?', require('./index')); +}; diff --git a/lib/routes/javdb/search.js b/lib/v2/javdb/search.js similarity index 77% rename from lib/routes/javdb/search.js rename to lib/v2/javdb/search.js index 3a46e64ad..b3fc784e9 100644 --- a/lib/routes/javdb/search.js +++ b/lib/v2/javdb/search.js @@ -1,10 +1,10 @@ const utils = require('./utils'); module.exports = async (ctx) => { - const filter = ctx.params.filter || ''; - const keyword = ctx.params.keyword || ''; + const filter = ctx.params.filter ?? ''; + const keyword = ctx.params.keyword ?? ''; - const currentUrl = `/search?q=${keyword}&f=${filter}`; + const currentUrl = `/search?q=${keyword}${filter ? `&f=${filter}` : ''}`; const filters = { '': '', diff --git a/lib/routes/javdb/series.js b/lib/v2/javdb/series.js similarity index 79% rename from lib/routes/javdb/series.js rename to lib/v2/javdb/series.js index df8718ee2..fd730cae9 100644 --- a/lib/routes/javdb/series.js +++ b/lib/v2/javdb/series.js @@ -2,9 +2,9 @@ const utils = require('./utils'); module.exports = async (ctx) => { const id = ctx.params.id; - const filter = ctx.params.filter || ''; + const filter = ctx.params.filter ?? ''; - const currentUrl = `/series/${id}?f=${filter}`; + const currentUrl = `/series/${id}${filter ? `?f=${filter}` : ''}`; const filters = { '': '', diff --git a/lib/routes/javdb/tags.js b/lib/v2/javdb/tags.js similarity index 75% rename from lib/routes/javdb/tags.js rename to lib/v2/javdb/tags.js index 517e3cf13..e1691b18a 100644 --- a/lib/routes/javdb/tags.js +++ b/lib/v2/javdb/tags.js @@ -1,8 +1,8 @@ const utils = require('./utils'); module.exports = async (ctx) => { - const category = ctx.params.category || 'censored'; - const query = ctx.params.query || ''; + const category = ctx.params.category ?? 'censored'; + const query = ctx.params.query ?? ''; const currentUrl = `/tags${category === 'censored' ? '' : `/${category}`}?${query}`; diff --git a/lib/v2/javdb/utils.js b/lib/v2/javdb/utils.js new file mode 100644 index 000000000..f85ee25ef --- /dev/null +++ b/lib/v2/javdb/utils.js @@ -0,0 +1,73 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = { + ProcessItems: async (ctx, currentUrl, title) => { + const domain = ctx.query.domain ?? 'javdb7.com'; + const rootUrl = `https://${domain}`; + + const response = await got({ + method: 'get', + url: `${rootUrl}${currentUrl}`, + }); + + const $ = cheerio.load(response.data); + + $('.tags, .tag-can-play').remove(); + + let items = $('.grid-item a') + .slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 20) + .toArray() + .map((item) => { + item = $(item); + return { + title: item.text(), + link: `${rootUrl}${item.attr('href')}`, + pubDate: parseDate(item.find('.meta').text()), + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.enclosure_type = 'application/x-bittorrent'; + item.enclosure_url = content('#magnets-content button[data-clipboard-text]').first().attr('data-clipboard-text'); + + content('icon').remove(); + content('#modal-review-watched, #modal-comment-warning, #modal-save-list').remove(); + content('.review-buttons, .copy-to-clipboard, .preview-video-container, .play-button').remove(); + + content('.preview-images img').each(function () { + content(this).removeAttr('data-src'); + content(this).attr('src', content(this).parent().attr('href')); + }); + + item.category = content('.panel-block .value a') + .toArray() + .map((v) => content(v).text()); + item.author = content('.panel-block .value').last().parent().find('.value a').first().text(); + item.description = content('.cover-container, .column-video-cover').html() + content('.movie-panel-info').html() + content('#magnets-content').html() + content('.preview-images').html(); + + return item; + }) + ) + ); + + const htmlTitle = $('title').text(); + const subject = htmlTitle.indexOf('|') === -1 ? '' : htmlTitle.split('|')[0]; + + return { + title: subject === '' ? title : `${subject} - ${title}`, + link: `${rootUrl}${currentUrl}`, + item: items, + }; + }, +};