Skip to content

Commit

Permalink
fix(youtube): check if username exists (DIYgod#18025)
Browse files Browse the repository at this point in the history
* fix(youtube): check if username exists

* docs: fix descriptoin

https://support.google.com/youtube/answer/6180214
  • Loading branch information
TonyRL authored Jan 1, 2025
1 parent ba22b4e commit efcac36
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/routes/youtube/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const route: Route = {
categories: ['social-media', 'popular'],
view: ViewType.Videos,
example: '/youtube/user/@JFlaMusic',
parameters: { username: 'YouTuber username with @', embed: 'Default to embed the video, set to any value to disable embedding' },
parameters: { username: 'YouTuber handle with @', embed: 'Default to embed the video, set to any value to disable embedding' },
features: {
requireConfig: [
{
Expand All @@ -33,7 +33,7 @@ export const route: Route = {
target: '/user/:username',
},
],
name: 'Channel with username',
name: 'Channel with user handle',
maintainers: ['DIYgod'],
handler,
};
Expand Down Expand Up @@ -72,7 +72,16 @@ async function handler(ctx) {
};
});
}
const playlistId = userHandleData?.playlistId || (await utils.getChannelWithUsername(username, 'contentDetails', cache)).data.items[0].contentDetails.relatedPlaylists.uploads;
const playlistId =
userHandleData?.playlistId ||
(await (async () => {
const channelData = await utils.getChannelWithUsername(username, 'contentDetails', cache);
const items = channelData.data.items;
if (!items) {
throw new NotFoundError(`The channel https://www.youtube.com/user/${username} does not exist.`);
}
return items[0].contentDetails.relatedPlaylists.uploads;
})());

const playlistItems = await utils.getPlaylistItems(playlistId, 'snippet', cache);
if (!playlistItems) {
Expand Down

0 comments on commit efcac36

Please sign in to comment.