From b7e7ab32039dc5bc714017edd2ee5e0cb1e46a7f Mon Sep 17 00:00:00 2001 From: nczitzk Date: Mon, 19 Apr 2021 14:08:57 +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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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 c950374608ff9e..2089ed06fc451e 100644 --- a/docs/multimedia.md +++ b/docs/multimedia.md @@ -957,6 +957,22 @@ pageClass: routes +## 弯弯字幕组 + +### 分类 + + + +| ALL | 英语小分队 | 日语小分队 | 韩语小分队 | 葡语小分队 | 西语小分队 | 法语小分队 | 意语小分队 | 德语小分队 | 泰语小分队 | 其他语种 | +| --- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | -------- | +| 139 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 153 | 117 | 154 | + + + +### 剧集 + + + ## 网易云音乐 ### 歌单歌曲 diff --git a/lib/router.js b/lib/router.js index bb40705959f751..953fe27b2adf21 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4061,4 +4061,8 @@ 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')); + module.exports = router; 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>/g); + + if (links) { + item.enclosure_type = 'application/x-bittorrent'; + item.enclosure_url = links.pop().match(/磁力<\/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 = `

${item.html()}

`; + i.title = item.text().split(' ')[0]; + i.link = currentUrl; + + return i; + }) + .get(); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +};