Skip to content

Commit 435594a

Browse files
committed
feat: show "on repeat" data for users
1 parent 5a2a9f3 commit 435594a

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

mixins/browsing.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ import {
3434
parse_mixed_content,
3535
parse_moods,
3636
parse_playlist,
37+
parse_user_contents,
3738
ParsedAlbum,
3839
ParsedPlaylist,
40+
UserContents,
3941
} from "../parsers/browsing.ts";
4042
import {
4143
parse_playlist_items,
@@ -466,8 +468,11 @@ export async function get_artist_albums(
466468
return results.map((result: any) => parse_album(result[MTRIR]));
467469
}
468470

469-
export interface User extends ArtistContents {
471+
export interface User extends UserContents {
470472
name: string;
473+
songs_on_repeat: {
474+
results: PlaylistItem[];
475+
} | null;
471476
}
472477

473478
export async function get_user(
@@ -483,9 +488,18 @@ export async function get_user(
483488

484489
const user: User = {
485490
name: j(json, "header.musicVisualHeaderRenderer", TITLE_TEXT),
486-
...parse_artist_contents(results),
491+
...parse_user_contents(results),
492+
songs_on_repeat: null,
487493
};
488494

495+
if ("musicShelfRenderer" in results[0]) {
496+
const musicShelf = j(results[0], `${MUSIC_SHELF}`);
497+
498+
user.songs_on_repeat = {
499+
results: parse_playlist_items(musicShelf.contents),
500+
};
501+
}
502+
489503
return user;
490504
}
491505

parsers/browsing.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,22 @@ export function parse_categories<
275275
return categories;
276276
}
277277

278+
export function parse_user_contents(results: any[]) {
279+
const categories_data = {
280+
artists_on_repeat: [_("artists_on_repeat"), parse_related_artist],
281+
playlists_on_repeat: [_("playlists_on_repeat"), parse_playlist],
282+
playlists: [_("playlists"), parse_playlist],
283+
} satisfies CategoryMap;
284+
285+
return parse_categories(results, categories_data);
286+
}
287+
288+
export type NonNUllableUserContents = ReturnType<typeof parse_user_contents>;
289+
290+
export type UserContents = {
291+
[Key in keyof NonNUllableUserContents]: NonNUllableUserContents[Key] | null;
292+
};
293+
278294
export function parse_artist_contents(results: any[]) {
279295
const categories_data = {
280296
albums: [_("albums"), parse_album],

0 commit comments

Comments
 (0)