Browse Source

Add initial getSongs endpoint for jellyfin

master
jeffvli 3 years ago
committed by Jeff
parent
commit
44e27d0d25
  1. 2
      src/api/controller.ts
  2. 61
      src/api/jellyfinApi.ts
  3. 3
      src/types.ts

2
src/api/controller.ts

@ -61,6 +61,7 @@ import {
updatePlaylistSongs as jfUpdatePlaylistSongs,
updatePlaylistSongsLg as jfUpdatePlaylingSongsLg,
updatePlaylist as jfUpdatePlaylist,
getSongs as jfGetSongs,
} from './jellyfinApi';
import { APIEndpoints, ServerType } from '../types';
@ -91,6 +92,7 @@ const endpoints = [
{ id: 'getMusicDirectory', endpoint: { subsonic: getMusicDirectory, jellyfin: jfGetMusicDirectory } },
{ id: 'getMusicDirectorySongs', endpoint: { subsonic: getMusicDirectorySongs, jellyfin: jfGetMusicDirectorySongs } },
{ id: 'getDownloadUrl', endpoint: { subsonic: getDownloadUrl, jellyfin: jfGetDownloadUrl } },
{ id: 'getSongs', endpoint: { subsonic: undefined, 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.

61
src/api/jellyfinApi.ts

@ -392,7 +392,7 @@ export const getAlbums = async (options: {
fields: 'Genres, DateCreated, ChildCount, ParentId',
includeItemTypes: 'MusicAlbum',
limit: options.size,
offset: options.offset,
startIndex: options.offset,
parentId: options.musicFolderId,
recursive: true,
sortBy: sortType!.replacement,
@ -403,6 +403,65 @@ export const getAlbums = async (options: {
return (data.Items || []).map((entry: any) => normalizeAlbum(entry));
};
export const getSongs = async (options: {
type: any;
size: number;
offset: number;
recursive: boolean;
order: 'asc' | 'desc';
musicFolderId?: string;
}) => {
const sortTypes = [
{ original: 'alphabeticalByName', replacement: 'SortName' },
{ original: 'alphabeticalByArtist', replacement: 'AlbumArtist' },
{ original: 'alphabeticalByTrackArtist', replacement: 'Artist' },
{ original: 'frequent', replacement: 'PlayCount' },
{ original: 'random', replacement: 'Random' },
{ original: 'newest', replacement: 'DateCreated' },
{ original: 'recent', replacement: 'DatePlayed' },
{ original: 'playCount', replacement: 'PlayCount' },
{ original: 'year', replacement: 'PremiereDate' },
{ original: 'duration', replacement: 'Runtime' },
];
const sortType = sortTypes.find((type) => type.original === options.type);
if (options.recursive) {
const { data } = await jellyfinApi.get(`/users/${auth.username}/items`, {
params: {
fields: 'Genres, DateCreated, MediaSources, ParentId',
genres: !sortType ? options.type : undefined,
includeItemTypes: 'Audio',
parentId: options.musicFolderId,
recursive: true,
sortBy: sortType ? sortType!.replacement : 'SortName',
sortOrder: options.order === 'asc' ? 'Ascending' : 'Descending',
imageTypeLimit: 1,
enableImageTypes: 'Primary',
},
});
return (data.Items || []).map((entry: any) => normalizeSong(entry));
}
const { data } = await jellyfinApi.get(`/users/${auth.username}/items`, {
params: {
fields: 'Genres, DateCreated, MediaSources, ParentId',
includeItemTypes: 'Audio',
limit: options.size,
startIndex: options.offset,
parentId: options.musicFolderId,
recursive: true,
sortBy: sortType!.replacement,
sortOrder: options.order === 'asc' ? 'Ascending' : 'Descending',
imageTypeLimit: 1,
enableImageTypes: 'Primary',
},
});
return (data.Items || []).map((entry: any) => normalizeSong(entry));
};
export const getArtist = async (options: { id: string; musicFolderId?: string }) => {
const { data } = await jellyfinApi.get(`/users/${auth.username}/items/${options.id}`);
const { data: albumData } = await jellyfinApi.get(`/users/${auth.username}/items`, {

3
src/types.ts

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

Loading…
Cancel
Save