UNPKG

@duell10111/youtubei.js

Version:

A JavaScript client for YouTube's private API, known as InnerTube.

55 lines 1.88 kB
import { Parser, PlaylistVideoListContinuation } from '../index.js'; import { InnertubeError } from '../../utils/Utils.js'; import { observe } from '../helpers.js'; import TwoColumn from '../classes/TwoColumn.js'; export default class Playlist { #page; #actions; #continuation; header; contents; background; constructor(response, actions) { this.#actions = actions; this.#page = Parser.parseResponse(response.data); this.#continuation = null; const two_col = this.#page.contents_memo?.getType(TwoColumn)?.[0]; if (two_col) { this.header = two_col.left_column ?? undefined; if (two_col.right_column) { this.#continuation = two_col.right_column.continuation ?? null; this.contents = two_col.right_column.videos ?? null; } } if (this.#page.continuation_contents) { const data = this.#page.continuation_contents?.as(PlaylistVideoListContinuation); if (!data.contents) { throw new InnertubeError('No contents found in the response'); } this.contents = data.contents; this.#continuation = data.continuation ?? null; } } /** * Retrieves playlist items continuation. */ async getContinuation() { if (!this.#continuation) throw new InnertubeError('Continuation not found.'); const response = await this.#actions.execute('/browse', { client: 'TV', continuation: this.#continuation }); return new Playlist(response, this.#actions); } get page() { return this.#page; } get items() { return this.contents || observe([]); } get has_continuation() { return !!this.#continuation; } } //# sourceMappingURL=Playlist.js.map