Skip to content

Commit

Permalink
feat: show "on repeat" data for users
Browse files Browse the repository at this point in the history
  • Loading branch information
vixalien committed May 4, 2023
1 parent 5a2a9f3 commit 435594a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
18 changes: 16 additions & 2 deletions mixins/browsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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;
}

Expand Down
16 changes: 16 additions & 0 deletions parsers/browsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof parse_user_contents>;

export type UserContents = {
[Key in keyof NonNUllableUserContents]: NonNUllableUserContents[Key] | null;
};

export function parse_artist_contents(results: any[]) {
const categories_data = {
albums: [_("albums"), parse_album],
Expand Down

0 comments on commit 435594a

Please sign in to comment.