feat(route): youtube music charts (#11979)

* feat(route): youtube music charts

* docs: fix example
This commit is contained in:
Tony
2023-02-28 00:48:16 -11:00
committed by GitHub
parent 9c5261de7d
commit 992ab44a3a
6 changed files with 215 additions and 5 deletions
+50
View File
@@ -551,3 +551,53 @@ YouTube provides official RSS feeds for channels, for instance <https://www.yout
### Subscriptions
<RouteEn author="TonyRL" path="/youtube/subscriptions/:embed?" example="/youtube/subscriptions" :paramsDesc="['Default to embed the video, set to any value to disable embedding']" selfhost="1" radar="1" rssbud="1"/>
### Music Charts
<RouteEn author="TonyRL" path="/youtube/charts/:category?/:country?/:embed?" example="/youtube/charts" :paramsDesc="['Chart, see table below, default to `TopVideos`', 'Country Code, see table below, default to global', 'Default to embed the video, set to any value to disable embedding']" radar="1" rssbud="1">
::: details Chart
| Top artists | Top songs | Top music videos | Trending |
| ----------- | --------- | ---------------- | -------- |
| TopArtists | TopSongs | TopVideos | TrendingVideos |
:::
::: details Country Code
| Argentina | Australia | Austria | Belgium | Bolivia | Brazil | Canada |
| --------- | --------- | ------- | ------- | ------- | ------ | ------ |
| ar | au | at | be | bo | br | ca |
| Chile | Colombia | Costa Rica | Czechia | Denmark | Dominican Republic | Ecuador |
| ----- | -------- | ---------- | ------- | ------- | ------------------ | ------- |
| cl | co | cr | cz | dk | do | ec |
| Egypt | El Salvador | Estonia | Finland | France | Germany | Guatemala |
| ----- | ----------- | ------- | ------- | ------ | ------- | --------- |
| eg | sv | ee | fi | fr | de | gt |
| Honduras | Hungary | Iceland | India | Indonesia | Ireland | Israel | Italy |
| -------- | ------- | ------- | ----- | --------- | ------- | ------ | ----- |
| hn | hu | is | in | id | ie | il | it |
| Japan | Kenya | Luxembourg | Mexico | Netherlands | New Zealand | Nicaragua |
| ----- | ----- | ---------- | ------ | ----------- | ----------- | --------- |
| jp | ke | lu | mx | nl | nz | ni |
| Nigeria | Norway | Panama | Paraguay | Peru | Poland | Portugal | Romania |
| ------- | ------ | ------ | -------- | ---- | ------ | -------- | ------- |
| ng | no | pa | py | pe | pl | pt | ro |
| Russia | Saudi Arabia | Serbia | South Africa | South Korea | Spain | Sweden | Switzerland |
| ----- | ------------- | ------ | ------------ | ----------- | ----- | ------ | ----------- |
| ru | sa | rs | za | kr | es | se | ch |
| Tanzania | Turkey | Uganda | Ukraine | United Arab Emirates | United Kingdom | United States |
| -------- | ------ | ------ | ------- | -------------------- | -------------- | ------------- |
| tz | tr | ug | ua | ae | gb | us |
| Uruguay | Zimbabwe |
| ------- | -------- |
| uy | zw |
:::
</RouteEn>
+57 -5
View File
@@ -889,7 +889,7 @@ Instagram Stories 没有可靠的 guid,你的 RSS 阅读器可能将同一条
### 分类页面
<Route author="MisteryMonster" example="/vimeo/category/documentary/staffpicks" path="/vimeo/category/:category/:staffpicks?" :paramsDesc="['主分类名可从 url 获得,如 [https://vimeo.com/categories/documentary/videos](https://vimeo.com/categories/documentary/videos) 中的 `documentary`。', '填入 `staffpicks` 则按 staffpicks 排序']" radar="1">
<Route author="MisteryMonster" example="/vimeo/category/documentary/staffpicks" path="/vimeo/category/:category/:staffpicks?" :paramsDesc="['主分类名可从 url 获得,如 [https://vimeo.com/categories/documentary/videos](https://vimeo.com/categories/documentary/videos) 中的 `documentary`', '填入 `staffpicks` 则按 staffpicks 排序']" radar="1">
</Route>
@@ -919,19 +919,71 @@ YouTube 官方亦有提供频道 RSS,形如 <https://www.youtube.com/feeds/vid
:::
<Route author="DIYgod" example="/youtube/channel/UCDwDMPOZfxVV0x_dz0eQ8KQ" path="/youtube/channel/:id/:disableEmbed?" :paramsDesc="['频道 id', '默认为开启内嵌视频, 任意值为关闭']" radar="1" rssbud="1"/>
<Route author="DIYgod" example="/youtube/channel/UCDwDMPOZfxVV0x_dz0eQ8KQ" path="/youtube/channel/:id/:disableEmbed?" :paramsDesc="['频道 id', '默认为开启内嵌视频,任意值为关闭']" radar="1" rssbud="1"/>
### 自定义网址
<Route author="TonyRL" path="/youtube/c/:id/:embed?" example="/youtube/c/YouTubeCreators" :paramsDesc="['YouTube 自定义网址', '默认为开启内嵌视频, 任意值为关闭']" radar="1" rssbud="1"/>
<Route author="TonyRL" path="/youtube/c/:id/:embed?" example="/youtube/c/YouTubeCreators" :paramsDesc="['YouTube 自定义网址', '默认为开启内嵌视频,任意值为关闭']" radar="1" rssbud="1"/>
### 播放列表
<Route author="HenryQW" example="/youtube/playlist/PLqQ1RwlxOgeLTJ1f3fNMSwhjVgaWKo_9Z" path="/youtube/playlist/:id/:disableEmbed?" :paramsDesc="['播放列表 id', '默认为开启内嵌视频, 任意值为关闭']" radar="1" rssbud="1"/>
<Route author="HenryQW" example="/youtube/playlist/PLqQ1RwlxOgeLTJ1f3fNMSwhjVgaWKo_9Z" path="/youtube/playlist/:id/:disableEmbed?" :paramsDesc="['播放列表 id', '默认为开启内嵌视频,任意值为关闭']" radar="1" rssbud="1"/>
### 订阅列表
<Route author="TonyRL" path="/youtube/subscriptions/:embed?" example="/youtube/subscriptions" :paramsDesc="['默认为开启内嵌视频, 任意值为关闭']" selfhost="1" radar="1" rssbud="1"/>
<Route author="TonyRL" path="/youtube/subscriptions/:embed?" example="/youtube/subscriptions" :paramsDesc="['默认为开启内嵌视频,任意值为关闭']" selfhost="1" radar="1" rssbud="1"/>
### 音乐排行榜
<Route author="TonyRL" path="/youtube/charts/:category?/:country?/:embed?" example="/youtube/charts" :paramsDesc="['排行榜,见下表,默认为 `TopVideos`', '国家代码,见下表,默认为全球', '默认为开启内嵌视频,任意值为关闭']" radar="1" rssbud="1">
::: details 排行榜
| 热门音乐人 | 热门歌曲 | 热门音乐视频 | 时下流行 |
| ---------- | -------- | --------- | -------------- |
| TopArtists | TopSongs | TopVideos | TrendingVideos |
| ::: | | | |
::: details 国家代码
| Argentina | Australia | Austria | Belgium | Bolivia | Brazil | Canada |
| --------- | --------- | ------- | ------- | ------- | ------ | ------ |
| ar | au | at | be | bo | br | ca |
| Chile | Colombia | Costa Rica | Czechia | Denmark | Dominican Republic | Ecuador |
| ----- | -------- | ---------- | ------- | ------- | ------------------ | ------- |
| cl | co | cr | cz | dk | do | ec |
| Egypt | El Salvador | Estonia | Finland | France | Germany | Guatemala |
| ----- | ----------- | ------- | ------- | ------ | ------- | --------- |
| eg | sv | ee | fi | fr | de | gt |
| Honduras | Hungary | Iceland | India | Indonesia | Ireland | Israel | Italy |
| -------- | ------- | ------- | ----- | --------- | ------- | ------ | ----- |
| hn | hu | is | in | id | ie | il | it |
| Japan | Kenya | Luxembourg | Mexico | Netherlands | New Zealand | Nicaragua |
| ----- | ----- | ---------- | ------ | ----------- | ----------- | --------- |
| jp | ke | lu | mx | nl | nz | ni |
| Nigeria | Norway | Panama | Paraguay | Peru | Poland | Portugal | Romania |
| ------- | ------ | ------ | -------- | ---- | ------ | -------- | ------- |
| ng | no | pa | py | pe | pl | pt | ro |
| Russia | Saudi Arabia | Serbia | South Africa | South Korea | Spain | Sweden | Switzerland |
| ------ | ------------ | ------ | ------------ | ----------- | ----- | ------ | ----------- |
| ru | sa | rs | za | kr | es | se | ch |
| Tanzania | Turkey | Uganda | Ukraine | United Arab Emirates | United Kingdom | United States |
| -------- | ------ | ------ | ------- | -------------------- | -------------- | ------------- |
| tz | tr | ug | ua | ae | gb | us |
| Uruguay | Zimbabwe |
| ------- | -------- |
| uy | zw |
| ::: | |
</Route>
## 巴哈姆特
+97
View File
@@ -0,0 +1,97 @@
const got = require('@/utils/got');
const { renderDescription } = require('./utils');
const config = require('@/config').value;
module.exports = async (ctx) => {
const contentMap = {
TopArtists: {
contentKey: 'artists',
viewKey: 'artistViews',
title: 'Top artists',
},
TopSongs: {
contentKey: 'trackTypes',
viewKey: 'trackViews',
title: 'Top songs',
},
TopVideos: {
contentKey: 'videos',
viewKey: 'videoViews',
title: 'Top music videos',
},
TrendingVideos: {
contentKey: 'videos',
viewKey: 'videoViews',
title: 'Trending',
},
};
const { category = 'TopVideos', country } = ctx.params;
const embed = !ctx.params.embed;
const { content } = await ctx.cache.tryGet(
`youtube:charts:${country ? country : 'global'}`,
async () => {
const { data } = await got.post('https://charts.youtube.com/youtubei/v1/browse', {
searchParams: {
alt: 'json',
key: 'AIzaSyCzEW7JUJdSql0-2V4tHUb6laYm4iAE_dM',
},
json: {
browseId: 'FEmusic_analytics_charts_home',
context: {
capabilities: {},
client: {
clientName: 'WEB_MUSIC_ANALYTICS',
clientVersion: '0.2',
experimentIds: [],
experimentsToken: '',
gl: 'US',
hl: 'en',
theme: 'MUSIC',
},
request: {
internalExperimentFlags: [],
},
},
query: `chart_params_type=WEEK&perspective=CHART&flags=viral_video_chart&selected_chart=TRACKS&chart_params_id=weekly:0:0${country ? `:${country}` : ''}`,
},
});
return data.contents.sectionListRenderer.contents[0].musicAnalyticsSectionRenderer;
},
config.cache.routeExpire,
false
);
const { entityId } = content.perspectiveMetadata;
let items;
if (category === 'TopArtists') {
items = content[contentMap[category].contentKey][0][contentMap[category].viewKey].map((item) => ({
title: item.name,
link: `https://charts.youtube.com/artist/${encodeURIComponent(item.id)}`,
guid: `youtube:charts:${category}:${entityId}:${item.id}`,
}));
} else {
items = content[contentMap[category].contentKey][category !== 'TrendingVideos' ? 0 : 1][contentMap[category].viewKey].map((item) => {
const videoId = category === 'TopSongs' ? item.encryptedVideoId : item.id;
const author = item.artists
.filter((a) => a.name)
.map((artist) => artist.name)
.join(', ');
return {
title: `${item.title ?? item.name} - ${author}`,
description: renderDescription(embed, videoId, item.thumbnail?.thumbnails.pop().url, ''),
link: `https://www.youtube.com/watch?v=${videoId}`,
guid: `youtube:charts:${category}:${entityId}:${item.id}`,
author,
};
});
}
ctx.state.data = {
title: `YouTube Music Charts - ${contentMap[category].title}`,
link: `https://charts.youtube.com/charts/${category}/${country ? country : 'global'}`,
item: items,
};
};
+2
View File
@@ -1,5 +1,7 @@
module.exports = {
'/c/:id/:embed?': ['TonyRL'],
'/channel/:id/:embed?': ['DIYgod'],
'/charts/:category?/:country?/:embed?': ['TonyRL'],
'/playlist/:id/:embed?': ['HenryQW'],
'/subscriptions/:embed?': ['TonyRL'],
'/user/:username/:embed?': ['DIYgod'],
+8
View File
@@ -1,6 +1,14 @@
module.exports = {
'youtube.com': {
_name: 'YouTube',
charts: [
{
title: '音乐排行榜',
docs: 'https://docs.rsshub.app/social-media.html#youtube',
source: ['/charts/:category/:country/*', '/charts/:category/:country', '/charts/:category'],
target: (params) => `/youtube/charts/${params.category}${params.country ? params.country : ''}`,
},
],
www: [
{
title: '用户',
+1
View File
@@ -1,6 +1,7 @@
module.exports = (router) => {
router.get('/c/:username/:embed?', require('./custom'));
router.get('/channel/:id/:embed?', require('./channel'));
router.get('/charts/:category?/:country?/:embed?', require('./charts'));
router.get('/playlist/:id/:embed?', require('./playlist'));
router.get('/subscriptions/:embed?', require('./subscriptions'));
router.get('/user/:username/:embed?', require('./user'));