mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-23 23:09:28 +00:00
feat: make Player instance optional (#240)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user