feat: fix music#library.getArtists() and add MusicShelf.bottom_button (#152)

* fix: #143

* feat: add `bottom_button` to `MusicShelf`
This commit is contained in:
Patrick Kan
2022-08-26 04:14:32 +08:00
committed by GitHub
parent 6fe4d235ff
commit 05b4593e0a
3 changed files with 14 additions and 3 deletions

View File

@@ -86,11 +86,14 @@ 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;
case 'MUSIC_PAGE_TYPE_LIBRARY_ARTIST':
this.item_type = 'library_artist';
this.#parseLibraryArtist();
break;
default:
if (this.#flex_columns[1]) {
this.#parseVideoOrSong();
@@ -191,7 +194,12 @@ class MusicResponsiveListItem extends YTNode {
this.name = this.#flex_columns[0].key('title').instanceof(Text).toString();
this.subtitle = this.#flex_columns[1].key('title').instanceof(Text);
this.subscribers = this.subtitle.runs?.find((run) => (/^(\d*\.)?\d+[M|K]? subscribers?$/i).test(run.text))?.text || '';
this.song_count = this.subtitle.runs?.find((run) => (/^\d+(,\d+)? songs?$/i).test(run.text))?.text || '';
}
#parseLibraryArtist() {
this.name = this.#flex_columns[0].key('title').instanceof(Text).toString();
this.subtitle = this.#flex_columns[1].key('title').instanceof(Text);
this.song_count = this.subtitle?.runs?.find((run) => (/^\d+(,\d+)? songs?$/i).test(run.text))?.text || '';
}
#parseAlbum() {

View File

@@ -4,6 +4,7 @@ import NavigationEndpoint from './NavigationEndpoint';
import MusicResponsiveListItem from './MusicResponsiveListItem';
import { YTNode } from '../helpers';
import Button from './Button';
class MusicShelf extends YTNode {
static type = 'MusicShelf';
@@ -13,6 +14,7 @@ class MusicShelf extends YTNode {
endpoint: NavigationEndpoint | null;
continuation: string | null;
bottom_text: Text | null;
bottom_button?: Button | null;
subheaders?: Array<any>;
constructor(data: any) {
@@ -25,6 +27,7 @@ class MusicShelf extends YTNode {
data.continuations?.[0].nextContinuationData?.continuation ||
data.continuations?.[0].reloadContinuationData?.continuation || null;
this.bottom_text = Reflect.has(data, 'bottomText') ? new Text(data.bottomText) : null;
this.bottom_button = Parser.parseItem(data.bottomButton, Button);
if (data.subheaders) {
this.subheaders = Parser.parseArray(data.subheaders);
}

View File

@@ -103,7 +103,7 @@ class Library {
* Retrieves the library's artists
*/
async getArtists(args?: { sort_by?: SortBy }) {
const data = await this.#fetchAndParseTabContents(this.#getBrowseId('artists'), (item) => item.item_type === 'artist');
const data = await this.#fetchAndParseTabContents(this.#getBrowseId('artists'), (item) => item.item_type === 'library_artist');
const sort_by = args?.sort_by || null;
return sort_by ? this.#applySortBy(data, sort_by) : data;
}