@duell10111/youtubei.js
Version:
A JavaScript client for YouTube's private API, known as InnerTube.
40 lines • 1.54 kB
JavaScript
import SectionList from '../classes/SectionList.js';
import { InnertubeError } from '../../utils/Utils.js';
import { Parser, SectionListContinuation } from '../index.js';
export default class HomeFeed {
#page;
#actions;
#continuation;
sections;
constructor(response, actions) {
this.#actions = actions;
this.#page = Parser.parseResponse(response.data);
const sectionList = this.#page.contents_memo?.getType(SectionList).firstOfType(SectionList);
this.sections = sectionList?.contents;
this.#continuation = sectionList?.continuation;
if (!sectionList) {
if (!this.#page.continuation_contents) {
throw new InnertubeError('Continuation did not have any content.');
}
const sectionListContinuation = this.#page.continuation_contents.as(SectionListContinuation);
this.#continuation = sectionListContinuation.continuation;
this.sections = sectionListContinuation.contents ?? undefined;
}
}
/**
* Retrieves home feed 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 HomeFeed(response, this.#actions);
}
get has_continuation() {
return !!this.#continuation;
}
}
//# sourceMappingURL=HomeFeed.js.map