Skip to content

Commit

Permalink
feat: Add upcoming and live info to playlist videos (#317)
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue authored Feb 20, 2023
1 parent 9d352b5 commit a0bfe16
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/parser/classes/PlaylistVideo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -20,6 +21,7 @@ class PlaylistVideo extends YTNode {
endpoint: NavigationEndpoint;
is_playable: boolean;
menu: Menu | null;
upcoming;

duration: {
text: string;
Expand All @@ -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<Menu>(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;
2 changes: 2 additions & 0 deletions src/parser/classes/ThumbnailOverlayTimeStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down

0 comments on commit a0bfe16

Please sign in to comment.