@duell10111/youtubei.js
Version:
A JavaScript client for YouTube's private API, known as InnerTube.
84 lines • 4.72 kB
JavaScript
var _Library_page, _Library_actions, _Library_continuation;
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
import { GridContinuation, Parser, SectionListContinuation, TvSurfaceContentContinuation } from '../index.js';
import { observe } from '../helpers.js';
import { InnertubeError } from '../../utils/Utils.js';
import SectionList from '../classes/SectionList.js';
import TvSurfaceContent from '../classes/TvSurfaceContent.js';
import Grid from '../classes/Grid.js';
class Library {
constructor(response, actions) {
_Library_page.set(this, void 0);
_Library_actions.set(this, void 0);
_Library_continuation.set(this, void 0);
__classPrivateFieldSet(this, _Library_actions, actions, "f");
__classPrivateFieldSet(this, _Library_page, Parser.parseResponse(response.data), "f");
const tvSurfaceContent = __classPrivateFieldGet(this, _Library_page, "f").contents_memo?.getType(TvSurfaceContent)?.first();
if (tvSurfaceContent) {
if (tvSurfaceContent.content?.is(SectionList)) {
this.contents = tvSurfaceContent.content.contents;
__classPrivateFieldSet(this, _Library_continuation, tvSurfaceContent.content.continuation, "f");
}
else if (tvSurfaceContent.content?.is(Grid)) {
this.contents = tvSurfaceContent.content.contents;
__classPrivateFieldSet(this, _Library_continuation, tvSurfaceContent.content.continuation ?? undefined, "f");
}
}
if (__classPrivateFieldGet(this, _Library_page, "f").continuation_contents) {
if (__classPrivateFieldGet(this, _Library_page, "f").continuation_contents?.is(SectionListContinuation)) {
const data = __classPrivateFieldGet(this, _Library_page, "f").continuation_contents?.as(SectionListContinuation);
if (!data.contents) {
throw new InnertubeError('No contents found in the response');
}
this.contents = data.contents;
__classPrivateFieldSet(this, _Library_continuation, data.continuation ?? undefined, "f");
}
else if (__classPrivateFieldGet(this, _Library_page, "f").continuation_contents?.is(GridContinuation)) {
const data = __classPrivateFieldGet(this, _Library_page, "f").continuation_contents?.as(GridContinuation);
this.contents = data.contents ?? undefined;
__classPrivateFieldSet(this, _Library_continuation, data.continuation ?? undefined, "f");
}
else if (__classPrivateFieldGet(this, _Library_page, "f").continuation_contents?.is(TvSurfaceContentContinuation)) {
const data = __classPrivateFieldGet(this, _Library_page, "f").continuation_contents?.as(TvSurfaceContentContinuation);
// Nested data
if (data?.content?.is(Grid)) {
this.contents = data?.content.contents ?? undefined;
__classPrivateFieldSet(this, _Library_continuation, data?.content.continuation ?? undefined, "f");
}
}
}
}
async selectButtonTile(tile) {
if (tile.style === 'TILE_STYLE_YTLR_WORMHOLE_RECTANGULAR' && tile.content_id && ['FEhistory', 'FEplaylist_aggregation'].includes(tile.content_id)) {
const response = await tile.on_select_endpoint.call(__classPrivateFieldGet(this, _Library_actions, "f"), {
client: 'TV'
});
return new Library(response, __classPrivateFieldGet(this, _Library_actions, "f"));
}
throw new InnertubeError(`Tile with content_id ${tile.content_id} not found`);
}
/**
* Retrieves library items continuation.
*/
async getContinuation() {
if (!__classPrivateFieldGet(this, _Library_continuation, "f"))
throw new InnertubeError('Continuation not found.');
const response = await __classPrivateFieldGet(this, _Library_actions, "f").execute('/browse', {
client: 'TV',
continuation: __classPrivateFieldGet(this, _Library_continuation, "f")
});
return new Library(response, __classPrivateFieldGet(this, _Library_actions, "f"));
}
get page() {
return __classPrivateFieldGet(this, _Library_page, "f");
}
get items() {
return this.contents || observe([]);
}
get has_continuation() {
return !!__classPrivateFieldGet(this, _Library_continuation, "f");
}
}
_Library_page = new WeakMap(), _Library_actions = new WeakMap(), _Library_continuation = new WeakMap();
export default Library;
//# sourceMappingURL=Library.js.map