Files
YouTube.js/src/parser/classes/PlaylistVideo.ts
Daniel Wykerd b13bf6e992 refactor(Parser)!: general refactoring of parsers (#344)
* refactor: move common info into MediaInfo

* refactor: better inference on Memo

* refactor: improved typesafety in parser methods

* refactor: remove PlaylistAuthor in favor of Author

* refactor: cleanup live chat parsers

- Replace non standard author type with Author class
- Remove redundant code

* fix: new errors due to changes

* fix: pass actions to FormatUtils#toDash

* refactor!: merge NavigatableText and Text into single class
2023-03-15 18:25:12 -03:00

64 lines
1.8 KiB
TypeScript

import Text from './misc/Text.js';
import Parser from '../index.js';
import Thumbnail from './misc/Thumbnail.js';
import Author from './misc/Author.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import ThumbnailOverlayTimeStatus from './ThumbnailOverlayTimeStatus.js';
import Menu from './menus/Menu.js';
import { YTNode } from '../helpers.js';
class PlaylistVideo extends YTNode {
static type = 'PlaylistVideo';
id: string;
index: Text;
title: Text;
author: Author;
thumbnails: Thumbnail[];
thumbnail_overlays;
set_video_id: string | undefined;
endpoint: NavigationEndpoint;
is_playable: boolean;
menu: Menu | null;
upcoming;
duration: {
text: string;
seconds: number;
};
constructor(data: any) {
super();
this.id = data.videoId;
this.index = new Text(data.index);
this.title = new Text(data.title);
this.author = new Author(data.shortBylineText);
this.thumbnails = Thumbnail.fromResponse(data.thumbnail);
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, Menu);
const upcoming = data.upcomingEventData && Number(`${data.upcomingEventData.startTime}000`);
if (upcoming) {
this.upcoming = new Date(upcoming);
}
this.duration = {
text: new Text(data.lengthText).toString(),
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;