Skip to content

Commit

Permalink
feat(route): add 弯弯字幕组 (#7408)
Browse files Browse the repository at this point in the history
Co-authored-by: NeverBehave <[email protected]>
  • Loading branch information
Ethan Shen and NeverBehave authored May 12, 2021
1 parent 9e6aaf2 commit a87ecdf
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/multimedia.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 中找到']" />

## 网易云音乐

### 歌单歌曲
Expand Down
4 changes: 4 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
58 changes: 58 additions & 0 deletions lib/routes/wanwansub/index.js
Original file line number Diff line number Diff line change
@@ -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,
};
};
44 changes: 44 additions & 0 deletions lib/routes/wanwansub/info.js
Original file line number Diff line number Diff line change
@@ -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,
};
};

1 comment on commit a87ecdf

@vercel
Copy link

@vercel vercel bot commented on a87ecdf May 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.