diff --git a/mixins/browsing.ts b/mixins/browsing.ts index 5d49b09..2e71c10 100644 --- a/mixins/browsing.ts +++ b/mixins/browsing.ts @@ -34,8 +34,10 @@ import { parse_mixed_content, parse_moods, parse_playlist, + parse_user_contents, ParsedAlbum, ParsedPlaylist, + UserContents, } from "../parsers/browsing.ts"; import { parse_playlist_items, @@ -466,8 +468,11 @@ export async function get_artist_albums( return results.map((result: any) => parse_album(result[MTRIR])); } -export interface User extends ArtistContents { +export interface User extends UserContents { name: string; + songs_on_repeat: { + results: PlaylistItem[]; + } | null; } export async function get_user( @@ -483,9 +488,18 @@ export async function get_user( const user: User = { name: j(json, "header.musicVisualHeaderRenderer", TITLE_TEXT), - ...parse_artist_contents(results), + ...parse_user_contents(results), + songs_on_repeat: null, }; + if ("musicShelfRenderer" in results[0]) { + const musicShelf = j(results[0], `${MUSIC_SHELF}`); + + user.songs_on_repeat = { + results: parse_playlist_items(musicShelf.contents), + }; + } + return user; } diff --git a/parsers/browsing.ts b/parsers/browsing.ts index e58d7a4..5cb7a8b 100644 --- a/parsers/browsing.ts +++ b/parsers/browsing.ts @@ -275,6 +275,22 @@ export function parse_categories< return categories; } +export function parse_user_contents(results: any[]) { + const categories_data = { + artists_on_repeat: [_("artists_on_repeat"), parse_related_artist], + playlists_on_repeat: [_("playlists_on_repeat"), parse_playlist], + playlists: [_("playlists"), parse_playlist], + } satisfies CategoryMap; + + return parse_categories(results, categories_data); +} + +export type NonNUllableUserContents = ReturnType; + +export type UserContents = { + [Key in keyof NonNUllableUserContents]: NonNUllableUserContents[Key] | null; +}; + export function parse_artist_contents(results: any[]) { const categories_data = { albums: [_("albums"), parse_album],