Skip to content

Commit

Permalink
fix(youtube): handle empty channel (#17633)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored Nov 19, 2024
1 parent 618cbbd commit a41cfc7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/routes/youtube/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { parseDate } from '@/utils/parse-date';
import ofetch from '@/utils/ofetch';
import * as cheerio from 'cheerio';
import ConfigNotFoundError from '@/errors/types/config-not-found';
import NotFoundError from '@/errors/types/not-found';

export const route: Route = {
path: '/user/:username/:embed?',
Expand Down Expand Up @@ -73,14 +74,17 @@ async function handler(ctx) {
}
const playlistId = userHandleData?.playlistId || (await utils.getChannelWithUsername(username, 'contentDetails', cache)).data.items[0].contentDetails.relatedPlaylists.uploads;

const data = (await utils.getPlaylistItems(playlistId, 'snippet', cache)).data.items;
const playlistItems = await utils.getPlaylistItems(playlistId, 'snippet', cache);
if (!playlistItems) {
throw new NotFoundError("This channel doesn't have any content.");
}

return {
title: `${userHandleData?.channelName || username} - YouTube`,
link: username.startsWith('@') ? `https://www.youtube.com/${username}` : `https://www.youtube.com/user/${username}`,
description: userHandleData?.description || `YouTube user ${username}`,
image: userHandleData?.image,
item: data
item: playlistItems.data.items
.filter((d) => d.snippet.title !== 'Private video' && d.snippet.title !== 'Deleted video')
.map((item) => {
const snippet = item.snippet;
Expand Down

0 comments on commit a41cfc7

Please sign in to comment.