Skip to content

Commit

Permalink
feat(route): add gcores podcast (DIYgod#12150)
Browse files Browse the repository at this point in the history
* feat(route): add gcores podcast

* feat(route): add gcores podcast

* Update lib/v2/gcores/maintainer.js

* Update lib/v2/gcores/router.js

* [fix] radar.js

* [fix] radar.js

* Update lib/v2/gcores/radio.js

* Update docs/new-media.md

---------
  • Loading branch information
eternasuno authored Mar 22, 2023
1 parent bf91c06 commit 8e3a4ac
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -2540,6 +2540,10 @@ others = 热点新闻 + 滚动新闻

</Route>

### 播客

<Route author="eternasuno" example="/gcores/radios/45" path="/gcores/radios/:category?" :paramsDesc="['分类名,默认为全部,可在分类页面的 URL 中找到,如 Gadio News -- 45']" radar="1" supportPodcast="1" />

## 加美财经

<Route author="nczitzk" example="/caus" path="/caus/:category?" :paramsDesc="['分类,见下表,默认为全部']">
Expand Down
1 change: 1 addition & 0 deletions lib/v2/gcores/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
'/category/:category': ['MoguCloud', 'StevenRCE0'],
'/radios/:category?': ['eternasuno'],
'/tag/:tag/:category?': ['StevenRCE0'],
};
12 changes: 12 additions & 0 deletions lib/v2/gcores/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ module.exports = {
source: ['/categories/:tag', '/'],
target: '/gcores/tag/:tag',
},
{
title: '播客',
docs: 'https://docs.rsshub.app/new-media.html#ji-he-wang-bo-ke',
source: ['/radios'],
target: '/gcores/radios',
},
{
title: '播客-分类',
docs: 'https://docs.rsshub.app/new-media.html#ji-he-wang-bo-ke',
source: ['/categories/:category'],
target: '/gcores/radios/:category',
},
],
},
};
90 changes: 90 additions & 0 deletions lib/v2/gcores/radio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const { art } = require('@/utils/render');
const { parseDate } = require('@/utils/parse-date');
const cheerio = require('cheerio');
const got = require('@/utils/got');
const md5 = require('@/utils/md5');
const path = require('path');

module.exports = async (ctx) => {
const category = ctx.params.category || 'all';
const limit = parseInt(ctx.query.limit) || 12;

const link = getLink(category);
const $ = cheerio.load(await get(link));
const title = $('head>title').text();
const description = $('head>meta[name="description"]').attr('content');
const image = $('head>link[rel="apple-touch-icon"]').attr('href');

const api = getApi(category);
api.searchParams.set('include', 'media');
api.searchParams.set('page[limit]', limit);
api.searchParams.set('sort', '-published-at');
api.searchParams.set('filter[list-all]', '0');
api.searchParams.set('fields[radios]', 'title,cover,published-at,duration,content,media');
const { data, included } = await get(api);

const audios = included.reduce((result, media) => {
result[media.id] = media.attributes.audio;
return result;
}, {});

const item = data.map((radio) => {
const { id, attributes, relationships } = radio;

const link = `https://www.gcores.com/radios/${id}`;
const itunes_item_image = `https://image.gcores.com/${attributes.cover}`;
const media_id = relationships.media.data.id;
const enclosure_url = new URL(audios[media_id], 'https://alioss.gcores.com/uploads/audio/').toString();
const description = art(path.join(__dirname, 'templates/content.art'), {
content: JSON.parse(attributes.content),
});

return {
title: attributes.title,
author: '机核 GCORES',
description,
pubDate: parseDate(attributes['published-at']),
guid: md5(link),
link,
itunes_item_image,
itunes_duration: attributes.duration,
enclosure_url,
enclosure_type: 'audio/mpeg',
};
});

ctx.state.data = {
title,
link,
description,
language: 'zh-cn',
itunes_author: '机核 GCORES',
image: `https://www.gcores.com/${image}`,
item,
};
};

const get = async (url) => {
const response = await got({
method: 'get',
url: new URL(url, 'https://www.gcores.com'),
});

return response.data;
};

const getLink = (category) => {
if (category === 'all') {
return 'https://www.gcores.com/radios';
} else {
return `https://www.gcores.com/categories/${category}`;
}
};

const getApi = (category) => {
if (category === 'all') {
return new URL('https://www.gcores.com/gapi/v1/radios');
} else {
return new URL(`https://www.gcores.com/gapi/v1/categories/${category}/radios`);
}
};
1 change: 1 addition & 0 deletions lib/v2/gcores/router.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = function (router) {
router.get('/category/:category', require('./category'));
router.get('/radios/:category?', require('./radio'));
router.get('/tag/:tag/:category?', require('./tag'));
};
16 changes: 16 additions & 0 deletions lib/v2/gcores/templates/content.art
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{if content}}
{{each content.blocks line}}
{{if line.type === 'unstyled'}}
<p>{{line.text}}</p>
{{/if}}
{{/each}}

{{each content.entityMap ent}}
{{if ent.type === 'WIDGET'}}
<p><a href='{{ent.data.url}}'>{{ent.data.title}}</a></p>
{{/if}}
{{/each}}
{{else}}
<p>机核从2010年开始一直致力于分享游戏玩家的生活,以及深入探讨游戏相关的文化。我们开发原创的播客以及视频节目,一直在不断寻找民间高质量的内容创作者。</p>
<p>我们坚信游戏不止是游戏,游戏中包含的科学,文化,历史等各个层面的知识和故事,它们同时也会辐射到二次元甚至电影的领域,这些内容非常值得分享给热爱游戏的您。</p>
{{/if}}

0 comments on commit 8e3a4ac

Please sign in to comment.