Files
YouTube.js/lib/parser/contents/classes/PlaylistPanelVideo.js
LuanRT 1d62e469a9 refactor: rewrite Comments Section logic (#88)
* feat: add core comments section classes

* chore: update type declarations

* chore: fix linter warnings

* style: fix linter

* chore: update tests

* chore(tests): fix typo

* chore(tests): fix typo x2

* fix(tests): `getReplies()` method is only present in `CommentThread` and not `Comment`

* chore(tests): fix comment id path

* chore(tests): remove outdated code

* chore(tests): fix results path

* chore: enforce code style

* chore: update type declarations

* docs: add examples and documentation

* chore(docs): fix paths

* chore(docs): fix more paths

* chore(docs): fix `Comments.js` path

* chore(docs): fix typo

* chore(docs): mention example file

* chore(examples): fix imports

* chore(examples): fix typo
2022-07-02 19:55:33 -03:00

48 lines
1.5 KiB
JavaScript

'use strict';
const Parser = require('..');
const Text = require('./Text');
const Thumbnail = require('./Thumbnail');
const NavigationEndpoint = require('./NavigationEndpoint');
const Utils = require('../../../utils/Utils');
class PlaylistPanelVideo {
type = 'PlaylistPanelVideo';
constructor(data) {
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: Utils.timeToSeconds(new Text(data.lengthText).toString())
};
const album = new Text(data.longBylineText).runs.find((run) => run.endpoint.browse?.id.startsWith('MPR'));
const artists = new Text(data.longBylineText).runs.filter((run) => run.endpoint.browse?.id.startsWith('UC'));
this.author = new Text(data.shortBylineText).toString();
album && (this.album = {
id: album.endpoint.browse.id,
name: album.text,
year: new Text(data.longBylineText).runs.slice(-1)[0].text,
endpoint: album.endpoint
});
this.artists = artists.map((artist) => ({
name: artist.text,
channel_id: artist.endpoint.browse.id,
endpoint: artist.endpoint
}));
this.badges = Parser.parse(data.badges);
this.menu = Parser.parse(data.menu);
this.set_video_id = data.playlistSetVideoId;
}
}
module.exports = PlaylistPanelVideo;