From 7111c2c97552d19a210ee56bd18511fb925e7040 Mon Sep 17 00:00:00 2001 From: Hengyu <76626546+5upernova-heng@users.noreply.github.com> Date: Thu, 23 Mar 2023 03:20:54 +0800 Subject: [PATCH] fix(route): update root url for newzmz (#12158) * fix(route): update rootUrl for newzmz * refactor: migrate to v2 --------- --- lib/router.js | 4 ++-- lib/{routes => v2}/newzmz/index.js | 13 +++++++------ lib/v2/newzmz/maintainer.js | 4 ++++ lib/v2/newzmz/radar.js | 19 +++++++++++++++++++ lib/v2/newzmz/router.js | 4 ++++ lib/{routes => v2}/newzmz/view.js | 2 +- 6 files changed, 37 insertions(+), 9 deletions(-) rename lib/{routes => v2}/newzmz/index.js (86%) create mode 100644 lib/v2/newzmz/maintainer.js create mode 100644 lib/v2/newzmz/radar.js create mode 100644 lib/v2/newzmz/router.js rename lib/{routes => v2}/newzmz/view.js (96%) diff --git a/lib/router.js b/lib/router.js index dd826faf9baa82..9a01d5a09696bf 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3696,8 +3696,8 @@ router.get('/gab/user/:username', lazyloadRouteHandler('./routes/gab/user')); router.get('/gab/popular/:sort?', lazyloadRouteHandler('./routes/gab/explore')); // NEW 字幕组 -router.get('/newzmz/view/:id', lazyloadRouteHandler('./routes/newzmz/view')); -router.get('/newzmz/:category?', lazyloadRouteHandler('./routes/newzmz/index')); +// router.get('/newzmz/view/:id', lazyloadRouteHandler('./routes/newzmz/view')); +// router.get('/newzmz/:category?', lazyloadRouteHandler('./routes/newzmz/index')); // Phrack Magazine router.get('/phrack', lazyloadRouteHandler('./routes/phrack/index')); diff --git a/lib/routes/newzmz/index.js b/lib/v2/newzmz/index.js similarity index 86% rename from lib/routes/newzmz/index.js rename to lib/v2/newzmz/index.js index 7aee4d77f79f8a..240acaaf90cf0d 100644 --- a/lib/routes/newzmz/index.js +++ b/lib/v2/newzmz/index.js @@ -1,13 +1,14 @@ const got = require('@/utils/got'); const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { const category = parseInt(ctx.params.category || '1'); - const rootUrl = 'https://newzmz.com'; + const rootUrl = 'http://newzmz.com'; const response = await got({ method: 'get', - url: rootUrl, + url: `${rootUrl}/index.html`, }); const $ = cheerio.load(response.data); @@ -16,7 +17,6 @@ module.exports = async (ctx) => { const links = await Promise.all( target .find('.slides li a') - .slice(0, 15) .map((_, item) => { item = $(item); @@ -34,12 +34,13 @@ module.exports = async (ctx) => { }); const $ = cheerio.load(resourceResponse.data); - item.link = $('.addgz').attr('href'); - item.pubDate = new Date( + item.link = $('.addgz').attr('href').replace('http:', 'https:'); + item.pubDate = parseDate( $('.duration') + .not('.upday') .text() .replace(/更新时间:/, '') - ).toUTCString(); + ); return item; }) diff --git a/lib/v2/newzmz/maintainer.js b/lib/v2/newzmz/maintainer.js new file mode 100644 index 00000000000000..b8bcccd1f037c0 --- /dev/null +++ b/lib/v2/newzmz/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/:category?': ['nczitzk'], + '/view/:id?': ['nczitzk'], +}; diff --git a/lib/v2/newzmz/radar.js b/lib/v2/newzmz/radar.js new file mode 100644 index 00000000000000..4c2ee871f856bc --- /dev/null +++ b/lib/v2/newzmz/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'newzmz.com': { + _name: 'NEW 字幕组', + '.': [ + { + title: '分类', + docs: 'https://docs.rsshub.app/multimedia.html#new-zi-mu-zu', + source: ['/'], + target: '/newzmz', + }, + { + title: '指定剧集', + docs: 'https://docs.rsshub.app/multimedia.html#new-zi-mu-zu', + source: ['/view/:id'], + target: (params) => `/newzmz/view/${params.id.replace('.html', '')}`, + }, + ], + }, +}; diff --git a/lib/v2/newzmz/router.js b/lib/v2/newzmz/router.js new file mode 100644 index 00000000000000..d2d91824b82440 --- /dev/null +++ b/lib/v2/newzmz/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/:category?', require('./index')); + router.get('/view/:id', require('./view')); +}; diff --git a/lib/routes/newzmz/view.js b/lib/v2/newzmz/view.js similarity index 96% rename from lib/routes/newzmz/view.js rename to lib/v2/newzmz/view.js index 9107a7e9a4d1fd..58851ec8577afa 100644 --- a/lib/routes/newzmz/view.js +++ b/lib/v2/newzmz/view.js @@ -4,7 +4,7 @@ const cheerio = require('cheerio'); module.exports = async (ctx) => { const id = ctx.params.id; - const rootUrl = `https://ysfx.tv`; + const rootUrl = `https://s.newzmz.com`; const currentUrl = `${rootUrl}/view/${id}.html`; const response = await got({