Files
RSSHub/lib/v2/ntdtv/channel.js
T
FatpandacandTony b86fd05d5a feat(route): add 新唐人電視台 (#9292)
* feat(route): add 新唐人電視台

* Update docs/traditional-media.md

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/ntdtv/channel.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

Co-authored-by: Tony <TonyRL@users.noreply.github.com>
2022-03-10 20:02:09 +08:00

45 lines
1.4 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const host = 'https://www.ntdtv.com';
module.exports = async (ctx) => {
const language = ctx.params.language;
const id = ctx.params.id;
const url = `${host}/${language}/${id}`;
const response = await got(url);
const $ = cheerio.load(response.data);
const title = $('h1.block_title').text();
const list = $('div.list_wrapper > div')
.map((_, item) => ({
title: $(item).find('div.title').text(),
link: $(item).find('div.title > a').attr('href'),
description: $(item).find('div.excerpt').text(),
}))
.get()
.filter((item) => item.link);
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got.get(item.link);
const content = cheerio.load(detailResponse.data);
item.description = content('div.post_content').html();
item.pubDate = timezone(parseDate(content('div.time > span').text()), +8);
return item;
})
)
);
ctx.state.data = {
title: `新唐人电视台 - ${title}`,
link: url,
item: items,
};
};