Skip to content

Commit

Permalink
feat(route): add cgtn podcast 中国环球电视网 - 播客 (DIYgod#12128)
Browse files Browse the repository at this point in the history
* feat(route): add cgtn podcast

* apply changes of review
  • Loading branch information
5upernova-heng authored Mar 17, 2023
1 parent 3e0eb27 commit 7c8422f
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/traditional-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -2489,6 +2489,17 @@ category 对应的关键词有

</Route>

## 中国环球电视网

### 播客

<Route author="5upernova-heng" example="/cgtn/podcast/ezfm/4" path="/cgtn/podcast/:category/:id" :paramsDesc="['类型名','播客 id']" radar=1>

> 类型名与播客 id 可以在播客对应的 URL 中找到
> 如 URL `https://radio.cgtn.com/podcast/column/ezfm/More-to-Read/4` ,其 `category``ezfm``id``4`,对应的订阅路由为 [`/podcast/ezfm/4`](https://rsshub.app/podcast/ezfm/4)
</Route>

## 中国日报

### 英语点津
Expand Down
3 changes: 3 additions & 0 deletions lib/v2/cgtn/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/podcast/:category/:id': ['5upernova-heng'],
};
35 changes: 35 additions & 0 deletions lib/v2/cgtn/podcast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const got = require('@/utils/got');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');

async function getData(category, id) {
const url = `https://radio.cgtn.com/downapiRES/radio/v1/program/historyList/programId${id}_category${category}_page1.json`;
const response = await got(url);
return response.data;
}

function combDate(date, time) {
// combine date and time, return a Date object
return timezone(parseDate(date + ' ' + time), +8);
}

module.exports = async (ctx) => {
const { category, id } = ctx.params;
const categoryMap = { ezfm: 1, other: 5 };
const data = await getData(categoryMap[category], id);
const items = data.data.map((item) => ({
title: item.title,
pubDate: combDate(item.showDate, item.time.split(' ')[0]),
description: item.programSeries.content || item.detail,
itunes_item_image: item.programUrl,
itunes_duration: item.duration,
enclosure_url: item.mediaUrl,
enclosure_type: 'audio/mpeg',
}));
ctx.state.data = {
title: `中国环球电视网 CGTN Podcast - ${data.info}`,
link: 'https://www.cgtn.com/radio/',
item: items,
description: String(data.info),
};
};
13 changes: 13 additions & 0 deletions lib/v2/cgtn/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'cgtn.com': {
_name: '中国环球电视网 CGTN',
'.': [
{
title: '播客',
docs: 'https://docs.rsshub.app/traditional-media.html#zhong-guo-huan-qiu-dian-shi-wang',
source: ['/podcast/column/:category/*/:id'],
target: '/cgtn/podcast/:category/:id',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/cgtn/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/podcast/:category/:id', require('./podcast.js'));
};

0 comments on commit 7c8422f

Please sign in to comment.