Browse Source

Add top songs endpoint for subsonic

- Enforce unique entries only for top/similar songs
master
jeffvli 3 years ago
committed by Jeff
parent
commit
c88846f59e
  1. 11
      src/api/api.ts
  2. 2
      src/api/controller.ts
  3. 3
      src/types.ts

11
src/api/api.ts

@ -550,7 +550,16 @@ export const setRating = async (options: { ids: string[]; rating: number }) => {
export const getSimilarSongs = async (options: { id: string; count: number }) => {
const { data } = await api.get(`/getSimilarSongs2`, { params: options });
return (data.similarSongs2.song || []).map((entry: any) => normalizeSong(entry));
return (_.uniqBy(data.similarSongs2.song, (e: any) => e.id) || []).map((entry: any) =>
normalizeSong(entry)
);
};
export const getTopSongs = async (options: { artist: string; count: number }) => {
const { data } = await api.get(`/getTopSongs`, { params: options });
return (_.uniqBy(data?.topSongs?.song, (e: any) => e.id) || []).map((entry: any) =>
normalizeSong(entry)
);
};
export const updatePlaylistSongs = async (options: { id: string; entry: any[] }) => {

2
src/api/controller.ts

@ -22,6 +22,7 @@ import {
getScanStatus,
getSearch,
getSimilarSongs,
getTopSongs,
getStarred,
scrobble,
setRating,
@ -93,6 +94,7 @@ const endpoints = [
{ id: 'getMusicDirectorySongs', endpoint: { subsonic: getMusicDirectorySongs, jellyfin: jfGetMusicDirectorySongs } },
{ id: 'getDownloadUrl', endpoint: { subsonic: getDownloadUrl, jellyfin: jfGetDownloadUrl } },
{ id: 'getSongs', endpoint: { subsonic: undefined, jellyfin: jfGetSongs } },
{ id: 'getTopSongs', endpoint: { subsonic: getTopSongs, jellyfin: undefined } },
// Playlist handling logic is split up by server type due to differences in how each server handles them.
// You will need to add custom logic in the playlist/context menu component handlers.

3
src/types.ts

@ -51,7 +51,8 @@ export type APIEndpoints =
| 'getMusicDirectory'
| 'getMusicDirectorySongs'
| 'getDownloadUrl'
| 'getSongs';
| 'getSongs'
| 'getTopSongs';
export interface GenericItem {
id: string;

Loading…
Cancel
Save