diff --git a/play-dl/YouTube/classes/Video.ts b/play-dl/YouTube/classes/Video.ts index 9ac9418..6dcf2c3 100644 --- a/play-dl/YouTube/classes/Video.ts +++ b/play-dl/YouTube/classes/Video.ts @@ -65,7 +65,7 @@ interface VideoOptions { /** * `true` if the video has been identified by the YouTube community as inappropriate or offensive to some audiences and viewer discretion is advised */ - discretionAdvised: boolean; + discretionAdvised?: boolean; } /** * Class for YouTube Video url @@ -134,7 +134,7 @@ export class YouTubeVideo { /** * `true` if the video has been identified by the YouTube community as inappropriate or offensive to some audiences and viewer discretion is advised */ - discretionAdvised: boolean; + discretionAdvised?: boolean; /** * Constructor for YouTube Video Class * @param data JSON parsed data. @@ -161,7 +161,7 @@ export class YouTubeVideo { this.live = !!data.live; this.private = !!data.private; this.tags = data.tags || []; - this.discretionAdvised = !!data.discretionAdvised; + this.discretionAdvised = data.discretionAdvised === undefined ? undefined : data.discretionAdvised; } /** * Converts class to title name of video. diff --git a/play-dl/YouTube/utils/extractor.ts b/play-dl/YouTube/utils/extractor.ts index 9b3f022..701adeb 100644 --- a/play-dl/YouTube/utils/extractor.ts +++ b/play-dl/YouTube/utils/extractor.ts @@ -145,12 +145,14 @@ export async function video_basic_info(url: string, options: InfoOptions = {}): ); discretionAdvised = true; const cookies = - initial_response.topbar.desktopTopbarRenderer.interstitial.consentBumpV2Renderer.agreeButton + initial_response.topbar.desktopTopbarRenderer.interstitial?.consentBumpV2Renderer.agreeButton .buttonRenderer.command.saveConsentAction; - Object.assign(cookieJar, { - VISITOR_INFO1_LIVE: cookies.visitorCookie, - CONSENT: cookies.consentCookie - }); + if (cookies) { + Object.assign(cookieJar, { + VISITOR_INFO1_LIVE: cookies.visitorCookie, + CONSENT: cookies.consentCookie + }); + } const updatedValues = await acceptViewerDiscretion(vid.videoId, cookieJar, body, true); player_response.streamingData = updatedValues.streamingData; @@ -270,12 +272,14 @@ export async function video_stream_info(url: string, options: InfoOptions = {}): if (!initial_data) throw new Error('Initial Response Data is undefined.'); const cookies = - JSON.parse(initial_data).topbar.desktopTopbarRenderer.interstitial.consentBumpV2Renderer.agreeButton + JSON.parse(initial_data).topbar.desktopTopbarRenderer.interstitial?.consentBumpV2Renderer.agreeButton .buttonRenderer.command.saveConsentAction; - Object.assign(cookieJar, { - VISITOR_INFO1_LIVE: cookies.visitorCookie, - CONSENT: cookies.consentCookie - }); + if (cookies) { + Object.assign(cookieJar, { + VISITOR_INFO1_LIVE: cookies.visitorCookie, + CONSENT: cookies.consentCookie + }); + } const updatedValues = await acceptViewerDiscretion( player_response.videoDetails.videoId, @@ -463,7 +467,6 @@ export function getContinuationToken(data: any): string { .continuationEndpoint?.continuationCommand?.token; } - async function acceptViewerDiscretion( videoId: string, cookieJar: { [key: string]: string },