From a87ecdfed2ac4ff4b1f38a6166ecedc3600e6b78 Mon Sep 17 00:00:00 2001 From: Ethan Shen <nczitzk@gmail.com> Date: Thu, 13 May 2021 03:28:18 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=BC=AF=E5=BC=AF?= =?UTF-8?q?=E5=AD=97=E5=B9=95=E7=BB=84=20(#7408)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: NeverBehave <gayhub@never.pet> --- docs/multimedia.md | 16 ++++++++++ lib/router.js | 4 +++ lib/routes/wanwansub/index.js | 58 +++++++++++++++++++++++++++++++++++ lib/routes/wanwansub/info.js | 44 ++++++++++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 lib/routes/wanwansub/index.js create mode 100644 lib/routes/wanwansub/info.js diff --git a/docs/multimedia.md b/docs/multimedia.md index fcf94a9e0cdf8f..c96f20bdd38a7f 100644 --- a/docs/multimedia.md +++ b/docs/multimedia.md @@ -979,6 +979,22 @@ pageClass: routes <Route author="Andiedie" example="/tencentvideo/playlist/jx7g4sm320sqm7i" path="/tencentvideo/playlist/:id" :paramsDesc="['播放列表 ID,可以在 URL 中找到']" radar="1" /> +## 弯弯字幕组 + +### 分类 + +<Route author="nczitzk" example="/wanwansub/139" path="/wanwansub/:id?" :paramsDesc="['分类 id,见下表,默认为 ALL']" > + +| ALL | 英语小分队 | 日语小分队 | 韩语小分队 | 葡语小分队 | 西语小分队 | 法语小分队 | 意语小分队 | 德语小分队 | 泰语小分队 | 其他语种 | +| --- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | -------- | +| 139 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 153 | 117 | 154 | + +</Route> + +### 剧集 + +<Route author="nczitzk" example="/wanwansub/info/393" path="/wanwansub/info/:id" :paramsDesc="['剧集 id,可在剧集页 URL 中找到']" /> + ## 网易云音乐 ### 歌单歌曲 diff --git a/lib/router.js b/lib/router.js index d57eb8b756c35c..8e7256c301c98f 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4067,6 +4067,10 @@ router.get('/jisilu/topic/:user', require('./routes/jisilu/topic')); // Constitutional Court of Baden-Württemberg (Germany) router.get('/verfghbw/press/:keyword?', require('./routes/verfghbw/press')); +// 弯弯字幕组 +router.get('/wanwansub/info/:id', require('./routes/wanwansub/info')); +router.get('/wanwansub/:id?', require('./routes/wanwansub/index')); + // FIX 字幕侠 router.get('/zimuxia/portfolio/:id', require('./routes/zimuxia/portfolio')); router.get('/zimuxia/:category?', require('./routes/zimuxia/index')); diff --git a/lib/routes/wanwansub/index.js b/lib/routes/wanwansub/index.js new file mode 100644 index 00000000000000..8d4d87eadc0c32 --- /dev/null +++ b/lib/routes/wanwansub/index.js @@ -0,0 +1,58 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const id = ctx.params.id || '139'; + + const rootUrl = 'http://wanwansub.com'; + const currentUrl = `${rootUrl}/node/${id}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.pg-item a') + .slice(0, 10) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: `${rootUrl}${item.attr('href')}`, + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + const content = cheerio.load(detailResponse.data); + + content('.button').remove(); + + const links = detailResponse.data.match(/<a href="magnet:(.*?)" target="_self">磁力<\/a>/g); + + if (links) { + item.enclosure_type = 'application/x-bittorrent'; + item.enclosure_url = links.pop().match(/<a href="(.*)" target="_self">磁力<\/a>/)[1]; + } + + item.description = content('.content-box').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/routes/wanwansub/info.js b/lib/routes/wanwansub/info.js new file mode 100644 index 00000000000000..7cd978654bca9d --- /dev/null +++ b/lib/routes/wanwansub/info.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const id = ctx.params.id; + + const rootUrl = 'http://wanwansub.com'; + const currentUrl = `${rootUrl}/info/${id}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const items = $('.lightbox-image') + .nextAll('p') + .slice(3) + .map((_, item) => { + const i = {}; + + item = $(item); + + item.find('a').each(function () { + if ($(this).text() === '磁力') { + i.enclosure_url = $(this).attr('href'); + i.enclosure_type = 'application/x-bittorrent'; + } + }); + + i.description = `<p>${item.html()}</p>`; + i.title = item.text().split(' ')[0]; + i.link = currentUrl; + + return i; + }) + .get(); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +};