diff --git a/docs/README.md b/docs/README.md index 730bbd7c06..c2e775c881 100644 --- a/docs/README.md +++ b/docs/README.md @@ -989,6 +989,10 @@ GitHub 官方也提供了一些 RSS: +### 高清电台 + + + ## 图片 ### 妹子图 diff --git a/lib/router.js b/lib/router.js index e6802fa6c0..7fcf56e03d 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1019,6 +1019,9 @@ router.get('/jpmorganchase', require('./routes/jpmorganchase/research')); // 美拍 router.get('/meipai/user/:uid', require('./routes/meipai/user')); +// 高清电台 +router.get('/gaoqing/latest', require('./routes/gaoqing/latest')); + // 轻小说文库 router.get('/wenku8/chapter/:id', require('./routes/wenku8/chapter')); diff --git a/lib/routes/gaoqing/latest.js b/lib/routes/gaoqing/latest.js new file mode 100644 index 0000000000..ff19881349 --- /dev/null +++ b/lib/routes/gaoqing/latest.js @@ -0,0 +1,28 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); +const util = require('./utils'); + +module.exports = async (ctx) => { + const response = await axios({ + method: 'get', + url: 'https://gaoqing.fm/', + headers: { + Referer: 'https://gaoqing.fm/', + }, + }); + + const data = response.data; + + const $ = cheerio.load(data); + const list = $('#result1 > li').get(); + + let result = await util.ProcessFeed(list, ctx.cache); + result = result.slice(0, 10); + + ctx.state.data = { + title: '高清电台', + link: 'https://gaoqing.fm', + description: $('meta[name="description"]').attr('content'), + item: result, + }; +}; diff --git a/lib/routes/gaoqing/utils.js b/lib/routes/gaoqing/utils.js new file mode 100644 index 0000000000..0e4e4be544 --- /dev/null +++ b/lib/routes/gaoqing/utils.js @@ -0,0 +1,59 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); + +// 加载详情页 +async function load(link) { + const response = await axios.get(link); + const $ = cheerio.load(response.data); + + // 提取标题 + const title = $('#mainrow > div:nth-child(2) > div.col-md-9 > div.row > div.col-md-12').html(); + + // 提取图片 + const img = $('.x-m-poster').html(); + + // 提取资料 + $('#viewfilm') + .find('img') + .remove(); + const info = $('#viewfilm').html(); + + // 提取简介 + const intro = $('#des-ex').html() || $('#des-full').html(); + + // 合并为描述 + const description = title + img + info + intro; + + return { description }; +} + +const ProcessFeed = async (list, caches) => + await Promise.all( + list.map(async (item) => { + const $ = cheerio.load(item); + + // 获取链接 + const $title = $('div.item-desc.pull-left > p > a'); + const itemUrl = $title.attr('href'); + + // 获取评分 + const rate = $('div.item-desc.pull-left > p > span').text(); + + // 列表上提取到的信息 + const single = { + title: $title.text() + ' - ' + rate, + link: itemUrl, + guid: itemUrl, + }; + + // 缓存 + const other = await caches.tryGet(itemUrl, async () => await load(itemUrl)); + + // 合并结果 + return Promise.resolve(Object.assign({}, single, other)); + }) + ); + +module.exports = { + ProcessFeed, +};