diff --git a/src/core/Actions.ts b/src/core/Actions.ts index c455a00d..b712e863 100644 --- a/src/core/Actions.ts +++ b/src/core/Actions.ts @@ -49,7 +49,7 @@ class Actions { referer: 'https://www.youtube.com', currentUrl: `/watch?v=${id}`, autonavState: 'STATE_OFF', - signatureTimestamp: this.#session.player.sts, + signatureTimestamp: this.#session.player?.sts || 0, autoCaptionsDefaultOn: false, html5Preference: 'HTML5_PREF_WANTS', lactMilliseconds: '-1' @@ -188,6 +188,7 @@ class Actions { 'FEsubscriptions', 'FEmusic_listening_review', 'FEmusic_library_landing', + 'SPaccount_overview', 'SPaccount_notifications', 'SPaccount_privacy', 'SPtime_watched' diff --git a/src/core/Music.ts b/src/core/Music.ts index d5fa6d0b..41e83bd5 100644 --- a/src/core/Music.ts +++ b/src/core/Music.ts @@ -61,7 +61,7 @@ class Music { videoId: video_id, playbackContext: { contentPlaybackContext: { - signatureTimestamp: this.#session.player.sts + signatureTimestamp: this.#session.player?.sts || 0 } } }); @@ -89,7 +89,7 @@ class Music { client: 'YTMUSIC', playbackContext: { contentPlaybackContext: { - signatureTimestamp: this.#session.player.sts + signatureTimestamp: this.#session.player?.sts || 0 } } }); diff --git a/src/core/Session.ts b/src/core/Session.ts index 91d6d642..fe3cacfa 100644 --- a/src/core/Session.ts +++ b/src/core/Session.ts @@ -78,7 +78,7 @@ export default class Session extends EventEmitterLike { actions; cache; - constructor(context: Context, api_key: string, api_version: string, account_index: number, player: Player, cookie?: string, fetch?: FetchFunction, cache?: UniversalCache) { + constructor(context: Context, api_key: string, api_version: string, account_index: number, player?: Player, cookie?: string, fetch?: FetchFunction, cache?: UniversalCache) { super(); this.#context = context; this.#account_index = account_index; diff --git a/src/parser/classes/misc/Format.ts b/src/parser/classes/misc/Format.ts index df561358..6a409e46 100644 --- a/src/parser/classes/misc/Format.ts +++ b/src/parser/classes/misc/Format.ts @@ -1,4 +1,5 @@ import Player from '../../../core/Player'; +import { InnertubeError } from '../../../utils/Utils'; class Format { itag: string; @@ -73,7 +74,8 @@ class Format { * Decipher the streaming url of the format. * @returns Deciphered URL. */ - decipher(player: Player): string { + decipher(player: Player | undefined): string { + if (!player) throw new InnertubeError('Cannot decipher format, this session appears to have no valid player.'); return player.decipher(this.url, this.signature_cipher, this.cipher); } } diff --git a/src/parser/youtube/VideoInfo.ts b/src/parser/youtube/VideoInfo.ts index d7b89161..e5c4f8ea 100644 --- a/src/parser/youtube/VideoInfo.ts +++ b/src/parser/youtube/VideoInfo.ts @@ -92,7 +92,7 @@ class VideoInfo { * @param data - API response. * @param cpn - Client Playback Nonce */ - constructor(data: [ApiResponse, ApiResponse?], actions: Actions, player: Player, cpn: string) { + constructor(data: [ApiResponse, ApiResponse?], actions: Actions, player?: Player, cpn?: string) { this.#actions = actions; this.#player = player; this.#cpn = cpn; @@ -492,7 +492,7 @@ class VideoInfo { throw new InnertubeError('Index and init ranges not available', { format }); const url = new URL(format.decipher(this.#player)); - url.searchParams.set('cpn', this.#cpn); + url.searchParams.set('cpn', this.#cpn || ''); set.appendChild(this.#el(document, 'Representation', { id: format.itag, @@ -522,7 +522,7 @@ class VideoInfo { throw new InnertubeError('Index and init ranges not available', { format }); const url = new URL(format.decipher(this.#player)); - url.searchParams.set('cpn', this.#cpn); + url.searchParams.set('cpn', this.#cpn || ''); set.appendChild(this.#el(document, 'Representation', { id: format.itag,