From 0a0f5134783e018f08d269ee86b334d22445d126 Mon Sep 17 00:00:00 2001 From: WardPearce Date: Sun, 8 Mar 2026 15:32:49 +1300 Subject: [PATCH] Set channel id for channel content --- materialious/src/lib/api/youtubejs/channel.ts | 27 ++++++++++--------- materialious/src/lib/api/youtubejs/schema.ts | 1 + 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/materialious/src/lib/api/youtubejs/channel.ts b/materialious/src/lib/api/youtubejs/channel.ts index c5ad03f3..762e23fa 100644 --- a/materialious/src/lib/api/youtubejs/channel.ts +++ b/materialious/src/lib/api/youtubejs/channel.ts @@ -16,8 +16,6 @@ export async function getChannelYTjs(channelId: string): Promise { const innerResults = await innertube.getChannel(channelId); - const authorId = innerResults.metadata.url?.split('/')[4] ?? ''; - let authorBanners: Image[] = []; if ( innerResults.header?.is(YTNodes.PageHeader) && @@ -38,12 +36,12 @@ export async function getChannelYTjs(channelId: string): Promise { isFamilyFriendly: true, author: innerResults.metadata.title ?? '', authorThumbnails: innerResults.metadata.avatar ?? [], - authorId: authorId, + authorId: channelId, authorBanners, joined: 0, authorVerified: true, totalViews: 0, - authorUrl: `/channel/${authorId}`, + authorUrl: `/channel/${channelId}`, subCount: 0, autoGenerated: false, description, @@ -53,7 +51,8 @@ export async function getChannelYTjs(channelId: string): Promise { export function invidiousChannelContentSchema( innerResults: YT.Channel | YT.ChannelListContinuation, - author: string + author: string, + authorId: string ) { const videos: Video[] = []; @@ -77,6 +76,7 @@ export function invidiousChannelContentSchema( const invidiousSchema = invidiousItemSchema(item.content); if (invidiousSchema?.type === 'video') { invidiousSchema.author = author; + invidiousSchema.authorId = authorId; videos.push(invidiousSchema); } } @@ -87,30 +87,33 @@ export function invidiousChannelContentSchema( function fetchChannelContentVideosWithContinuation( innerResults: YT.ChannelListContinuation, - author: string + author: string, + authorId: string ): () => Promise { return async () => { const continuation = await innerResults.getContinuation(); return { - videos: invidiousChannelContentSchema(continuation, author), - getContinuation: fetchChannelContentVideosWithContinuation(continuation, author) + videos: invidiousChannelContentSchema(continuation, author, authorId), + getContinuation: fetchChannelContentVideosWithContinuation(continuation, author, authorId) }; }; } async function fetchChannelContentWithContinuation( innerResults: YT.Channel | YT.ChannelListContinuation, - author: string + author: string, + authorId: string ): Promise { const channelContent: ChannelContent = { continuation: innerResults.has_continuation ? 'logicalPlaceholder' : undefined, - videos: invidiousChannelContentSchema(innerResults, author) + videos: invidiousChannelContentSchema(innerResults, author, authorId) }; if (channelContent.continuation) { channelContent.getContinuation = fetchChannelContentVideosWithContinuation( innerResults, - author + author, + authorId ); } @@ -138,5 +141,5 @@ export async function getChannelContentYTjs( innerResults = await channel.getLiveStreams(); } - return fetchChannelContentWithContinuation(innerResults, author); + return fetchChannelContentWithContinuation(innerResults, author, channelId); } diff --git a/materialious/src/lib/api/youtubejs/schema.ts b/materialious/src/lib/api/youtubejs/schema.ts index ba673718..58819f6c 100644 --- a/materialious/src/lib/api/youtubejs/schema.ts +++ b/materialious/src/lib/api/youtubejs/schema.ts @@ -6,6 +6,7 @@ import { Helpers, YTNodes } from 'youtubei.js'; export function invidiousItemSchema(item: Helpers.YTNode): Video | Channel | Playlist | undefined { if (item.is(YTNodes.Video)) { const views = extractNumber(item.view_count?.toString() || ''); + console.log(item); return { type: 'video', title: item.title.toString(),