mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-24 12:15:32 +08:00
feat(route): youtube music charts (#11979)
* feat(route): youtube music charts * docs: fix example
This commit is contained in:
@@ -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,
|
||||
};
|
||||
};
|
||||
@@ -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'],
|
||||
|
||||
@@ -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,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'));
|
||||
|
||||
Reference in New Issue
Block a user