add jellyfin, improvements

This commit is contained in:
Kendall Garner 2023-06-02 23:54:34 -07:00 committed by Jeff
parent 85d2576bdc
commit 58f38b2655
11 changed files with 168 additions and 17 deletions

View file

@ -174,6 +174,14 @@ export const contract = c.router({
400: jfType._response.error,
},
},
getSongLyrics: {
method: 'GET',
path: 'users/:userId/Items/:id/Lyrics',
responses: {
200: jfType._response.lyrics,
404: jfType._response.error,
},
},
getTopSongsList: {
method: 'GET',
path: 'users/:userId/items',

View file

@ -44,6 +44,8 @@ import {
SearchResponse,
RandomSongListResponse,
RandomSongListArgs,
LyricsArgs,
SynchronizedLyricsArray,
} from '/@/renderer/api/types';
import { jfApiClient } from '/@/renderer/api/jellyfin/jellyfin-api';
import { jfNormalize } from './jellyfin-normalize';
@ -846,6 +848,28 @@ const getRandomSongList = async (args: RandomSongListArgs): Promise<RandomSongLi
totalRecordCount: res.body.Items.length || 0,
};
};
const getLyrics = async (args: LyricsArgs): Promise<SynchronizedLyricsArray> => {
const { query, apiClientProps } = args;
if (!apiClientProps.server?.userId) {
throw new Error('No userId found');
}
const res = await jfApiClient(apiClientProps).getSongLyrics({
params: {
id: query.songId,
userId: apiClientProps.server?.userId,
},
});
if (res.status !== 200) {
throw new Error('Failed to get lyrics');
}
return res.body.Lyrics.map((lyric) => [lyric.Start / 1e4, lyric.Text]);
};
export const jfController = {
addToPlaylist,
authenticate,
@ -859,6 +883,7 @@ export const jfController = {
getAlbumList,
getArtistList,
getGenreList,
getLyrics,
getMusicFolderList,
getPlaylistDetail,
getPlaylistList,

View file

@ -631,6 +631,15 @@ const searchParameters = paginationParameters.merge(baseParameters);
const search = z.any();
const lyricText = z.object({
Start: z.number(),
Text: z.string(),
});
const lyrics = z.object({
Lyrics: z.array(lyricText),
});
export const jfType = {
_enum: {
collection: jfCollection,
@ -670,6 +679,7 @@ export const jfType = {
favorite,
genre,
genreList,
lyrics,
musicFolderList,
playlist,
playlistList,