feat: add parsers for TimeWatched

This commit is contained in:
LuanRT
2022-08-24 06:13:19 -03:00
parent c000bd8d5f
commit 541cdc455f
11 changed files with 159 additions and 32 deletions

View File

@@ -1,15 +1,22 @@
import Parser from '../index';
import ChildElement from './misc/ChildElement';
import { YTNode } from '../helpers';
class Element extends YTNode {
static type = 'Element';
model;
child_elements?: ChildElement[];
constructor(data: any) {
super();
const type = data.newElement.type.componentType;
this.model = Parser.parse(type.model);
this.model = Parser.parse(type?.model);
if (data.newElement?.childElements) {
this.child_elements = data.newElement?.childElements?.map((el: any) => new ChildElement(el)) || null;
}
}
}

View File

@@ -0,0 +1,38 @@
import Text from './misc/Text';
import NavigationEndpoint from './NavigationEndpoint';
import { YTNode } from '../helpers';
class SettingBoolean extends YTNode {
static type = 'SettingBoolean';
title?: Text;
summary?: Text;
enable_endpoint?: NavigationEndpoint;
disable_endpoint?: NavigationEndpoint;
item_id: string;
constructor(data: any) {
super();
if (data.title) {
this.title = new Text(data.title);
}
if (data.summary) {
this.summary = new Text(data.summary);
}
if (data.enableServiceEndpoint) {
this.enable_endpoint = new NavigationEndpoint(data.enableServiceEndpoint);
}
if (data.disableServiceEndpoint) {
this.disable_endpoint = new NavigationEndpoint(data.disableServiceEndpoint);
}
this.item_id = data.itemId;
}
}
export default SettingBoolean;

View File

@@ -0,0 +1,18 @@
import Text from './misc/Text';
import { YTNode } from '../helpers';
class SimpleTextSection extends YTNode {
static type = 'SimpleTextSection';
lines: Text[];
style: string;
constructor(data: any) {
super();
this.lines = data.lines.map((line: any) => new Text(line));
this.style = data.layoutStyle;
}
}
export default SimpleTextSection;

View File

@@ -5,12 +5,18 @@ class AnalyticsVodCarouselCard extends YTNode {
static type = 'AnalyticsVodCarouselCard';
title: string;
videos: Video[];
videos: Video[] | null;
no_data_message?: string;
constructor(data: any) {
super();
this.title = data.title;
this.videos = data.videoCarouselData.videos.map((video: any) => new Video(video));
if (data.noDataMessage) {
this.no_data_message = data.noDataMessage;
}
this.videos = data.videoCarouselData?.videos.map((video: any) => new Video(video)) || null;
}
}

View File

@@ -0,0 +1,18 @@
import Text from '../misc/Text';
import { YTNode } from '../../helpers';
class StatRow extends YTNode {
static type = 'StatRow';
title: Text;
contents: Text;
constructor(data: any) {
super();
this.title = new Text(data.title);
this.contents = new Text(data.contents);
}
}
export default StatRow;

View File

@@ -0,0 +1,18 @@
class ChildElement {
static type = 'ChildElement';
text: string | null;
properties;
child_elements?: ChildElement[];
constructor(data: any) {
this.text = data.type.textType?.text?.content || null;
this.properties = data.properties;
if (data.childElements) {
this.child_elements = data.childElements.map((el: any) => new ChildElement(el));
}
}
}
export default ChildElement;