Skip to content

Commit

Permalink
refactor(parser): fix many minor inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanRT committed Mar 15, 2023
1 parent 1a2fc3a commit 3d34364
Show file tree
Hide file tree
Showing 35 changed files with 141 additions and 141 deletions.
8 changes: 4 additions & 4 deletions src/parser/classes/ChannelFeaturedContent.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import Parser from '../index.js';
import Text from './misc/Text.js';
import { YTNode } from '../helpers.js';
import Parser, { RawNode } from '../index.js';
import Text from './misc/Text.js';

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

title: Text;
items;

constructor(data: any) {
constructor(data: RawNode) {
super();
this.title = new Text(data.title);
this.items = Parser.parse(data.items);
this.items = Parser.parseArray(data.items);
}
}

Expand Down
17 changes: 8 additions & 9 deletions src/parser/classes/CompactVideo.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import Parser from '../index.js';
import Text from './misc/Text.js';
import Author from './misc/Author.js';
import { timeToSeconds } from '../../utils/Utils.js';
import { YTNode } from '../helpers.js';
import Parser, { RawNode } from '../index.js';
import Menu from './menus/Menu.js';
import MetadataBadge from './MetadataBadge.js';
import Author from './misc/Author.js';
import Text from './misc/Text.js';
import Thumbnail from './misc/Thumbnail.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import type Menu from './menus/Menu.js';
import MetadataBadge from './MetadataBadge.js';

import { YTNode } from '../helpers.js';

class CompactVideo extends YTNode {
static type = 'CompactVideo';
Expand All @@ -31,7 +30,7 @@ class CompactVideo extends YTNode {
endpoint: NavigationEndpoint;
menu: Menu | null;

constructor(data: any) {
constructor(data: RawNode) {
super();
this.id = data.videoId;
this.thumbnails = Thumbnail.fromResponse(data.thumbnail) || null;
Expand All @@ -50,7 +49,7 @@ class CompactVideo extends YTNode {

this.thumbnail_overlays = Parser.parseArray(data.thumbnailOverlays);
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);
this.menu = Parser.parseItem<Menu>(data.menu);
this.menu = Parser.parseItem(data.menu, Menu);
}

get best_thumbnail() {
Expand Down
4 changes: 2 additions & 2 deletions src/parser/classes/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class Element extends YTNode {
super();

if (Reflect.has(data, 'elementRenderer')) {
return Parser.parseItem<Element>(data, Element) as Element;
return Parser.parseItem(data, Element) as Element;
}

const type = data.newElement.type.componentType;
this.model = Parser.parse(type?.model);
this.model = Parser.parseItem(type?.model);

if (data.newElement?.childElements) {
this.child_elements = data.newElement?.childElements?.map((el: any) => new ChildElement(el)) || null;
Expand Down
10 changes: 5 additions & 5 deletions src/parser/classes/EmergencyOnebox.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Text from './misc/Text.js';
import Parser from '../index.js';
import { YTNode } from '../helpers.js';
import Parser, { RawNode } from '../index.js';
import Text from './misc/Text.js';

class EmergencyOnebox extends YTNode {
static type = 'EmergencyOnebox';
Expand All @@ -9,11 +9,11 @@ class EmergencyOnebox extends YTNode {
first_option;
menu;

constructor(data: any) {
constructor(data: RawNode) {
super();
this.title = new Text(data.title);
this.first_option = Parser.parse(data.firstOption);
this.menu = Parser.parse(data.menu);
this.first_option = Parser.parseItem(data.firstOption);
this.menu = Parser.parseItem(data.menu);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/parser/classes/EndScreenVideo.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Parser from '../index.js';
import Text from './misc/Text.js';
import { YTNode } from '../helpers.js';
import Parser, { RawNode } from '../index.js';
import Author from './misc/Author.js';
import Text from './misc/Text.js';
import Thumbnail from './misc/Thumbnail.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import { YTNode } from '../helpers.js';

class EndScreenVideo extends YTNode {
static type = 'EndScreenVideo';
Expand All @@ -22,12 +22,12 @@ class EndScreenVideo extends YTNode {
seconds: number;
};

constructor(data: any) {
constructor(data: RawNode) {
super();
this.id = data.videoId;
this.title = new Text(data.title);
this.thumbnails = Thumbnail.fromResponse(data.thumbnail);
this.thumbnail_overlays = Parser.parse(data.thumbnailOverlays);
this.thumbnail_overlays = Parser.parseArray(data.thumbnailOverlays);
this.author = new Author(data.shortBylineText, data.ownerBadges);
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);
this.short_view_count = new Text(data.shortViewCountText);
Expand Down
6 changes: 3 additions & 3 deletions src/parser/classes/Grid.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Parser from '../index.js';
import Parser, { RawNode } from '../index.js';
import { YTNode } from '../helpers.js';

class Grid extends YTNode {
Expand All @@ -11,13 +11,13 @@ class Grid extends YTNode {
continuation: string | null;
header?;

constructor(data: any) {
constructor(data: RawNode) {
super();

this.items = Parser.parseArray(data.items);

if (data.header) {
this.header = Parser.parse(data.header);
this.header = Parser.parseItem(data.header);
}

if (data.isCollapsible) {
Expand Down
10 changes: 5 additions & 5 deletions src/parser/classes/GridChannel.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { YTNode } from '../helpers.js';
import Parser, { RawNode } from '../index.js';
import Author from './misc/Author.js';
import Parser from '../index.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import Text from './misc/Text.js';
import { YTNode } from '../helpers.js';
import NavigationEndpoint from './NavigationEndpoint.js';

class GridChannel extends YTNode {
static type = 'GridChannel';
Expand All @@ -14,7 +14,7 @@ class GridChannel extends YTNode {
endpoint: NavigationEndpoint;
subscribe_button;

constructor(data: any) {
constructor(data: RawNode) {
super();
this.id = data.channelId;

Expand All @@ -26,7 +26,7 @@ class GridChannel extends YTNode {
this.subscribers = new Text(data.subscriberCountText);
this.video_count = new Text(data.videoCountText);
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);
this.subscribe_button = Parser.parse(data.subscribeButton);
this.subscribe_button = Parser.parseItem(data.subscribeButton);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/parser/classes/GridPlaylist.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { YTNode } from '../helpers.js';
import Parser, { RawNode } from '../index.js';
import PlaylistAuthor from './misc/PlaylistAuthor.js';
import Text from './misc/Text.js';
import Parser from '../index.js';
import Thumbnail from './misc/Thumbnail.js';
import PlaylistAuthor from './misc/PlaylistAuthor.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import { YTNode } from '../helpers.js';

class GridPlaylist extends YTNode {
static type = 'GridPlaylist';
Expand All @@ -20,7 +20,7 @@ class GridPlaylist extends YTNode {
video_count: Text;
video_count_short: Text;

constructor(data: any) {
constructor(data: RawNode) {
super();
this.id = data.playlistId;
this.title = new Text(data.title);
Expand All @@ -29,11 +29,11 @@ class GridPlaylist extends YTNode {
this.author = new PlaylistAuthor(data.shortBylineText, data.ownerBadges);
}

this.badges = Parser.parse(data.ownerBadges);
this.badges = Parser.parseArray(data.ownerBadges);
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);
this.view_playlist = new Text(data.viewPlaylistText);
this.thumbnails = Thumbnail.fromResponse(data.thumbnail);
this.thumbnail_renderer = Parser.parse(data.thumbnailRenderer);
this.thumbnail_renderer = Parser.parseItem(data.thumbnailRenderer);
this.sidebar_thumbnails = [].concat(...data.sidebarThumbnails?.map((thumbnail: any) => Thumbnail.fromResponse(thumbnail)) || []) || null;
this.video_count = new Text(data.thumbnailText);
this.video_count_short = new Text(data.videoCountShortText);
Expand Down
6 changes: 3 additions & 3 deletions src/parser/classes/GridVideo.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Parser from '../index.js';
import Parser, { RawNode } from '../index.js';
import Text from './misc/Text.js';
import Thumbnail from './misc/Thumbnail.js';
import NavigationEndpoint from './NavigationEndpoint.js';
Expand All @@ -24,14 +24,14 @@ class GridVideo extends YTNode {
endpoint: NavigationEndpoint;
menu: Menu | null;

constructor(data: any) {
constructor(data: RawNode) {
super();
const length_alt = data.thumbnailOverlays.find((overlay: any) => overlay.hasOwnProperty('thumbnailOverlayTimeStatusRenderer'))?.thumbnailOverlayTimeStatusRenderer;
this.id = data.videoId;
this.title = new Text(data.title);
this.thumbnails = Thumbnail.fromResponse(data.thumbnail);
this.thumbnail_overlays = Parser.parseArray(data.thumbnailOverlays);
this.rich_thumbnail = data.richThumbnail && Parser.parse(data.richThumbnail);
this.rich_thumbnail = data.richThumbnail && Parser.parseItem(data.richThumbnail);
this.published = new Text(data.publishedTimeText);
this.duration = data.lengthText ? new Text(data.lengthText) : length_alt?.text ? new Text(length_alt.text) : null;
this.author = data.shortBylineText && new Author(data.shortBylineText, data.ownerBadges);
Expand Down
8 changes: 4 additions & 4 deletions src/parser/classes/LiveChat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Parser from '../index.js';
import Text from './misc/Text.js';
import { YTNode } from '../helpers.js';
import Parser, { RawNode } from '../index.js';
import Text from './misc/Text.js';

class LiveChat extends YTNode {
static type = 'LiveChat';
Expand All @@ -19,9 +19,9 @@ class LiveChat extends YTNode {

is_replay: boolean;

constructor(data: any) {
constructor(data: RawNode) {
super();
this.header = Parser.parse(data.header);
this.header = Parser.parseItem(data.header);
this.initial_display_state = data.initialDisplayState;
this.continuation = data.continuations[0]?.reloadContinuationData?.continuation;

Expand Down
8 changes: 4 additions & 4 deletions src/parser/classes/MerchandiseShelf.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Parser from '../index.js';
import { YTNode } from '../helpers.js';
import Parser, { RawNode } from '../index.js';

class MerchandiseShelf extends YTNode {
static type = 'MerchandiseShelf';
Expand All @@ -8,11 +8,11 @@ class MerchandiseShelf extends YTNode {
menu;
items;

constructor(data: any) {
constructor(data: RawNode) {
super();
this.title = data.title;
this.menu = Parser.parse(data.actionButton);
this.items = Parser.parse(data.items);
this.menu = Parser.parseItem(data.actionButton);
this.items = Parser.parseArray(data.items);
}

// XXX: alias for consistency
Expand Down
8 changes: 4 additions & 4 deletions src/parser/classes/Movie.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Parser from '../index.js';
import Parser, { RawNode } from '../index.js';
import Author from './misc/Author.js';
import Thumbnail from './misc/Thumbnail.js';
import NavigationEndpoint from './NavigationEndpoint.js';
Expand Down Expand Up @@ -28,7 +28,7 @@ class Movie extends YTNode {
show_action_menu: boolean;
menu;

constructor(data: any) {
constructor(data: RawNode) {
super();
const overlay_time_status = data.thumbnailOverlays
.find((overlay: any) => overlay.thumbnailOverlayTimeStatusRenderer)
Expand All @@ -39,7 +39,7 @@ class Movie extends YTNode {
this.description_snippet = data.descriptionSnippet ? new Text(data.descriptionSnippet) : null;
this.top_metadata_items = new Text(data.topMetadataItems);
this.thumbnails = Thumbnail.fromResponse(data.thumbnail);
this.thumbnail_overlays = Parser.parse(data.thumbnailOverlays);
this.thumbnail_overlays = Parser.parseArray(data.thumbnailOverlays);
this.author = new Author(data.longBylineText, data.ownerBadges, data.channelThumbnailSupportedRenderers?.channelThumbnailWithLinkRenderer?.thumbnail);

this.duration = {
Expand All @@ -51,7 +51,7 @@ class Movie extends YTNode {
this.badges = Parser.parse(data.badges);
this.use_vertical_poster = data.useVerticalPoster;
this.show_action_menu = data.showActionMenu;
this.menu = Parser.parse(data.menu);
this.menu = Parser.parseItem(data.menu);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/parser/classes/MusicDetailHeader.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { YTNode } from '../helpers.js';
import Parser, { RawNode } from '../index.js';
import Text from './misc/Text.js';
import TextRun from './misc/TextRun.js';
import Thumbnail from './misc/Thumbnail.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import Parser from '../index.js';
import { YTNode } from '../helpers.js';

class MusicDetailHeader extends YTNode {
static type = 'MusicDetailHeader';
Expand All @@ -24,7 +24,7 @@ class MusicDetailHeader extends YTNode {
};
menu;

constructor(data: any) {
constructor(data: RawNode) {
super();
this.title = new Text(data.title);
this.description = new Text(data.description);
Expand All @@ -46,7 +46,7 @@ class MusicDetailHeader extends YTNode {
};
}

this.menu = Parser.parse(data.menu);
this.menu = Parser.parseItem(data.menu);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/parser/classes/MusicEditablePlaylistDetailHeader.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Parser from '../index.js';
import Parser, { RawNode } from '../index.js';
import { YTNode } from '../helpers.js';

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

header;

constructor(data: any) {
constructor(data: RawNode) {
super();
this.header = Parser.parse(data.header);
this.header = Parser.parseItem(data.header);

// TODO: Should we also parse data.editHeader.musicPlaylistEditHeaderRenderer?
// It doesn't seem practical to do so...
Expand Down
6 changes: 3 additions & 3 deletions src/parser/classes/MusicHeader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Parser from '../index.js';
import Parser, { RawNode } from '../index.js';
import { YTNode } from '../helpers.js';
import Text from './misc/Text.js';

Expand All @@ -8,11 +8,11 @@ class MusicHeader extends YTNode {
header?;
title?: Text;

constructor(data: any) {
constructor(data: RawNode) {
super();

if (data.header) {
this.header = Parser.parse(data.header);
this.header = Parser.parseItem(data.header);
}

if (data.title) {
Expand Down
Loading

0 comments on commit 3d34364

Please sign in to comment.