Files
YouTube.js/src/parser/classes/PlaylistPanelVideo.ts
Daniel Wykerd 2ccbe2ce62 refactor!: cleanup platform support (#306)
* refactor!: cleanup platform support

* chore: lint

* fix: web platform

* feat: provide UniversalCache

Provide UniversalCache as a wrapper around Platform.shim.Cache.

* fix: invalid import

* refactor: remove isolated-vm support

* fix: type info

* refactor: cleanup exports

* fix: mark jintr as external dependency

In the bundled CJS node build, mark jintr as external.

* chore: add additional exports

web exports provide a way to select web implementation manually without
relying on the bundler to select it correctly from the "exports" field

web points to src/platform/web.js
web.bundle points to bundle/browser.js
web.bundle.browser points to bundle/browser.min.js

agnostic exports provide users of the library to provide their own
platform implementation without first importing the default one.

agnostic points to src/platform/lib.ts

* fix: toDash on web

* revert: eval is synchronous

* fix: use serializeDOM in FormatUtils

* ci: automate releases with `release-please`

* chore: clean up workflow files

* ci: fix NPM publish action

---------

Co-authored-by: LuanRT <luan.lrt4@gmail.com>
2023-02-12 04:21:44 -03:00

85 lines
2.3 KiB
TypeScript

import Parser from '../index.js';
import Text from './misc/Text.js';
import TextRun from './misc/TextRun.js';
import Thumbnail from './misc/Thumbnail.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import { timeToSeconds } from '../../utils/Utils.js';
import { YTNode } from '../helpers.js';
class PlaylistPanelVideo extends YTNode {
static type = 'PlaylistPanelVideo';
title: Text;
thumbnail: Thumbnail[];
endpoint: NavigationEndpoint;
selected: boolean;
video_id: string;
duration: {
text: string;
seconds: number
};
author: string;
album?: {
id: string | undefined;
name: string;
year: string | undefined;
endpoint: NavigationEndpoint | undefined;
};
artists?: {
name: string;
channel_id: string | undefined;
endpoint: NavigationEndpoint | undefined;
}[];
badges;
menu;
set_video_id: string | undefined;
constructor(data: any) {
super();
this.title = new Text(data.title);
this.thumbnail = Thumbnail.fromResponse(data.thumbnail);
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);
this.selected = data.selected;
this.video_id = data.videoId;
this.duration = {
text: new Text(data.lengthText).toString(),
seconds: timeToSeconds(new Text(data.lengthText).toString())
};
const album = new Text(data.longBylineText).runs?.find((run: any) => run.endpoint?.payload?.browseId?.startsWith('MPR'));
const artists = new Text(data.longBylineText).runs?.filter((run: any) => run.endpoint?.payload?.browseId?.startsWith('UC'));
this.author = new Text(data.shortBylineText).toString();
if (album) {
this.album = {
id: (album as TextRun).endpoint?.payload?.browseId,
name: (album as TextRun).text,
year: new Text(data.longBylineText).runs?.slice(-1)[0].text,
endpoint: (album as TextRun).endpoint
};
}
if (artists) {
this.artists = artists.map((artist) => ({
name: (artist as TextRun).text,
channel_id: (artist as TextRun).endpoint?.payload?.browseId,
endpoint: (artist as TextRun).endpoint
}));
}
this.badges = Parser.parseArray(data.badges);
this.menu = Parser.parseItem(data.menu);
this.set_video_id = data.playlistSetVideoId;
}
}
export default PlaylistPanelVideo;