From a3c22ee805ea8d0060fc4e66983082ee878bf1db Mon Sep 17 00:00:00 2001 From: jeffvli Date: Wed, 19 Jan 2022 05:30:48 -0800 Subject: [PATCH] Add getSongsByGenre endpoint --- src/api/api.ts | 18 +++++++++++++++--- src/api/controller.ts | 2 ++ src/types.ts | 3 ++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/api/api.ts b/src/api/api.ts index 07ae2e8..078bf31 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -199,7 +199,7 @@ const normalizeSong = (item: any) => { discNumber: item.discNumber, created: item.created, streamUrl: getStreamUrl(item.id, legacyAuth), - image: getCoverArtUrl(item, legacyAuth, 150), + image: getCoverArtUrl(item, legacyAuth, 350), starred: item.starred, userRating: item.userRating, type: Item.Music, @@ -288,7 +288,7 @@ const normalizeFolder = (item: any) => { title: item.name || item.title, created: item.DateCreated, isDir: true, - image: getCoverArtUrl(item, legacyAuth, 150), + image: getCoverArtUrl(item, legacyAuth, 350), type: Item.Folder, uniqueId: nanoid(), }; @@ -565,7 +565,7 @@ 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 (_.uniqBy(data.similarSongs2.song, (e: any) => e.id) || []).map((entry: any) => + return (_.uniqBy(data?.similarSongs2?.song, (e: any) => e.id) || []).map((entry: any) => normalizeSong(entry) ); }; @@ -577,6 +577,18 @@ export const getTopSongs = async (options: { artist: string; count: number }) => ); }; +export const getSongsByGenre = async (options: { + genre: string; + count: number; + offset: number; + musicFolderId?: string | number; +}) => { + const { data } = await api.get(`/getSongsByGenre`, { params: options }); + return (_.uniqBy(data?.songsByGenre?.song, (e: any) => e.id) || []).map((entry: any) => + normalizeSong(entry) + ); +}; + export const updatePlaylistSongs = async (options: { id: string; entry: any[] }) => { const playlistParams = new URLSearchParams(); const songIds = _.map(options.entry, 'id'); diff --git a/src/api/controller.ts b/src/api/controller.ts index cdc1b97..398c3ce 100644 --- a/src/api/controller.ts +++ b/src/api/controller.ts @@ -22,6 +22,7 @@ import { getSearch, getSimilarSongs, getTopSongs, + getSongsByGenre, getStarred, scrobble, setRating, @@ -95,6 +96,7 @@ const endpoints = [ { id: 'getDownloadUrl', endpoint: { subsonic: getDownloadUrl, jellyfin: jfGetDownloadUrl } }, { id: 'getSongs', endpoint: { subsonic: undefined, jellyfin: jfGetSongs } }, { id: 'getTopSongs', endpoint: { subsonic: getTopSongs, jellyfin: undefined } }, + { id: 'getSongsByGenre', endpoint: { subsonic: getSongsByGenre, jellyfin: jfGetSongs } }, // 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. diff --git a/src/types.ts b/src/types.ts index 41781e2..d123e81 100644 --- a/src/types.ts +++ b/src/types.ts @@ -52,7 +52,8 @@ export type APIEndpoints = | 'getMusicDirectorySongs' | 'getDownloadUrl' | 'getSongs' - | 'getTopSongs'; + | 'getTopSongs' + | 'getSongsByGenre'; export interface GenericItem { id: string;