@duell10111/youtubei.js
Version:
A JavaScript client for YouTube's private API, known as InnerTube.
55 lines • 2.92 kB
JavaScript
var _SubscriptionsFeed_page, _SubscriptionsFeed_actions, _SubscriptionsFeed_continuation;
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
import { GridContinuation, Parser } from '../index.js';
import { observe } from '../helpers.js';
import { InnertubeError } from '../../utils/Utils.js';
import Tab from '../classes/Tab.js';
import TvSurfaceContent from '../classes/TvSurfaceContent.js';
import Grid from '../classes/Grid.js';
class SubscriptionsFeed {
constructor(response, actions) {
_SubscriptionsFeed_page.set(this, void 0);
_SubscriptionsFeed_actions.set(this, void 0);
_SubscriptionsFeed_continuation.set(this, void 0);
__classPrivateFieldSet(this, _SubscriptionsFeed_actions, actions, "f");
__classPrivateFieldSet(this, _SubscriptionsFeed_page, Parser.parseResponse(response.data), "f");
const grid = __classPrivateFieldGet(this, _SubscriptionsFeed_page, "f").contents_memo?.getType(Tab)?.first()?.content?.as(TvSurfaceContent)?.content?.as(Grid);
if (grid) {
this.contents = grid.contents;
__classPrivateFieldSet(this, _SubscriptionsFeed_continuation, grid.continuation ?? undefined, "f");
}
if (__classPrivateFieldGet(this, _SubscriptionsFeed_page, "f").continuation_contents) {
const data = __classPrivateFieldGet(this, _SubscriptionsFeed_page, "f").continuation_contents?.as(GridContinuation);
if (!data.contents) {
throw new InnertubeError('No contents found in the response');
}
this.contents = data.contents;
__classPrivateFieldSet(this, _SubscriptionsFeed_continuation, data.continuation ?? undefined, "f");
}
}
// TODO: Add option to switch to other tabs (other channels) available
/**
* Retrieves subscription items continuation.
*/
async getContinuation() {
if (!__classPrivateFieldGet(this, _SubscriptionsFeed_continuation, "f"))
throw new InnertubeError('Continuation not found.');
const response = await __classPrivateFieldGet(this, _SubscriptionsFeed_actions, "f").execute('/browse', {
client: 'TV',
continuation: __classPrivateFieldGet(this, _SubscriptionsFeed_continuation, "f")
});
return new SubscriptionsFeed(response, __classPrivateFieldGet(this, _SubscriptionsFeed_actions, "f"));
}
get page() {
return __classPrivateFieldGet(this, _SubscriptionsFeed_page, "f");
}
get items() {
return this.contents || observe([]);
}
get has_continuation() {
return !!__classPrivateFieldGet(this, _SubscriptionsFeed_continuation, "f");
}
}
_SubscriptionsFeed_page = new WeakMap(), _SubscriptionsFeed_actions = new WeakMap(), _SubscriptionsFeed_continuation = new WeakMap();
export default SubscriptionsFeed;
//# sourceMappingURL=SubscriptionsFeed.js.map