mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-17 03:22:15 +00:00
82 lines
2.6 KiB
JavaScript
82 lines
2.6 KiB
JavaScript
'use strict';
|
|
|
|
const Parser = require('..');
|
|
const Text = require('./Text');
|
|
const Thumbnail = require('./Thumbnail');
|
|
const NavigationEndpoint = require('./NavigationEndpoint');
|
|
|
|
class MusicTwoRowItem {
|
|
type = 'MusicTwoRowItem';
|
|
|
|
constructor(data) {
|
|
this.title = new Text(data.title);
|
|
|
|
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);
|
|
|
|
this.id = this.endpoint.browse?.id ||
|
|
this.endpoint.watch.video_id;
|
|
|
|
this.subtitle = new Text(data.subtitle);
|
|
this.badges = Parser.parse(data.subtitleBadges);
|
|
|
|
switch (this.endpoint.browse?.page_type) {
|
|
case 'MUSIC_PAGE_TYPE_ARTIST':
|
|
this.type = 'artist';
|
|
this.subscribers = this.subtitle.toString();
|
|
break;
|
|
case 'MUSIC_PAGE_TYPE_PLAYLIST':
|
|
this.type = 'playlist';
|
|
this.item_count = parseInt(this.subtitle.runs
|
|
.find((run) => run.text
|
|
.match(/\d+ (songs|song)/))?.text
|
|
.match(/\d+/g)) || null;
|
|
break;
|
|
case 'MUSIC_PAGE_TYPE_ALBUM':
|
|
this.type = 'album';
|
|
|
|
const artists = this.subtitle.runs.filter((run) => run.endpoint.browse?.id.startsWith('UC'));
|
|
|
|
artists && (this.artists = artists.map((artist) => ({
|
|
name: artist.text,
|
|
channel_id: artist.endpoint.browse.id,
|
|
endpoint: artist.endpoint
|
|
})))
|
|
|
|
this.year = this.subtitle.runs.slice(-1)[0].text;
|
|
isNaN(this.year) && (delete this.year);
|
|
break;
|
|
default:
|
|
this.subtitle.runs[0].text !== 'Song' &&
|
|
(this.type = 'video') ||
|
|
(this.type = 'song');
|
|
|
|
if (this.type == 'video') {
|
|
this.views = this.subtitle.runs
|
|
.find((run) => run.text.match(/(.*?) views/)).text;
|
|
|
|
const author = this.subtitle.runs.find((run) => run.endpoint.browse?.id.startsWith('UC'));
|
|
|
|
author && (this.author = {
|
|
name: author.text,
|
|
channel_id: author.endpoint.browse.id,
|
|
endpoint: author.endpoint
|
|
});
|
|
} else {
|
|
const artists = this.subtitle.runs.filter((run) => run.endpoint.browse?.id.startsWith('UC'));
|
|
|
|
artists && (this.artists = artists.map((artist) => ({
|
|
name: artist.text,
|
|
channel_id: artist.endpoint.browse.id,
|
|
endpoint: artist.endpoint
|
|
})));
|
|
}
|
|
break;
|
|
}
|
|
|
|
this.thumbnail = Thumbnail.fromResponse(data.thumbnailRenderer.musicThumbnailRenderer.thumbnail);
|
|
this.thumbnail_overlay = Parser.parse(data.thumbnailOverlay);
|
|
this.menu = Parser.parse(data.menu);
|
|
}
|
|
}
|
|
|
|
module.exports = MusicTwoRowItem; |