feat(yt): add getGuide() (#335)

* feat(yt): add `getGuide()`

* chore: lint

* fix(Guide): wrong prop

* fix(Guide): include subscription section

* fix(Guide): wrong import

* feat(Guide): add `page`
This commit is contained in:
Patrick Kan
2023-03-04 17:23:17 +08:00
committed by GitHub
parent 2d774e26aa
commit 2cc7b8bcd6
13 changed files with 204 additions and 1 deletions

View File

@@ -0,0 +1,35 @@
import Text from './misc/Text.js';
import { YTNode } from '../helpers.js';
import Parser from '../parser.js';
class GuideCollapsibleEntry extends YTNode {
static type = 'GuideCollapsibleEntry';
expander_item: {
title: string,
icon_type: string
};
collapser_item: {
title: string,
icon_type: string
};
expandable_items;
constructor(data: any) {
super();
this.expander_item = {
title: new Text(data.expanderItem.guideEntryRenderer.formattedTitle).toString(),
icon_type: data.expanderItem.guideEntryRenderer.icon.iconType
};
this.collapser_item = {
title: new Text(data.collapserItem.guideEntryRenderer.formattedTitle).toString(),
icon_type: data.collapserItem.guideEntryRenderer.icon.iconType
};
this.expandable_items = Parser.parseArray(data.expandableItems);
}
}
export default GuideCollapsibleEntry;

View File

@@ -0,0 +1,23 @@
import { YTNode } from '../helpers.js';
import Parser from '../parser.js';
class GuideCollapsibleSectionEntry extends YTNode {
static type = 'GuideCollapsibleSectionEntry';
header_entry;
expander_icon: string;
collapser_icon: string;
section_items;
constructor(data: any) {
super();
this.header_entry = Parser.parseItem(data.headerEntry);
this.expander_icon = data.expanderIcon.iconType;
this.collapser_icon = data.collapserIcon.iconType;
this.section_items = Parser.parseArray(data.sectionItems);
}
}
export default GuideCollapsibleSectionEntry;

View File

@@ -0,0 +1,14 @@
import GuideEntry from './GuideEntry.js';
class GuideDownloadsEntry extends GuideEntry {
static type = 'GuideDownloadsEntry';
always_show: boolean;
constructor(data: any) {
super(data.entryRenderer.guideEntryRenderer);
this.always_show = !!data.alwaysShow;
}
}
export default GuideDownloadsEntry;

View File

@@ -0,0 +1,33 @@
import Text from './misc/Text.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import { YTNode } from '../helpers.js';
import Thumbnail from './misc/Thumbnail.js';
class GuideEntry extends YTNode {
static type = 'GuideEntry';
title: Text;
endpoint: NavigationEndpoint;
icon_type?: string;
thumbnails?: Thumbnail[];
badges?: any;
is_primary: boolean;
constructor(data: any) {
super();
this.title = new Text(data.formattedTitle);
this.endpoint = new NavigationEndpoint(data.navigationEndpoint || data.serviceEndpoint);
if (data.icon?.iconType) {
this.icon_type = data.icon.iconType;
}
if (data.thumbnail) {
this.thumbnails = Thumbnail.fromResponse(data.thumbnail);
}
if (data.badges) {
this.badges = data.badges;
}
this.is_primary = !!data.isPrimary;
}
}
export default GuideEntry;

View File

@@ -0,0 +1,20 @@
import Text from './misc/Text.js';
import { YTNode } from '../helpers.js';
import Parser from '../parser.js';
class GuideSection extends YTNode {
static type = 'GuideSection';
title?: Text;
items;
constructor(data: any) {
super();
if (data.formattedTitle) {
this.title = new Text(data.formattedTitle);
}
this.items = Parser.parseArray(data.items);
}
}
export default GuideSection;

View File

@@ -0,0 +1,7 @@
import GuideSection from './GuideSection.js';
class GuideSubscriptionsSection extends GuideSection {
static type = 'GuideSubscriptionsSection';
}
export default GuideSubscriptionsSection;