diff --git a/src/api/controller.ts b/src/api/controller.ts index db14741..aa60fd2 100644 --- a/src/api/controller.ts +++ b/src/api/controller.ts @@ -41,6 +41,7 @@ import { getPlaylist as jfGetPlaylist, getPlaylists as jfGetPlaylists, getRandomSongs as jfGetRandomSongs, + getStarred as jfGetStarred, } from './jellyfinApi'; import { APIEndpoints, ServerType } from '../types'; @@ -48,7 +49,7 @@ import { APIEndpoints, ServerType } from '../types'; const endpoints = [ { id: 'getPlaylist', endpoint: { subsonic: getPlaylist, jellyfin: jfGetPlaylist } }, { id: 'getPlaylists', endpoint: { subsonic: getPlaylists, jellyfin: jfGetPlaylists } }, - { id: 'getStarred', endpoint: { subsonic: getStarred, jellyfin: undefined } }, + { id: 'getStarred', endpoint: { subsonic: getStarred, jellyfin: jfGetStarred } }, { id: 'getAlbum', endpoint: { subsonic: getAlbum, jellyfin: jfGetAlbum } }, { id: 'getAlbums', endpoint: { subsonic: getAlbums, jellyfin: jfGetAlbums } }, { id: 'getRandomSongs', endpoint: { subsonic: getRandomSongs, jellyfin: jfGetRandomSongs } }, diff --git a/src/api/jellyfinApi.ts b/src/api/jellyfinApi.ts index e322871..4ffff44 100644 --- a/src/api/jellyfinApi.ts +++ b/src/api/jellyfinApi.ts @@ -345,3 +345,35 @@ export const getRandomSongs = async (options: { return (data.Items || []).map((entry: any) => normalizeSong(entry)); }; + +export const getStarred = async () => { + const { data: songAndAlbumData } = await jellyfinApi.get(`/users/${auth.username}/items`, { + params: { + fields: 'Genres, DateCreated, MediaSources, ChildCount, UserData', + includeItemTypes: 'MusicAlbum, Audio', + isFavorite: true, + recursive: true, + }, + }); + + const { data: artistData } = await jellyfinApi.get(`/artists`, { + params: { + imageTypeLimit: 1, + recursive: true, + sortBy: 'SortName', + sortOrder: 'Ascending', + isFavorite: true, + userId: auth.username, + }, + }); + + return { + album: ( + songAndAlbumData.Items.filter((data: any) => data.Type === 'MusicAlbum') || [] + ).map((entry: any) => normalizeAlbum(entry)), + song: ( + songAndAlbumData.Items.filter((data: any) => data.Type === 'Audio') || [] + ).map((entry: any) => normalizeSong(entry)), + artist: (artistData.Items || []).map((entry: any) => normalizeArtist(entry)), + }; +};