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.
Merge pull request #883 from DIYgod/master
[pull] master from diygod:master
- Loading branch information
Showing
8 changed files
with
157 additions
and
33 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
module.exports = { | ||
'/category/:category': ['MoguCloud', 'StevenRCE0'], | ||
'/radios/:category?': ['eternasuno'], | ||
'/tag/:tag/:category?': ['StevenRCE0'], | ||
}; |
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,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`); | ||
} | ||
}; |
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 |
---|---|---|
@@ -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')); | ||
}; |
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,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}} |
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
35fc0fe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
rsshub-master – ./
rsshub-master.vercel.app
rsshub-master-auto-bot-ty.vercel.app
rsshub-master-git-master-auto-bot-ty.vercel.app