Skip to content

Commit

Permalink
feat(route): add FIX字幕侠 (DIYgod#7412)
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 4c499e3 commit d32b904
Show file tree
Hide file tree
Showing 4 changed files with 116 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 @@ -217,6 +217,22 @@ pageClass: routes

:::

## FIX 字幕侠

### 分类

<Route author="nczitzk" example="/zimuxia" path="/zimuxia/:category?" :paramsDesc="['分类,见下表,默认为 ALL']" >

| ALL | FIX 德语社 | 欧美剧集 | 欧美电影 | 综艺 & 纪录 | FIX 日语社 | FIX 韩语社 | FIX 法语社 |
| --- | ---------- | -------- | -------- | ----------- | ---------- | ---------- | ---------- |
| | 昆仑德语社 | 欧美剧集 | 欧美电影 | 综艺纪录 | fix 日语社 | fix 韩语社 | fix 法语社 |

</Route>

### 剧集

<Route author="nczitzk" example="/zimuxia/portfolio/我们这一天" path="/zimuxia/portfolio/:id" :paramsDesc="['剧集名,可在剧集页 URL 中找到']" />

### Lookup Torrents by IMDB ID

<Route author="Songkeys" example="/eztv/torrents/6048596" path="/eztv/torrents/:imdb_id" :paramsDesc="['想搜寻的 show 的种子所对应的 IMDB ID, 可在 [IMDB](https://www.imdb.com) 官网找到']" supportBT="1"/>
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'));

// FIX 字幕侠
router.get('/zimuxia/portfolio/:id', require('./routes/zimuxia/portfolio'));
router.get('/zimuxia/:category?', require('./routes/zimuxia/index'));

// Bandcamp
router.get('/bandcamp/tag/:tag?', require('./routes/bandcamp/tag'));

Expand Down
57 changes: 57 additions & 0 deletions lib/routes/zimuxia/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');

module.exports = async (ctx) => {
const category = ctx.params.category || '';

const rootUrl = 'https://www.zimuxia.cn';
const currentUrl = `${rootUrl}/我们的作品?cat=${category}`;
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.find('h2').text(),
link: 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);

const links = detailResponse.data.match(/<a href="magnet:(.*?)" target="_blank">磁力下载<\/a>/g);

if (links) {
item.enclosure_type = 'application/x-bittorrent';
item.enclosure_url = links.pop().match(/<a href="(.*)" target="_blank">磁力下载<\/a>/)[1];
}

item.description = content('.content-box').html();

return item;
})
)
);

ctx.state.data = {
title: `${category || 'ALL'} - FIX字幕侠`,
link: currentUrl,
item: items,
};
};
39 changes: 39 additions & 0 deletions lib/routes/zimuxia/portfolio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');

module.exports = async (ctx) => {
const id = ctx.params.id;

const rootUrl = 'http://zimuxia.cn';
const currentUrl = `${rootUrl}/portfolio/${id}`;
const response = await got({
method: 'get',
url: currentUrl,
});

const $ = cheerio.load(response.data);

const items = $('a')
.filter(function () {
return $(this).attr('href').substr(0, 7) === 'magnet:';
})
.reverse()
.map((_, item) => {
item = $(item);

return {
link: currentUrl,
title: item.parent().text().split(' ')[0],
description: `<p>${item.parent().html()}</p>`,
enclosure_url: item.attr('href'),
enclosure_type: 'application/x-bittorrent',
};
})
.get();

ctx.state.data = {
title: `${$('.content-page-title').text()} - FIX字幕侠`,
link: currentUrl,
item: items,
};
};

0 comments on commit d32b904

Please sign in to comment.