refactor: fix a few parsing inconsistencies

This commit is contained in:
LuanRT
2022-09-23 03:06:21 -03:00
parent 9e703abe3a
commit 7485726f1e
4 changed files with 15 additions and 14 deletions

View File

@@ -6,8 +6,8 @@ class Card extends YTNode {
teaser;
content;
card_id: string;
feature: string;
card_id: string | null;
feature: string | null;
cue_ranges: {
start_card_active_ms: string;
@@ -18,10 +18,10 @@ class Card extends YTNode {
constructor(data: any) {
super();
this.teaser = Parser.parse(data.teaser);
this.content = Parser.parse(data.content);
this.card_id = data.cardId;
this.feature = data.feature;
this.teaser = Parser.parseItem(data.teaser);
this.content = Parser.parseItem(data.content);
this.card_id = data.cardId || null;
this.feature = data.feature || null;
this.cue_ranges = data.cueRanges.map((cr: any) => ({
start_card_active_ms: cr.startCardActiveMs,
@@ -32,4 +32,4 @@ class Card extends YTNode {
}
}
export default Card;
export default Card;

View File

@@ -8,7 +8,7 @@ class ProfileColumnStats extends YTNode {
constructor(data: any) {
super();
this.items = Parser.parse(data.items);
this.items = Parser.parseArray(data.items);
}
// XXX: alias for consistency
@@ -17,4 +17,4 @@ class ProfileColumnStats extends YTNode {
}
}
export default ProfileColumnStats;
export default ProfileColumnStats;

View File

@@ -1,6 +1,7 @@
import Parser from '../index';
import Text from './misc/Text';
import Author from './misc/Author';
import Menu from './menus/Menu';
import Thumbnail from './misc/Thumbnail';
import NavigationEndpoint from './NavigationEndpoint';
import { timeToSeconds } from '../../utils/Utils';
@@ -53,8 +54,8 @@ class Video extends YTNode {
})) || [];
this.thumbnails = Thumbnail.fromResponse(data.thumbnail);
this.thumbnail_overlays = Parser.parse(data.thumbnailOverlays);
this.rich_thumbnail = data.richThumbnail && Parser.parse(data.richThumbnail);
this.thumbnail_overlays = Parser.parseArray(data.thumbnailOverlays);
this.rich_thumbnail = data.richThumbnail ? Parser.parse(data.richThumbnail) : null;
this.author = new Author(data.ownerText, data.ownerBadges, data.channelThumbnailSupportedRenderers?.channelThumbnailWithLinkRenderer?.thumbnail);
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);
this.published = new Text(data.publishedTimeText);
@@ -73,7 +74,7 @@ class Video extends YTNode {
this.show_action_menu = data.showActionMenu;
this.is_watched = data.isWatched || false;
this.menu = Parser.parse(data.menu);
this.menu = Parser.parseItem<Menu>(data.menu, Menu);
}
get description(): string {