feat: make Player instance optional (#240)

This commit is contained in:
LuanRT
2022-11-16 03:17:59 -03:00
committed by GitHub
parent 0e5e0c0fab
commit fe4c5433cf
5 changed files with 11 additions and 8 deletions

View File

@@ -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);
}
}

View File

@@ -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,