feat: add ddrk.me (#3738)

This commit is contained in:
Twinkle
2020-01-14 14:27:52 +08:00
committed by DIYgod
parent 5d639f916d
commit 1da57d937b
3 changed files with 41 additions and 0 deletions

View File

@@ -420,3 +420,9 @@ pageClass: routes
### 影视
<Route author="DIYgod" example="/zimuzu/resource/37031" path="/zimuzu/resource/:id?" :paramsDesc="['影视 id对应影视的 URL 中找到,为空时输出最近更新']" supportBT="1"/>
## 低端影视
### 影视剧集
<Route author="saintwinkle" example="/ddrk/silicon-valley/6" path="/ddrk/:name/:season?" :paramsDesc="['影视名称,可以在 URL 中找到','季数,可以在 URL 中找到,剧集没有分季时不用填写,或是默认输出第一季的内容,']" />

View File

@@ -2098,6 +2098,9 @@ router.get('/mlog-club/projects', require('./routes/mlog-club/projects'));
// Chrome 网上应用店
router.get('/chrome/webstore/extensions/:id', require('./routes/chrome/extensions'));
// 低端影视
router.get('/ddrk/:name/:season?', require('./routes/ddrk/index'));
// 公主链接日服公告
router.get('/pcr/news', require('./routes/pcr/news'));

32
lib/routes/ddrk/index.js Normal file
View File

@@ -0,0 +1,32 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const name = ctx.params.name;
const season = ctx.params.season;
let link = `https://ddrk.me/${name}/`;
if (season) {
link += `${season}/`;
}
const response = await got(link);
const $ = cheerio.load(response.body);
const title = $('title').html();
const description = $('.abstract').html();
const tracks = JSON.parse($('.wp-playlist-script').html()).tracks.reverse();
const total = tracks.length;
ctx.state.data = {
title,
link,
description,
item: tracks.map(({ caption, description }, index) => ({
title: caption,
link: `${link}?ep=${total - index}`,
description,
})),
};
};