diff --git a/src/parser/classes/PlaylistVideo.ts b/src/parser/classes/PlaylistVideo.ts index ab67fee60..83573d79f 100644 --- a/src/parser/classes/PlaylistVideo.ts +++ b/src/parser/classes/PlaylistVideo.ts @@ -3,6 +3,7 @@ import Parser from '../index.js'; import Thumbnail from './misc/Thumbnail.js'; import PlaylistAuthor from './misc/PlaylistAuthor.js'; import NavigationEndpoint from './NavigationEndpoint.js'; +import ThumbnailOverlayTimeStatus from './ThumbnailOverlayTimeStatus.js'; import type Menu from './menus/Menu.js'; import { YTNode } from '../helpers.js'; @@ -20,6 +21,7 @@ class PlaylistVideo extends YTNode { endpoint: NavigationEndpoint; is_playable: boolean; menu: Menu | null; + upcoming; duration: { text: string; @@ -33,16 +35,30 @@ class PlaylistVideo extends YTNode { this.title = new Text(data.title); this.author = new PlaylistAuthor(data.shortBylineText); this.thumbnails = Thumbnail.fromResponse(data.thumbnail); - this.thumbnail_overlays = Parser.parse(data.thumbnailOverlays); + this.thumbnail_overlays = Parser.parseArray(data.thumbnailOverlays); this.set_video_id = data?.setVideoId; this.endpoint = new NavigationEndpoint(data.navigationEndpoint); this.is_playable = data.isPlayable; this.menu = Parser.parseItem(data.menu); + + const upcoming = data.upcomingEventData && Number(`${data.upcomingEventData.startTime}000`); + if (upcoming) { + this.upcoming = new Date(upcoming); + } + this.duration = { text: new Text(data.lengthText).text, seconds: parseInt(data.lengthSeconds) }; } + + get is_live(): boolean { + return this.thumbnail_overlays.firstOfType(ThumbnailOverlayTimeStatus)?.style === 'LIVE'; + } + + get is_upcoming(): boolean { + return this.thumbnail_overlays.firstOfType(ThumbnailOverlayTimeStatus)?.style === 'UPCOMING'; + } } export default PlaylistVideo; \ No newline at end of file diff --git a/src/parser/classes/ThumbnailOverlayTimeStatus.ts b/src/parser/classes/ThumbnailOverlayTimeStatus.ts index e3835f1f1..aa05a9366 100644 --- a/src/parser/classes/ThumbnailOverlayTimeStatus.ts +++ b/src/parser/classes/ThumbnailOverlayTimeStatus.ts @@ -5,10 +5,12 @@ class ThumbnailOverlayTimeStatus extends YTNode { static type = 'ThumbnailOverlayTimeStatus'; text: string; + style: string; constructor(data: any) { super(); this.text = new Text(data.text).toString(); + this.style = data.style; } }