Skip to content

Commit

Permalink
Merge pull request #883 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored Mar 22, 2023
2 parents 9875b41 + 8e3a4ac commit 35fc0fe
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 33 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}}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@vuepress/shared-utils": "1.9.9",
"cross-env": "7.0.3",
"eslint": "8.36.0",
"eslint-config-prettier": "8.7.0",
"eslint-config-prettier": "8.8.0",
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-yml": "1.5.0",
"fs-extra": "11.1.1",
Expand All @@ -68,7 +68,7 @@
"mockdate": "3.0.5",
"nock": "13.3.0",
"nodemon": "2.0.21",
"prettier": "2.8.5",
"prettier": "2.8.6",
"prettier-check": "2.0.0",
"pretty-quick": "3.1.3",
"remark": "13.0.0",
Expand All @@ -92,7 +92,7 @@
"dependencies": {
"@koa/router": "12.0.0",
"@postlight/parser": "2.2.3",
"@sentry/node": "7.43.0",
"@sentry/node": "7.44.2",
"aes-js": "3.1.2",
"art-template": "4.13.2",
"bbcodejs": "0.0.4",
Expand Down
60 changes: 30 additions & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1590,39 +1590,39 @@
domhandler "^5.0.3"
selderee "^0.10.0"

"@sentry/core@7.43.0":
version "7.43.0"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.43.0.tgz#c78e79399172738c96e3b388244258153c49215f"
integrity sha512-zvMZgEi7ptLBwDnd+xR/u4zdSe5UzS4S3ZhoemdQrn1PxsaVySD/ptyzLoGSZEABqlRxGHnQrZ78MU1hUDvKuQ==
"@sentry/core@7.44.2":
version "7.44.2"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-7.44.2.tgz#e33b2880e83cc4aaaa3d1b8a160588484d0e2624"
integrity sha512-m2nOHP4YX+kmWFQTzgBEsdblCuNFSB7017oLaR6/VH0a0mVWdrW7Q1gHMpw4/08uWRiA+oC2dXqCH7A1FwfGIQ==
dependencies:
"@sentry/types" "7.43.0"
"@sentry/utils" "7.43.0"
"@sentry/types" "7.44.2"
"@sentry/utils" "7.44.2"
tslib "^1.9.3"

"@sentry/node@7.43.0":
version "7.43.0"
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-7.43.0.tgz#bcb553486ffe3f1413063e9125fd34f9d84277d2"
integrity sha512-oXaTBq6Bk8Qwsd46hhRU2MLEnjYqWI41nPJmXyAWkDSYQTP7sUe1qM8bCUdsRpPwQh955Vq9qCRfgMbN4lEoAQ==
"@sentry/node@7.44.2":
version "7.44.2"
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-7.44.2.tgz#e37864790d95b91d1a2610ee59af36eda6807ac2"
integrity sha512-tEMcT+di7q7OYZt8Lg9kIpXoSO1YQNhnfMyffpzC82TMyJGNclBllNTF/UUnPqEiRW8WeewNgWuJAMLpPzjmfw==
dependencies:
"@sentry/core" "7.43.0"
"@sentry/types" "7.43.0"
"@sentry/utils" "7.43.0"
"@sentry/core" "7.44.2"
"@sentry/types" "7.44.2"
"@sentry/utils" "7.44.2"
cookie "^0.4.1"
https-proxy-agent "^5.0.0"
lru_map "^0.3.3"
tslib "^1.9.3"

"@sentry/types@7.43.0":
version "7.43.0"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.43.0.tgz#e621257601e9db2a39cdd3bd75e67fe338ed51eb"
integrity sha512-5XxCWqYWJNoS+P6Ie2ZpUDxLRCt7FTEzmlQkCdjW6MFWOX26hAbF/wEuOTYAFKZXMIXOz0Egofik1e8v1Cg6/A==
"@sentry/types@7.44.2":
version "7.44.2"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-7.44.2.tgz#c8acdd884f4daf03f3e813935e9e16da71473247"
integrity sha512-vdGb2BAelXRitgKWRBF1cCAoisLsbugUaJzrGCQoIoS3lYpZ8d8r2zELE7cNoVObVoQbUHF/WFhXVv8cumj+RA==

"@sentry/utils@7.43.0":
version "7.43.0"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.43.0.tgz#ad16efb86b94ffe6dca2ed2b299d5230ba6d815b"
integrity sha512-f78YfMLcgNU7+suyWFCuQhQlneXXMS+egb0EFZh7iU7kANUPRX5T4b+0C+fwaPm5gA6XfGYskr4ZnzQJLOlSqg==
"@sentry/utils@7.44.2":
version "7.44.2"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-7.44.2.tgz#a2f77713fec4471076e79e050c75561c21ad8abb"
integrity sha512-PzL4Z0fhIHfQacfWvgiAs+drcm4Nc45Tc8PW1RdOZtHxzhGAYZYAPniDGML586Mnlu19QM6kGHiDu+CBgnnXAQ==
dependencies:
"@sentry/types" "7.43.0"
"@sentry/types" "7.44.2"
tslib "^1.9.3"

"@sinclair/typebox@^0.25.16":
Expand Down Expand Up @@ -5620,10 +5620,10 @@ escodegen@^2.0.0:
optionalDependencies:
source-map "~0.6.1"

eslint-config-prettier@8.7.0:
version "8.7.0"
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.7.0.tgz#f1cc58a8afebc50980bd53475451df146c13182d"
integrity sha512-HHVXLSlVUhMSmyW4ZzEuvjpwqamgmlfkutD53cYXLikh4pt/modINRcCIApJ84czDxM4GZInwUrromsDdTImTA==
eslint-config-prettier@8.8.0:
version "8.8.0"
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.8.0.tgz#bfda738d412adc917fd7b038857110efe98c9348"
integrity sha512-wLbQiFre3tdGgpDv67NQKnJuTlcUVYHas3k+DZCc2U2BadthoEY4B7hLPvAxaqdyOGCzuLfii2fqGph10va7oA==

eslint-plugin-prettier@4.2.1:
version "4.2.1"
Expand Down Expand Up @@ -11148,10 +11148,10 @@ prettier-linter-helpers@^1.0.0:
dependencies:
fast-diff "^1.1.2"

prettier@2.8.5, "prettier@^1.18.2 || ^2.0.0":
version "2.8.5"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.5.tgz#3dd8ae1ebddc4f6aa419c9b64d8c8319a7e0d982"
integrity sha512-3gzuxrHbKUePRBB4ZeU08VNkUcqEHaUaouNt0m7LGP4Hti/NuB07C7PPTM/LkWqXoJYJn2McEo5+kxPNrtQkLQ==
prettier@2.8.6, "prettier@^1.18.2 || ^2.0.0":
version "2.8.6"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.6.tgz#5c174b29befd507f14b83e3c19f83fdc0e974b71"
integrity sha512-mtuzdiBbHwPEgl7NxWlqOkithPyp4VN93V7VeHVWBF+ad3I5avc0RVDT4oImXQy9H/AqxA2NSQH8pSxHW6FYbQ==

pretty-bytes@^5.1.0:
version "5.6.0"
Expand Down

1 comment on commit 35fc0fe

@vercel
Copy link

@vercel vercel bot commented on 35fc0fe Mar 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.