feat(ytmusic): music#Playlist fixes and additions (#138)

* feat: add MusicEditablePlaylistDetailHeader parser

* feat: more info in `DropdownItem`

* fix: empty `year` value in `MusicDetailHeader`

* fix(ytmusic#Playlist): header err w/ own playlists

* feat: include reload continuation in `MusicShelf`

* feat(ytmusic): add getSuggestions() to Playlist
This commit is contained in:
Patrick Kan
2022-08-15 07:39:31 +08:00
committed by GitHub
parent 713fd13c74
commit dba34dc5ae
7 changed files with 80 additions and 9 deletions

View File

@@ -7,8 +7,9 @@ class DropdownItem extends YTNode {
label: string;
selected: boolean;
value?: number;
value?: number | string;
iconType?: string;
description?: string;
endpoint?: NavigationEndpoint;
constructor(data: any) {
@@ -19,6 +20,8 @@ class DropdownItem extends YTNode {
if (data.int32Value) {
this.value = data.int32Value;
} else if (data.stringValue) {
this.value = data.stringValue;
}
if (data.onSelectCommand?.browseEndpoint) {
@@ -28,6 +31,10 @@ class DropdownItem extends YTNode {
if (data.icon?.iconType) {
this.iconType = data.icon?.iconType;
}
if (data.descriptionText) {
this.description = new Text(data.descriptionText).toString();
}
}
}

View File

@@ -12,7 +12,7 @@ class MusicDetailHeader extends YTNode {
this.description = new Text(data.description);
this.subtitle = new Text(data.subtitle);
this.second_subtitle = new Text(data.secondSubtitle);
this.year = this.subtitle.runs.find((run) => (/^[12][0-9]{3}$/).test(run.text)).text;
this.year = this.subtitle.runs.find((run) => (/^[12][0-9]{3}$/).test(run.text))?.text || null;
this.song_count = this.second_subtitle.runs[0].text;
this.total_duration = this.second_subtitle.runs[2].text;
this.thumbnails = Thumbnail.fromResponse(data.thumbnail.croppedSquareThumbnailRenderer.thumbnail);

View File

@@ -0,0 +1,18 @@
import Parser from '../index';
import { YTNode } from '../helpers';
class MusicEditablePlaylistDetailHeader extends YTNode {
static type = 'MusicEditablePlaylistDetailHeader';
header;
constructor(data: any) {
super();
this.header = Parser.parse(data.header);
// TODO: Should we also parse data.editHeader.musicPlaylistEditHeaderRenderer?
// It doesn't seem practical to do so...
}
}
export default MusicEditablePlaylistDetailHeader;

View File

@@ -20,7 +20,9 @@ class MusicShelf extends YTNode {
this.title = new Text(data.title);
this.contents = Parser.parseArray<MusicResponsiveListItem>(data.contents, MusicResponsiveListItem);
this.endpoint = Reflect.has(data, 'bottomEndpoint') ? new NavigationEndpoint(data.bottomEndpoint) : null;
this.continuation = data.continuations?.[0]?.nextContinuationData?.continuation || null;
this.continuation =
data.continuations?.[0].nextContinuationData?.continuation ||
data.continuations?.[0].reloadContinuationData?.continuation || null;
this.bottom_text = Reflect.has(data, 'bottomText') ? new Text(data.bottomText) : null;
}
}