forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add cgtn podcast 中国环球电视网 - 播客 (DIYgod#12128)
* feat(route): add cgtn podcast * apply changes of review
- Loading branch information
1 parent
3e0eb27
commit 7c8422f
Showing
5 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'/podcast/:category/:id': ['5upernova-heng'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
}; |