mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-30 09:55:18 +00:00
feat(ytmusic): implement music#Library (#136)
* feat: add ItemSectionTab and related parsers * feat: add `continuation` to `Grid`parser class * feat (ytmusic): implement music#getLibrary() * Improve album fetch in `MusicResponsiveListItem` * music#Library: return [] for empty results * feat: add `Dropdown` & `DropdownItem` parsers * feat: add `CreatePlaylistDialog` parser * feat: add `create_playlist` to NavigationEndpoint * feat: add `AutomixPreviewVideo` parser * feat: improve parsing of items * fix: `PlaylistPanel` continuation * feat: more args in `Actions#next` * feat: add `PlaylistPanelContinuation` to `Parser` * chore: update parser-map * music#Library: refactor + add shuffle songs opt * feat: add `endpoint` to `DropdownItem` * feat: add `end_items` to `ItemSectionTabbedHeader` * feat(ytmusic): add `sort_by` to `music#Library`
This commit is contained in:
@@ -84,12 +84,17 @@ class MusicResponsiveListItem extends YTNode {
|
||||
this.#parsePlaylist();
|
||||
break;
|
||||
case 'MUSIC_PAGE_TYPE_ARTIST':
|
||||
case 'MUSIC_PAGE_TYPE_LIBRARY_ARTIST':
|
||||
case 'MUSIC_PAGE_TYPE_USER_CHANNEL':
|
||||
this.item_type = 'artist';
|
||||
this.#parseArtist();
|
||||
break;
|
||||
default:
|
||||
this.#parseVideoOrSong();
|
||||
if (this.#flex_columns[1]) {
|
||||
this.#parseVideoOrSong();
|
||||
} else {
|
||||
this.#parseOther();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -97,12 +102,22 @@ class MusicResponsiveListItem extends YTNode {
|
||||
this.index = new Text(data.index);
|
||||
}
|
||||
|
||||
this.thumbnails = data.thumbnail ? Thumbnail.fromResponse(data.thumbnail.musicThumbnailRenderer.thumbnail) : [];
|
||||
this.thumbnails = data.thumbnail ? Thumbnail.fromResponse(data.thumbnail.musicThumbnailRenderer?.thumbnail) : [];
|
||||
this.badges = Parser.parseArray(data.badges);
|
||||
this.menu = Parser.parse(data.menu);
|
||||
this.overlay = Parser.parse(data.overlay);
|
||||
}
|
||||
|
||||
#parseOther() {
|
||||
this.title = this.#flex_columns[0].key('title').instanceof(Text).toString();
|
||||
|
||||
if (this.endpoint) {
|
||||
this.item_type = 'endpoint';
|
||||
} else {
|
||||
this.item_type = 'unknown';
|
||||
}
|
||||
}
|
||||
|
||||
#parseVideoOrSong() {
|
||||
const is_video = this.#flex_columns[1].key('title').instanceof(Text).runs?.some((run) => run.text.match(/(.*?) views/));
|
||||
if (is_video) {
|
||||
@@ -127,7 +142,8 @@ class MusicResponsiveListItem extends YTNode {
|
||||
seconds: timeToSeconds(duration_text)
|
||||
});
|
||||
|
||||
const album = this.#flex_columns[1].key('title').instanceof(Text).runs?.find((run) => Reflect.get(run, 'endpoint')?.browse?.id.startsWith('MPR')) as TextRun;
|
||||
const album = this.#flex_columns[1].key('title').instanceof(Text).runs?.find((run) => Reflect.get(run, 'endpoint')?.browse?.id.startsWith('MPR')) as TextRun ||
|
||||
this.#flex_columns[2]?.key('title').instanceof(Text).runs?.find((run) => Reflect.get(run, 'endpoint')?.browse?.id.startsWith('MPR')) as TextRun;
|
||||
if (album) {
|
||||
this.album = {
|
||||
id: album.endpoint?.browse?.id,
|
||||
|
||||
Reference in New Issue
Block a user