Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add upcoming and live info to playlist videos #317

Merged
merged 1 commit into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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