Browse Source

Add getSongsByGenre for jellyfin API

master
jeffvli 3 years ago
committed by Jeff
parent
commit
7d7d0ead13
  1. 3
      src/api/controller.ts
  2. 45
      src/api/jellyfinApi.ts

3
src/api/controller.ts

@ -65,6 +65,7 @@ import {
updatePlaylist as jfUpdatePlaylist,
getSongs as jfGetSongs,
getSimilarSongs as jfGetSimilarSongs,
getSongsByGenre as jfGetSongsByGenre,
} from './jellyfinApi';
import { APIEndpoints, ServerType } from '../types';
@ -97,7 +98,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 } },
{ id: 'getSongsByGenre', endpoint: { subsonic: getSongsByGenre, jellyfin: jfGetSongsByGenre } },
{ id: 'getLyrics', endpoint: { subsonic: getLyrics, jellyfin: undefined } },
// Playlist handling logic is split up by server type due to differences in how each server handles them.

45
src/api/jellyfinApi.ts

@ -688,6 +688,51 @@ export const getSimilarSongs = async (options: {
return (data.Items || []).map((entry: any) => normalizeSong(entry));
};
export const getSongsByGenre = async (options: {
genre: string;
size: number;
offset: number;
musicFolderId?: string | number;
recursive?: boolean;
}) => {
if (options.recursive) {
const { data } = await jellyfinApi.get(`/users/${auth.username}/items`, {
params: {
fields: 'Genres, DateCreated, MediaSources, UserData, ParentId',
genres: options.genre,
recursive: true,
includeItemTypes: 'Audio',
StartIndex: 0,
},
});
const entries = (data.Items || []).map((entry: any) => normalizeSong(entry));
return normalizeAPIResult(
_.orderBy(entries || [], ['album', 'track'], ['asc', 'asc']),
data.TotalRecordCount
);
}
const { data } = await jellyfinApi.get(`/users/${auth.username}/items`, {
params: {
fields: 'Genres, DateCreated, MediaSources, UserData, ParentId',
genres: options.genre,
recursive: true,
includeItemTypes: 'Audio',
limit: options.size || 100,
startIndex: options.offset,
},
});
const entries = (data.Items || []).map((entry: any) => normalizeSong(entry));
return normalizeAPIResult(
_.orderBy(entries || [], ['album', 'track'], ['asc', 'asc']),
data.TotalRecordCount
);
};
export const getGenres = async (options: { musicFolderId?: string }) => {
const { data } = await jellyfinApi.get(`/musicgenres`, {
params: { parentId: options.musicFolderId },

Loading…
Cancel
Save