Add search for jellyfin

This commit is contained in:
jeffvli
2021-11-20 16:53:29 -08:00
committed by Jeff
parent a6fd1e8c48
commit a8ce2efacb
3 changed files with 33 additions and 6 deletions

View File

@@ -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 } },

View File

@@ -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)),
};
};

View File

@@ -20,7 +20,6 @@ import { setStatus } from '../../redux/playerSlice';
import ListViewTable from '../viewtypes/ListViewTable';
import { SectionTitle, SectionTitleWrapper, StyledPanel } from '../shared/styled';
import { apiController } from '../../api/controller';
import { Server } from '../../types';
const SearchView = () => {
const dispatch = useAppDispatch();
@@ -44,10 +43,7 @@ const SearchView = () => {
apiController({
serverType: config.serverType,
endpoint: 'getSearch',
args:
config.serverType === Server.Subsonic
? { query: urlQuery, songCount: 100, musicFolderId: musicFolder }
: null,
args: { query: urlQuery, songCount: 100, musicFolderId: musicFolder },
})
);