mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-23 23:09:28 +00:00
feat(ytkids): add getChannel() (#292)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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';
|
||||
|
||||
34
src/parser/ytkids/Channel.ts
Normal file
34
src/parser/ytkids/Channel.ts
Normal 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;
|
||||
Reference in New Issue
Block a user