mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-24 23:32:32 +00:00
feat: add parsers for TimeWatched
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
38
src/parser/classes/SettingBoolean.ts
Normal file
38
src/parser/classes/SettingBoolean.ts
Normal 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;
|
||||
18
src/parser/classes/SimpleTextSection.ts
Normal file
18
src/parser/classes/SimpleTextSection.ts
Normal 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;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
18
src/parser/classes/analytics/StatRow.ts
Normal file
18
src/parser/classes/analytics/StatRow.ts
Normal 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;
|
||||
18
src/parser/classes/misc/ChildElement.ts
Normal file
18
src/parser/classes/misc/ChildElement.ts
Normal 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;
|
||||
Reference in New Issue
Block a user