mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
feat: youtube cache
This commit is contained in:
@@ -8,7 +8,7 @@ module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
const embed = !ctx.params.embed;
|
||||
|
||||
const playlistId = (await utils.getChannelWithId(id, 'contentDetails')).data.items[0].contentDetails.relatedPlaylists.uploads;
|
||||
const playlistId = (await utils.getChannelWithId(id, 'contentDetails', ctx.cache)).data.items[0].contentDetails.relatedPlaylists.uploads;
|
||||
|
||||
const data = (await utils.getPlaylistItems(playlistId, 'snippet,contentDetails')).data.items;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
const embed = !ctx.params.embed;
|
||||
|
||||
const playlistTitle = (await utils.getPlaylist(id, 'snippet')).data.items[0].snippet.title;
|
||||
const playlistTitle = (await utils.getPlaylist(id, 'snippet', ctx.cache)).data.items[0].snippet.title;
|
||||
|
||||
const data = (await utils.getPlaylistItems(id, 'snippet,contentDetails')).data.items;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ module.exports = async (ctx) => {
|
||||
const username = ctx.params.username;
|
||||
const embed = !ctx.params.embed;
|
||||
|
||||
const playlistId = (await utils.getChannelWithUsername(username, 'contentDetails')).data.items[0].contentDetails.relatedPlaylists.uploads;
|
||||
const playlistId = (await utils.getChannelWithUsername(username, 'contentDetails', ctx.cache)).data.items[0].contentDetails.relatedPlaylists.uploads;
|
||||
|
||||
const data = (await utils.getPlaylistItems(playlistId, 'snippet,contentDetails')).data.items;
|
||||
|
||||
|
||||
+24
-21
@@ -14,27 +14,30 @@ const youtubeUtils = {
|
||||
});
|
||||
return res;
|
||||
},
|
||||
getPlaylist: async (id, part) => {
|
||||
const res = await youtube.playlists.list({
|
||||
part,
|
||||
id: id,
|
||||
});
|
||||
return res;
|
||||
},
|
||||
getChannelWithId: async (id, part) => {
|
||||
const res = await youtube.channels.list({
|
||||
part,
|
||||
id: id,
|
||||
});
|
||||
return res;
|
||||
},
|
||||
getChannelWithUsername: async (username, part) => {
|
||||
const res = await youtube.channels.list({
|
||||
part,
|
||||
forUsername: username,
|
||||
});
|
||||
return res;
|
||||
},
|
||||
getPlaylist: async (id, part, cache) =>
|
||||
await cache.tryGet('getPlaylist' + id, async () => {
|
||||
const res = await youtube.playlists.list({
|
||||
part,
|
||||
id: id,
|
||||
});
|
||||
return res;
|
||||
}),
|
||||
getChannelWithId: async (id, part, cache) =>
|
||||
await cache.tryGet('getChannelWithId' + id, async () => {
|
||||
const res = await youtube.channels.list({
|
||||
part,
|
||||
id: id,
|
||||
});
|
||||
return res;
|
||||
}),
|
||||
getChannelWithUsername: async (username, part, cache) =>
|
||||
await cache.tryGet('getPlaylist' + username, async () => {
|
||||
const res = await youtube.channels.list({
|
||||
part,
|
||||
forUsername: username,
|
||||
});
|
||||
return res;
|
||||
}),
|
||||
getThumbnail: (thumbnails) => thumbnails.maxres || thumbnails.standard || thumbnails.high || thumbnails.medium || thumbnails.default,
|
||||
formatDescription: (description) => description.replace(/(?:\r\n|\r|\n)/g, '<br>'),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user