Skip to content

Commit

Permalink
feat(parser): add GridShow and ShowCustomThumbnail
Browse files Browse the repository at this point in the history
Closes #459
  • Loading branch information
LuanRT committed Mar 15, 2023
1 parent b71f03c commit 8ef4b42
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 9 deletions.
29 changes: 29 additions & 0 deletions src/parser/classes/GridShow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ObservedArray, YTNode } from '../helpers.js';
import { RawNode } from '../index.js';
import Parser from '../parser.js';
import Author from './misc/Author.js';
import Text from './misc/Text.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import ShowCustomThumbnail from './ShowCustomThumbnail.js';
import ThumbnailOverlayBottomPanel from './ThumbnailOverlayBottomPanel.js';

export default class GridShow extends YTNode {
static type = 'GridShow';

title: Text;
thumbnail_renderer: ShowCustomThumbnail | null;
endpoint: NavigationEndpoint;
long_byline_text: Text;
thumbnail_overlays: ObservedArray<ThumbnailOverlayBottomPanel> | null;
author: Author;

constructor(data: RawNode) {
super();
this.title = new Text(data.title);
this.thumbnail_renderer = Parser.parseItem(data.thumbnailRenderer, ShowCustomThumbnail);
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);
this.long_byline_text = new Text(data.longBylineText);
this.thumbnail_overlays = Parser.parseArray(data.thumbnailOverlays, ThumbnailOverlayBottomPanel);
this.author = new Author(data.shortBylineText, undefined);
}
}
14 changes: 14 additions & 0 deletions src/parser/classes/ShowCustomThumbnail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { YTNode } from '../helpers.js';
import { RawNode } from '../index.js';
import Thumbnail from './misc/Thumbnail.js';

export default class ShowCustomThumbnail extends YTNode {
static type = 'ShowCustomThumbnail';

thumbnail: Thumbnail[];

constructor(data: RawNode) {
super();
this.thumbnail = Thumbnail.fromResponse(data.thumbnail);
}
}
15 changes: 12 additions & 3 deletions src/parser/classes/ThumbnailOverlayBottomPanel.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import { YTNode } from '../helpers.js';
import { RawNode } from '../index.js';
import Text from './misc/Text.js';

class ThumbnailOverlayBottomPanel extends YTNode {
static type = 'ThumbnailOverlayBottomPanel';

icon_type: string;
text?: Text;
icon_type?: string;

constructor(data: any) {
constructor(data: RawNode) {
super();
this.icon_type = data.icon.iconType;
if (Reflect.has(data, 'text')) {
this.text = new Text(data.text);
}

if (Reflect.has(data, 'icon') && Reflect.has(data.icon, 'iconType')) {
this.icon_type = data.icon.iconType;
}
}
}

Expand Down
13 changes: 7 additions & 6 deletions src/parser/classes/misc/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function escape(text: string) {
.replace(/'/g, '&#039;');
}

class Text {
export default class Text {
text?: string;
runs;
endpoint?: NavigationEndpoint;
Expand All @@ -39,8 +39,11 @@ class Text {
if (typeof data === 'object' && data !== null && Reflect.has(data, 'titleNavigationEndpoint')) {
this.endpoint = new NavigationEndpoint(data.titleNavigationEndpoint);
}
if (!this.endpoint)
this.endpoint = (this.runs?.[0] as TextRun)?.endpoint;
if (!this.endpoint) {
if ((this.runs?.[0] as TextRun)?.endpoint) {
this.endpoint = (this.runs?.[0] as TextRun)?.endpoint;
}
}
}

toHTML() {
Expand All @@ -54,6 +57,4 @@ class Text {
toString() {
return this.text || 'N/A';
}
}

export default Text;
}
2 changes: 2 additions & 0 deletions src/parser/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export { default as GridHeader } from './classes/GridHeader.js';
export { default as GridMix } from './classes/GridMix.js';
export { default as GridMovie } from './classes/GridMovie.js';
export { default as GridPlaylist } from './classes/GridPlaylist.js';
export { default as GridShow } from './classes/GridShow.js';
export { default as GridVideo } from './classes/GridVideo.js';
export { default as GuideCollapsibleEntry } from './classes/GuideCollapsibleEntry.js';
export { default as GuideCollapsibleSectionEntry } from './classes/GuideCollapsibleSectionEntry.js';
Expand Down Expand Up @@ -283,6 +284,7 @@ export { default as SettingsSidebar } from './classes/SettingsSidebar.js';
export { default as SettingsSwitch } from './classes/SettingsSwitch.js';
export { default as SharedPost } from './classes/SharedPost.js';
export { default as Shelf } from './classes/Shelf.js';
export { default as ShowCustomThumbnail } from './classes/ShowCustomThumbnail.js';
export { default as ShowingResultsFor } from './classes/ShowingResultsFor.js';
export { default as SimpleCardContent } from './classes/SimpleCardContent.js';
export { default as SimpleCardTeaser } from './classes/SimpleCardTeaser.js';
Expand Down

0 comments on commit 8ef4b42

Please sign in to comment.