refactor(parser): improve typings and do some refactoring (#305)

* dev: add response types

* dev: refactor `Parser#parseResponse()`

* dev: update YouTube parsers

* dev: update YouTube Music classes

* dev: update YouTube Kids classes

* dev: update core classes

* dev(Parser): fix some inconsistencies

* chore: update docs

* chore: update docs x2

* fix: export response types 

* chore(docs): update parser example
This commit is contained in:
LuanRT
2023-02-12 07:04:17 -03:00
committed by GitHub
parent 2ccbe2ce62
commit eb72c2f6ef
61 changed files with 1116 additions and 571 deletions

View File

@@ -11,23 +11,35 @@ class MusicShelf extends YTNode {
title: Text;
contents;
endpoint: NavigationEndpoint | null;
continuation: string | null;
bottom_text: Text | null;
endpoint?: NavigationEndpoint;
continuation?: string;
bottom_text?: Text;
bottom_button?: Button | null;
subheaders?: Array<any>;
constructor(data: any) {
super();
this.title = new Text(data.title);
this.contents = Parser.parseArray<MusicResponsiveListItem>(data.contents, MusicResponsiveListItem);
this.endpoint = Reflect.has(data, 'bottomEndpoint') ? new NavigationEndpoint(data.bottomEndpoint) : null;
this.continuation =
data.continuations?.[0].nextContinuationData?.continuation ||
data.continuations?.[0].reloadContinuationData?.continuation || null;
this.bottom_text = Reflect.has(data, 'bottomText') ? new Text(data.bottomText) : null;
this.bottom_button = Parser.parseItem(data.bottomButton, Button);
if (data.bottomEndpoint) {
this.endpoint = new NavigationEndpoint(data.bottomEndpoint);
}
if (data.continuations) {
this.continuation =
data.continuations?.[0].nextContinuationData?.continuation ||
data.continuations?.[0].reloadContinuationData?.continuation;
}
if (data.bottomText) {
this.bottom_text = new Text(data.bottomText);
}
if (data.bottomButton) {
this.bottom_button = Parser.parseItem<Button>(data.bottomButton);
}
if (data.subheaders) {
this.subheaders = Parser.parseArray(data.subheaders);
}