Skip to content

Commit

Permalink
feat: parse isLive in CompactVideo (#294)
Browse files Browse the repository at this point in the history
* Feat: parse isLive in CompactVideo

* Use 3 equal signs

Co-authored-by: absidue <[email protected]>

* use parse array for badges

add is_premiere, is_new, is_fundraiser

---------

Co-authored-by: absidue <[email protected]>
  • Loading branch information
ChunkyProgrammer and absidue authored Jan 27, 2023
1 parent 0b99180 commit 2acb7da
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/parser/classes/CompactVideo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { timeToSeconds } from '../../utils/Utils';
import Thumbnail from './misc/Thumbnail';
import NavigationEndpoint from './NavigationEndpoint';
import type Menu from './menus/Menu';
import MetadataBadge from './MetadataBadge';

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

Expand All @@ -19,6 +20,7 @@ class CompactVideo extends YTNode {
view_count: Text;
short_view_count: Text;
published: Text;
badges: MetadataBadge[];

duration: {
text: string;
Expand All @@ -39,6 +41,7 @@ class CompactVideo extends YTNode {
this.view_count = new Text(data.viewCountText);
this.short_view_count = new Text(data.shortViewCountText);
this.published = new Text(data.publishedTimeText);
this.badges = Parser.parseArray(data.badges, MetadataBadge);

this.duration = {
text: new Text(data.lengthText).toString(),
Expand All @@ -53,6 +56,25 @@ class CompactVideo extends YTNode {
get best_thumbnail() {
return this.thumbnails[0];
}

get is_fundraiser(): boolean {
return this.badges.some((badge) => badge.style === 'Fundraiser');
}

get is_live(): boolean {
return this.badges.some((badge) => {
if (badge.label === 'BADGE_STYLE_TYPE_LIVE_NOW' || badge.style === 'LIVE')
return true;
});
}

get is_new(): boolean {
return this.badges.some((badge) => badge.style === 'New');
}

get is_premiere(): boolean {
return this.badges.some((badge) => badge.style === 'PREMIERE');
}
}

export default CompactVideo;

0 comments on commit 2acb7da

Please sign in to comment.