From c5f4f45401387e20b997274b837fb9952954fa36 Mon Sep 17 00:00:00 2001 From: WardPearce Date: Wed, 30 Oct 2024 19:36:41 +1300 Subject: [PATCH] fixes to tostring patch error --- materialious/src/lib/patches/youtubejs.ts | 33 +++++++++++------------ 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/materialious/src/lib/patches/youtubejs.ts b/materialious/src/lib/patches/youtubejs.ts index 16f20808..4f74d5e0 100644 --- a/materialious/src/lib/patches/youtubejs.ts +++ b/materialious/src/lib/patches/youtubejs.ts @@ -7,7 +7,6 @@ import { get } from 'svelte/store'; import { Innertube, ProtoUtils, UniversalCache, Utils } from 'youtubei.js'; import { capacitorFetch } from '../android/http/capacitorFetch'; - export interface PoTokens { visitor_data: string; po_token: string; @@ -100,7 +99,7 @@ export async function patchYoutubeJs(videoId: string): Promise { dashUri = URL.createObjectURL(new Blob([manifest], { type: 'application/dash+xml;charset=utf8' })); } - const descString = video.secondary_info.description.toString(); + const descString = video.secondary_info.description?.toString() || ''; let authorThumbnails: Image[]; if (video.basic_info.channel_id) { @@ -115,18 +114,18 @@ export async function patchYoutubeJs(videoId: string): Promise { recommendedVideos.push({ videoThumbnails: recommended?.thumbnails as Thumbnail[] || [], videoId: recommended?.id || '', - title: recommended?.title.toString() || '', - viewCountText: recommended.view_count ? numberWithCommas(Number(recommended?.view_count.toString().replace(/\D/g, ''))) as string : '', + title: recommended?.title?.toString() || '', + viewCountText: recommended.view_count ? numberWithCommas(Number(recommended?.view_count.toString().replace(/\D/g, ''))) || '' : '', lengthSeconds: recommended?.duration?.seconds || 0, - author: recommended?.author.name || '', - authorId: recommended?.author.id || '' + author: recommended?.author?.name || '', + authorId: recommended?.author?.id || '' }); }); let captions: Captions[] = []; video.captions?.caption_tracks?.forEach(caption => { captions.push({ - label: caption.name.toString(), + label: caption.name?.toString() || '', language_code: caption.language_code, // Add correct format to url. url: caption.base_url + '&fmt=vtt' @@ -136,11 +135,11 @@ export async function patchYoutubeJs(videoId: string): Promise { let adaptiveFormats: AdaptiveFormats[] = []; video.streaming_data?.adaptive_formats.forEach(format => { adaptiveFormats.push({ - index: format.index_range?.start.toString() || '', - bitrate: format.bitrate.toString(), - init: format.init_range?.start.toString() || '', + index: format.index_range?.start?.toString() || '', + bitrate: format.bitrate?.toString() || '', + init: format.init_range?.start?.toString() || '', url: format.url || '', - itag: format.itag.toString(), + itag: format.itag?.toString() || '', type: format.mime_type, clen: '', lmt: '', @@ -168,9 +167,9 @@ export async function patchYoutubeJs(videoId: string): Promise { return { type: 'video', - title: video.primary_info.title ? video.primary_info.title.toString() : '', - viewCount: video.primary_info.view_count ? Number(video.primary_info.view_count.toString().replace(/\D/g, '')) : 0, - viewCountText: video.primary_info.view_count ? video.primary_info.view_count.toString() : '', + title: video.primary_info.title?.toString() || '', + viewCount: video.primary_info.view_count ? Number(video.primary_info.view_count?.toString()?.replace(/\D/g, '')) : 0, + viewCountText: video.primary_info.view_count?.toString() || '', likeCount: video.basic_info.like_count || 0, dislikeCount: 0, allowRatings: false, @@ -189,9 +188,9 @@ export async function patchYoutubeJs(videoId: string): Promise { authorUrl: `/channel/${video.basic_info.channel_id}`, authorVerified: false, description: descString, - descriptionHtml: video.secondary_info.description.toHTML() || descString, + descriptionHtml: video.secondary_info.description?.toHTML() || descString, published: 0, - publishedText: video.primary_info.published ? video.primary_info.published.toString() : '', + publishedText: video.primary_info.published?.toString() || '', premiereTimestamp: 0, hlsUrl: video.streaming_data?.hls_manifest_url || undefined, liveNow: video.basic_info.is_live || false, @@ -207,4 +206,4 @@ export async function patchYoutubeJs(videoId: string): Promise { allowedRegions: [], fallbackPatch: 'youtubejs' }; -} \ No newline at end of file +}