Files
RSSHub/lib/routes/zimuku/index.js
T
sanmmmm ebb30e99a1 feat: 字幕库 & 手办维基情报 (#2760)
* fix docs

* feat: 字幕库

* feat: hpoi info
2019-08-03 14:04:15 +08:00

42 lines
1.2 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const { type = 'mv' } = ctx.params;
const baseUrl = 'http://www.zimuku.la';
const url = `${baseUrl}/newsubs?t=${type}`;
const response = await got(url);
const $ = cheerio.load(response.data);
const items = $('table > tbody > tr')
.map((_, ele) => {
const $item = cheerio.load(ele);
const author = $item('.glyphicon-user').text();
const baseInfoNode = $item('.first > a');
const title = baseInfoNode.attr('title');
const link = `${baseUrl}${baseInfoNode.attr('href')}`;
const langs = $item('.lang > img')
.map((_, ele) => ele.attribs.title.replace('字幕', ''))
.get();
return {
title,
link,
author,
description: `语言: ${langs.join(' | ')}`,
};
})
.get();
const typeToLabel = {
mv: '电影字幕',
tv: '美剧字幕',
};
const title = `字幕库 - ${typeToLabel[type]}`;
ctx.state.data = {
title,
description: title,
link: url,
item: items,
};
};