diff --git a/docs/multimedia.md b/docs/multimedia.md index b08884c59..c7f52cb31 100644 --- a/docs/multimedia.md +++ b/docs/multimedia.md @@ -960,7 +960,7 @@ JavDB 有多个备用域名,本路由默认使用永久域名 + 如:雪国列车(剧版)的下载页 URL 为 `https://ysfx.tv/view/qEzRyY3v.html`,即剧集 id 为 `qEzRyY3v`。 diff --git a/lib/v2/newzmz/index.js b/lib/v2/newzmz/index.js index 240acaaf9..2caaf1753 100644 --- a/lib/v2/newzmz/index.js +++ b/lib/v2/newzmz/index.js @@ -1,79 +1,90 @@ 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 category = parseInt(ctx.params.category || '1'); + const category = ctx.params.category ? parseInt(ctx.params.category) : 1; const rootUrl = 'http://newzmz.com'; + const rootSUrl = 'http://s.newzmz.com'; + const currentUrl = `${rootUrl}/index.html`; + const response = await got({ method: 'get', - url: `${rootUrl}/index.html`, + url: currentUrl, }); const $ = cheerio.load(response.data); - const target = $('.rowMod').eq(category); - const links = await Promise.all( + const items = []; + + const target = $('div.rowMod').eq(category); + + await Promise.all( target - .find('.slides li a') - .map((_, item) => { + .find('ul.slides li a') + .toArray() + .map((item) => { item = $(item); return { title: item.text(), - link: `${rootUrl}${item.attr('href')}`, + link: `${rootSUrl}/view/${item.attr('href').split('/details-').pop()}`, }; }) - .get() .map((item) => ctx.cache.tryGet(item.link, async () => { - const resourceResponse = await got({ + const detailResponse = await got({ method: 'get', url: item.link, }); - const $ = cheerio.load(resourceResponse.data); - item.link = $('.addgz').attr('href').replace('http:', 'https:'); - item.pubDate = parseDate( - $('.duration') - .not('.upday') - .text() - .replace(/更新时间:/, '') + const content = cheerio.load(detailResponse.data); + + const title = content('.page-header-content').text(); + + items.push( + ...content('div.team-con-area') + .toArray() + .map((a) => { + a = content(a); + + const episode = a + .find('span.up') + .text() + .trim() + .replace(/第 (\d+) /g, '第$1'); + + return { + link: item.link, + guid: `${item.link}#${episode.replace(/\s*/g, '')}`, + title: `${title} ${episode}`, + category: a + .find('div.item-label a') + .toArray() + .map((l) => content(l).text()), + description: art(path.join(__dirname, 'templates/description.art'), { + links: a + .find('ul.team-icons li') + .toArray() + .map((i) => ({ + name: content(i).find('p').text(), + link: content(i).find('a').attr('href'), + })), + }), + enclosure_type: 'application/x-bittorrent', + enclosure_url: a.find('a[title="磁力链下载"]').attr('href'), + }; + }) ); - - return item; }) ) ); - const items = await Promise.all( - links.map((item) => - ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - const content = cheerio.load(detailResponse.data); - - content('img, .link-name').remove(); - - content('a[title]').each(function () { - content(this).text(content(this).attr('title')); - }); - - item.description = content('.faq--area').html(); - item.enclosure_type = 'application/x-bittorrent'; - item.enclosure_url = content('a[title="磁力链下载"]').attr('href'); - - return item; - }) - ) - ); - ctx.state.data = { - title: `${target.find('.row-header-title').text()} - NEW字幕组`, - link: rootUrl, + title: `NEW字幕组 - ${target.find('.row-header-title').text()}`, + link: currentUrl, item: items, }; }; diff --git a/lib/v2/newzmz/maintainer.js b/lib/v2/newzmz/maintainer.js index b8bcccd1f..b39b0bddc 100644 --- a/lib/v2/newzmz/maintainer.js +++ b/lib/v2/newzmz/maintainer.js @@ -1,4 +1,4 @@ module.exports = { '/:category?': ['nczitzk'], - '/view/:id?': ['nczitzk'], + '/:id?': ['nczitzk'], }; diff --git a/lib/v2/newzmz/radar.js b/lib/v2/newzmz/radar.js index 4c2ee871f..41fabd11b 100644 --- a/lib/v2/newzmz/radar.js +++ b/lib/v2/newzmz/radar.js @@ -12,7 +12,7 @@ module.exports = { title: '指定剧集', docs: 'https://docs.rsshub.app/multimedia.html#new-zi-mu-zu', source: ['/view/:id'], - target: (params) => `/newzmz/view/${params.id.replace('.html', '')}`, + target: (params) => `/newzmz/${params.id.replace('.html', '')}`, }, ], }, diff --git a/lib/v2/newzmz/router.js b/lib/v2/newzmz/router.js index d2d91824b..81adfde3b 100644 --- a/lib/v2/newzmz/router.js +++ b/lib/v2/newzmz/router.js @@ -1,4 +1,5 @@ module.exports = (router) => { - router.get('/:category?', require('./index')); + router.get(/\/(\d+)?/, require('./index')); router.get('/view/:id', require('./view')); + router.get('/:id', require('./view')); }; diff --git a/lib/v2/newzmz/templates/description.art b/lib/v2/newzmz/templates/description.art new file mode 100644 index 000000000..7ff8be92d --- /dev/null +++ b/lib/v2/newzmz/templates/description.art @@ -0,0 +1,7 @@ +{{ if links }} + +{{ /if }} \ No newline at end of file diff --git a/lib/v2/newzmz/view.js b/lib/v2/newzmz/view.js index 58851ec85..48f9d0753 100644 --- a/lib/v2/newzmz/view.js +++ b/lib/v2/newzmz/view.js @@ -1,5 +1,7 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const { art } = require('@/utils/render'); +const path = require('path'); module.exports = async (ctx) => { const id = ctx.params.id; @@ -11,32 +13,45 @@ module.exports = async (ctx) => { method: 'get', url: currentUrl, }); + const $ = cheerio.load(response.data); - $('img, .link-name').remove(); - - $('a[title]').each(function () { - $(this).text($(this).attr('title')); - }); - - const list = $('.team-con-area') - .map((_, item) => { + const items = $('div.team-con-area') + .toArray() + .map((item) => { item = $(item); - const link = item.find('a[data-target="#down-modal"]').eq(0).attr('href'); + + const episode = item + .find('span.up') + .text() + .trim() + .replace(/第 (\d+) /g, '第$1'); return { - link, - enclosure_url: link, + link: currentUrl, + guid: `${currentUrl}#${episode.replace(/\s*/g, '')}`, + title: episode, + category: item + .find('div.item-label a') + .toArray() + .map((l) => $(l).text()), + description: art(path.join(__dirname, 'templates/description.art'), { + links: item + .find('ul.team-icons li') + .toArray() + .map((i) => ({ + name: $(i).find('p').text(), + link: $(i).find('a').attr('href'), + })), + }), enclosure_type: 'application/x-bittorrent', - title: item.find('.item-content').text(), - description: ``, + enclosure_url: item.find('a[title="磁力链下载"]').attr('href'), }; - }) - .get(); + }); ctx.state.data = { - title: `${$('.page-header-content .title').text()} - NEW字幕组`, + title: `NEW字幕组 - ${$('.page-header-content').text()}`, link: currentUrl, - item: list, + item: items, }; };