feat(ytkids): add getChannel() (#292)

This commit is contained in:
LuanRT
2023-01-23 05:38:53 -03:00
committed by GitHub
parent 2bbefefbb7
commit 0fc29f0bbf
8 changed files with 107 additions and 2 deletions

View File

@@ -10,7 +10,8 @@ class ItemSection extends YTNode {
header: CommentsHeader | ItemSectionHeader | ItemSectionTabbedHeader | null;
contents;
target_id;
target_id?: string;
continuation?: string;
constructor(data: any) {
super();
@@ -20,6 +21,10 @@ class ItemSection extends YTNode {
if (data.targetId || data.sectionIdentifier) {
this.target_id = data?.target_id || data?.sectionIdentifier;
}
if (data.continuations) {
this.continuation = data.continuations?.at(0)?.nextContinuationData?.continuation;
}
}
}

View File

@@ -269,6 +269,8 @@ export default class Parser {
}
static parseLC(data: any) {
if (data.itemSectionContinuation)
return new ItemSectionContinuation(data.itemSectionContinuation);
if (data.sectionListContinuation)
return new SectionListContinuation(data.sectionListContinuation);
if (data.liveChatContinuation)
@@ -387,7 +389,22 @@ export default class Parser {
export type ParsedResponse = ReturnType<typeof Parser.parseResponse>;
// Continuation nodes
// Continuation
export class ItemSectionContinuation extends YTNode {
static readonly type = 'itemSectionContinuation';
contents: ObservedArray<YTNode> | null;
continuation?: string;
constructor(data: any) {
super();
this.contents = Parser.parseArray(data.contents);
if (data.continuations) {
this.continuation = data.continuations?.at(0)?.nextContinuationData?.continuation;
}
}
}
export class AppendContinuationItemsAction extends YTNode {
static readonly type = 'appendContinuationItemsAction';

View File

@@ -0,0 +1,34 @@
import Feed from '../../core/Feed';
import Actions from '../../core/Actions';
import C4TabbedHeader from '../classes/C4TabbedHeader';
import ItemSection from '../classes/ItemSection';
import { ItemSectionContinuation } from '..';
class Channel extends Feed {
header?: C4TabbedHeader;
contents?: ItemSection | ItemSectionContinuation;
constructor(actions: Actions, data: any, 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 videos.
*/
async getContinuation(): Promise<Channel> {
const response = await this.actions.execute('/browse', {
continuation: this.contents?.continuation,
client: 'YTKIDS'
});
return new Channel(this.actions, response.data);
}
get has_continuation(): boolean {
return !!this.contents?.continuation;
}
}
export default Channel;