mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-19 12:31:17 +00:00
feat: parse isLive in CompactVideo (#294)
* Feat: parse isLive in CompactVideo * Use 3 equal signs Co-authored-by: absidue <48293849+absidue@users.noreply.github.com> * use parse array for badges add is_premiere, is_new, is_fundraiser --------- Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -19,6 +20,7 @@ class CompactVideo extends YTNode {
|
||||
view_count: Text;
|
||||
short_view_count: Text;
|
||||
published: Text;
|
||||
badges: MetadataBadge[];
|
||||
|
||||
duration: {
|
||||
text: string;
|
||||
@@ -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(),
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user