Add getSongsByGenre endpoint

This commit is contained in:
jeffvli
2022-01-19 05:30:48 -08:00
parent c921201d31
commit a3c22ee805
3 changed files with 19 additions and 4 deletions

View File

@@ -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');

View File

@@ -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.

View File

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