-
-
Notifications
You must be signed in to change notification settings - Fork 239
/
Channel.ts
42 lines (34 loc) · 1.49 KB
/
Channel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import Feed from '../../core/mixins/Feed.js';
import C4TabbedHeader from '../classes/C4TabbedHeader.js';
import ItemSection from '../classes/ItemSection.js';
import { ItemSectionContinuation } from '../index.js';
import NavigationEndpoint from '../classes/NavigationEndpoint.js';
import type { IBrowseResponse } from '../types/index.js';
import type { ApiResponse, Actions } from '../../core/index.js';
export default class Channel extends Feed<IBrowseResponse> {
public header?: C4TabbedHeader;
public contents?: ItemSection | ItemSectionContinuation;
constructor(actions: Actions, data: ApiResponse | IBrowseResponse, already_parsed = false) {
super(actions, data, already_parsed);
this.header = this.page.header?.item().as(C4TabbedHeader);
this.contents = this.memo.getType(ItemSection).first() || this.page.continuation_contents?.as(ItemSectionContinuation);
}
/**
* Retrieves next batch of content.
*/
async getContinuation(): Promise<Channel> {
if (!this.contents)
throw new Error('No continuation available.');
const continuation_request = new NavigationEndpoint({
continuationCommand: {
token: this.contents.continuation,
request: 'CONTINUATION_REQUEST_TYPE_BROWSE'
}
});
const continuation_response = await continuation_request.call(this.actions, { client: 'YTKIDS' });
return new Channel(this.actions, continuation_response);
}
get has_continuation(): boolean {
return !!this.contents?.continuation;
}
}