mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-30 09:55:18 +00:00
feat: Add upcoming and live info to playlist videos (#317)
This commit is contained in:
@@ -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<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;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user