@duell10111/youtubei.js
Version:
A JavaScript client for YouTube's private API, known as InnerTube.
49 lines • 1.64 kB
JavaScript
import { GridContinuation, Parser } from '../index.js';
import { observe } from '../helpers.js';
import { InnertubeError } from '../../utils/Utils.js';
import Grid from '../classes/Grid.js';
export default class PlaylistsFeed {
#page;
#actions;
#continuation;
contents;
constructor(response, actions) {
this.#actions = actions;
this.#page = Parser.parseResponse(response.data);
const grid = this.#page.contents_memo?.getType(Grid)?.[0];
if (grid) {
this.contents = grid.contents;
this.#continuation = grid.continuation ?? undefined;
}
if (this.#page.continuation_contents) {
const data = this.#page.continuation_contents?.as(GridContinuation);
if (!data.contents) {
throw new InnertubeError('No contents found in the response');
}
this.contents = data.contents;
this.#continuation = data.continuation ?? undefined;
}
}
/**
* 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 PlaylistsFeed(response, this.#actions);
}
get page() {
return this.#page;
}
get items() {
return this.contents || observe([]);
}
get has_continuation() {
return !!this.#continuation;
}
}
//# sourceMappingURL=PlaylistsFeed.js.map