-
-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(yt): add `getGuide()` * chore: lint * fix(Guide): wrong prop * fix(Guide): include subscription section * fix(Guide): wrong import * feat(Guide): add `page`
- Loading branch information
1 parent
2d774e2
commit 2cc7b8b
Showing
13 changed files
with
204 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import GuideSection from './GuideSection.js'; | ||
|
||
class GuideSubscriptionsSection extends GuideSection { | ||
static type = 'GuideSubscriptionsSection'; | ||
} | ||
|
||
export default GuideSubscriptionsSection; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { IGuideResponse } from '../types/ParsedResponse.js'; | ||
import { IRawResponse, Parser } from '../index.js'; | ||
import { ObservedArray } from '../helpers.js'; | ||
import GuideSection from '../classes/GuideSection.js'; | ||
import GuideSubscriptionsSection from '../classes/GuideSubscriptionsSection.js'; | ||
|
||
export default class Guide { | ||
|
||
#page: IGuideResponse; | ||
contents: ObservedArray<GuideSection | GuideSubscriptionsSection>; | ||
|
||
constructor(data: IRawResponse) { | ||
this.#page = Parser.parseResponse<IGuideResponse>(data); | ||
this.contents = this.#page.items.array().as(GuideSection, GuideSubscriptionsSection); | ||
} | ||
|
||
get page(): IGuideResponse { | ||
return this.#page; | ||
} | ||
} |