Skip to content

Commit

Permalink
feat(parser): Add VideoViewCount node
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanRT committed Nov 15, 2024
1 parent 80dbd6f commit ad448f8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/parser/classes/VideoPrimaryInfo.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
import type { ObservedArray } from '../helpers.js';
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
import { Parser } from '../index.js';
import MetadataBadge from './MetadataBadge.js';
import Menu from './menus/Menu.js';
import { Parser, type RawNode } from '../index.js';
import { YTNode, type ObservedArray } from '../helpers.js';

import Text from './misc/Text.js';
import Menu from './menus/Menu.js';
import MetadataBadge from './MetadataBadge.js';
import VideoViewCount from './VideoViewCount.js';

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

title: Text;
super_title_link?: Text;
view_count: Text;
short_view_count: Text;
badges: ObservedArray<MetadataBadge>;
published: Text;
relative_date: Text;
menu: Menu | null;
public title: Text;
public super_title_link?: Text;
public view_count: VideoViewCount | null;
public badges: ObservedArray<MetadataBadge>;
public published: Text;
public relative_date: Text;
public menu: Menu | null;

constructor(data: RawNode) {
super();
this.title = new Text(data.title);

if (Reflect.has(data, 'superTitleLink')) {
if (Reflect.has(data, 'superTitleLink'))
this.super_title_link = new Text(data.superTitleLink);
}

this.view_count = new Text(data.viewCount?.videoViewCountRenderer?.viewCount);
this.short_view_count = new Text(data.viewCount?.videoViewCountRenderer?.shortViewCount);
this.view_count = Parser.parseItem(data.viewCount, VideoViewCount);
this.badges = Parser.parseArray(data.badges, MetadataBadge);
this.published = new Text(data.dateText);
this.relative_date = new Text(data.relativeDateText);
Expand Down
18 changes: 18 additions & 0 deletions src/parser/classes/VideoViewCount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Text } from '../misc.js';
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';

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

public original_view_count: string;
public short_view_count: Text;
public view_count: Text;

constructor(data: RawNode) {
super();
this.original_view_count = data.originalViewCount;
this.short_view_count = new Text(data.shortViewCount);
this.view_count = new Text(data.viewCount);
}
}
1 change: 1 addition & 0 deletions src/parser/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ export { default as VideoInfoCardContent } from './classes/VideoInfoCardContent.
export { default as VideoOwner } from './classes/VideoOwner.js';
export { default as VideoPrimaryInfo } from './classes/VideoPrimaryInfo.js';
export { default as VideoSecondaryInfo } from './classes/VideoSecondaryInfo.js';
export { default as VideoViewCount } from './classes/VideoViewCount.js';
export { default as ViewCountFactoid } from './classes/ViewCountFactoid.js';
export { default as WatchCardCompactVideo } from './classes/WatchCardCompactVideo.js';
export { default as WatchCardHeroVideo } from './classes/WatchCardHeroVideo.js';
Expand Down

0 comments on commit ad448f8

Please sign in to comment.