mirror of
https://github.com/jeffvli/sonixd.git
synced 2026-05-24 16:54:31 -04:00
Add search for jellyfin
This commit is contained in:
@@ -49,6 +49,7 @@ import {
|
||||
batchUnstar as jfBatchUnstar,
|
||||
getGenres as jfGetGenres,
|
||||
getMusicFolders as jfGetMusicFolders,
|
||||
getSearch as jfGetSearch,
|
||||
} from './jellyfinApi';
|
||||
import { APIEndpoints, ServerType } from '../types';
|
||||
|
||||
@@ -78,7 +79,7 @@ const endpoints = [
|
||||
{ id: 'updatePlaylist', endpoint: { subsonic: updatePlaylist, jellyfin: undefined } },
|
||||
{ id: 'clearPlaylist', endpoint: { subsonic: clearPlaylist, jellyfin: undefined } },
|
||||
{ id: 'getGenres', endpoint: { subsonic: getGenres, jellyfin: jfGetGenres } },
|
||||
{ id: 'getSearch', endpoint: { subsonic: getSearch, jellyfin: undefined } },
|
||||
{ id: 'getSearch', endpoint: { subsonic: getSearch, jellyfin: jfGetSearch } },
|
||||
{ id: 'scrobble', endpoint: { subsonic: scrobble, jellyfin: undefined } },
|
||||
{ id: 'getIndexes', endpoint: { subsonic: getIndexes, jellyfin: undefined } },
|
||||
{ id: 'getMusicFolders', endpoint: { subsonic: getMusicFolders, jellyfin: jfGetMusicFolders } },
|
||||
|
||||
@@ -455,3 +455,33 @@ export const getMusicFolders = async () => {
|
||||
const { data } = await jellyfinApi.get(`/users/${auth.username}/items`);
|
||||
return (data.Items || []).map((entry: any) => normalizeFolder(entry));
|
||||
};
|
||||
|
||||
export const getSearch = async (options: { query: string; musicFolderId?: string | number }) => {
|
||||
const { data } = await jellyfinApi.get(`/users/${auth.username}/items`, {
|
||||
params: {
|
||||
fields: 'Genres, DateCreated, MediaSources, ChildCount, UserData',
|
||||
includeArtists: false,
|
||||
includeGenres: false,
|
||||
includeItemTypes: 'Audio, MusicArtist, MusicAlbum',
|
||||
includeMedia: false,
|
||||
includeStudios: false,
|
||||
limit: 50,
|
||||
parentId: options.musicFolderId,
|
||||
recursive: true,
|
||||
searchTerm: options.query,
|
||||
},
|
||||
});
|
||||
|
||||
const { data: artistData } = await jellyfinApi.get(`/artists`, {
|
||||
params: { limit: 10, parentId: options.musicFolderId, searchTerm: options.query },
|
||||
});
|
||||
|
||||
const albumItems = data.Items.filter((entry: any) => entry.Type === 'MusicAlbum');
|
||||
const songItems = data.Items.filter((entry: any) => entry.Type === 'Audio');
|
||||
|
||||
return {
|
||||
artist: (artistData.Items || []).map((entry: any) => normalizeArtist(entry)),
|
||||
album: (albumItems || []).map((entry: any) => normalizeAlbum(entry)),
|
||||
song: (songItems || []).map((entry: any) => normalizeSong(entry)),
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user