mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-01 02:13:33 +00:00
os lyrics
This commit is contained in:
parent
9e4664a54c
commit
73cd647486
9 changed files with 182 additions and 46 deletions
|
|
@ -50,6 +50,8 @@ import type {
|
|||
LyricsResponse,
|
||||
ServerInfo,
|
||||
ServerInfoArgs,
|
||||
StructuredLyricsArgs,
|
||||
StructuredLyric,
|
||||
} from '/@/renderer/api/types';
|
||||
import { ServerType } from '/@/renderer/types';
|
||||
import { DeletePlaylistResponse, RandomSongListArgs } from './types';
|
||||
|
|
@ -90,6 +92,7 @@ export type ControllerEndpoint = Partial<{
|
|||
getServerInfo: (args: ServerInfoArgs) => Promise<ServerInfo>;
|
||||
getSongDetail: (args: SongDetailArgs) => Promise<SongDetailResponse>;
|
||||
getSongList: (args: SongListArgs) => Promise<SongListResponse>;
|
||||
getStructuredLyrics: (args: StructuredLyricsArgs) => Promise<StructuredLyric[]>;
|
||||
getTopSongs: (args: TopSongListArgs) => Promise<TopSongListResponse>;
|
||||
getUserList: (args: UserListArgs) => Promise<UserListResponse>;
|
||||
removeFromPlaylist: (args: RemoveFromPlaylistArgs) => Promise<RemoveFromPlaylistResponse>;
|
||||
|
|
@ -135,6 +138,7 @@ const endpoints: ApiController = {
|
|||
getServerInfo: jfController.getServerInfo,
|
||||
getSongDetail: jfController.getSongDetail,
|
||||
getSongList: jfController.getSongList,
|
||||
getStructuredLyrics: undefined,
|
||||
getTopSongs: jfController.getTopSongList,
|
||||
getUserList: undefined,
|
||||
removeFromPlaylist: jfController.removeFromPlaylist,
|
||||
|
|
@ -172,6 +176,7 @@ const endpoints: ApiController = {
|
|||
getServerInfo: ssController.getServerInfo,
|
||||
getSongDetail: ndController.getSongDetail,
|
||||
getSongList: ndController.getSongList,
|
||||
getStructuredLyrics: ssController.getStructuredLyrics,
|
||||
getTopSongs: ssController.getTopSongList,
|
||||
getUserList: ndController.getUserList,
|
||||
removeFromPlaylist: ndController.removeFromPlaylist,
|
||||
|
|
@ -206,6 +211,7 @@ const endpoints: ApiController = {
|
|||
getServerInfo: ssController.getServerInfo,
|
||||
getSongDetail: undefined,
|
||||
getSongList: undefined,
|
||||
getStructuredLyrics: ssController.getStructuredLyrics,
|
||||
getTopSongs: ssController.getTopSongList,
|
||||
getUserList: undefined,
|
||||
scrobble: ssController.scrobble,
|
||||
|
|
@ -496,6 +502,15 @@ const getServerInfo = async (args: ServerInfoArgs) => {
|
|||
)?.(args);
|
||||
};
|
||||
|
||||
const getStructuredLyrics = async (args: StructuredLyricsArgs) => {
|
||||
return (
|
||||
apiController(
|
||||
'getStructuredLyrics',
|
||||
args.apiClientProps.server?.type,
|
||||
) as ControllerEndpoint['getStructuredLyrics']
|
||||
)?.(args);
|
||||
};
|
||||
|
||||
export const controller = {
|
||||
addToPlaylist,
|
||||
authenticate,
|
||||
|
|
@ -518,6 +533,7 @@ export const controller = {
|
|||
getServerInfo,
|
||||
getSongDetail,
|
||||
getSongList,
|
||||
getStructuredLyrics,
|
||||
getTopSongList,
|
||||
getUserList,
|
||||
removeFromPlaylist,
|
||||
|
|
|
|||
|
|
@ -57,6 +57,14 @@ export const contract = c.router({
|
|||
200: ssType._response.serverInfo,
|
||||
},
|
||||
},
|
||||
getStructuredLyrics: {
|
||||
method: 'GET',
|
||||
path: 'getLyricsBySongId.view',
|
||||
query: ssType._parameters.structuredLyrics,
|
||||
responses: {
|
||||
200: ssType._response.structuredLyrics,
|
||||
},
|
||||
},
|
||||
getTopSongsList: {
|
||||
method: 'GET',
|
||||
path: 'getTopSongs.view',
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ import {
|
|||
RandomSongListArgs,
|
||||
ServerInfo,
|
||||
ServerInfoArgs,
|
||||
StructuredLyricsArgs,
|
||||
StructuredLyric,
|
||||
} from '/@/renderer/api/types';
|
||||
import { randomString } from '/@/renderer/utils';
|
||||
|
||||
|
|
@ -397,6 +399,51 @@ const getServerInfo = async (args: ServerInfoArgs): Promise<ServerInfo> => {
|
|||
return { features, id: apiClientProps.server?.id, version: ping.body.serverVersion };
|
||||
};
|
||||
|
||||
export const getStructuredLyrics = async (
|
||||
args: StructuredLyricsArgs,
|
||||
): Promise<StructuredLyric[]> => {
|
||||
const { query, apiClientProps } = args;
|
||||
|
||||
const res = await ssApiClient(apiClientProps).getStructuredLyrics({
|
||||
query: {
|
||||
id: query.songId,
|
||||
},
|
||||
});
|
||||
|
||||
if (res.status !== 200) {
|
||||
throw new Error('Failed to get server extensions');
|
||||
}
|
||||
|
||||
const lyrics = res.body.lyricsList?.structuredLyrics;
|
||||
|
||||
if (!lyrics) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return lyrics.map((lyric) => {
|
||||
const baseLyric = {
|
||||
artist: lyric.displayArtist || '',
|
||||
lang: lyric.lang,
|
||||
name: lyric.displayTitle || '',
|
||||
remote: false,
|
||||
source: apiClientProps.server?.name || 'music server',
|
||||
};
|
||||
|
||||
if (lyric.synced) {
|
||||
return {
|
||||
...baseLyric,
|
||||
lyrics: lyric.line.map((line) => [line.start!, line.value]),
|
||||
synced: true,
|
||||
};
|
||||
}
|
||||
return {
|
||||
...baseLyric,
|
||||
lyrics: lyric.line.map((line) => [line.value]).join('\n'),
|
||||
synced: false,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
export const ssController = {
|
||||
authenticate,
|
||||
createFavorite,
|
||||
|
|
@ -404,6 +451,7 @@ export const ssController = {
|
|||
getMusicFolderList,
|
||||
getRandomSongList,
|
||||
getServerInfo,
|
||||
getStructuredLyrics,
|
||||
getTopSongList,
|
||||
removeFavorite,
|
||||
scrobble,
|
||||
|
|
|
|||
|
|
@ -221,6 +221,32 @@ const serverInfo = z.object({
|
|||
openSubsonicExtensions: z.array(extension),
|
||||
});
|
||||
|
||||
const structuredLyricsParameters = z.object({
|
||||
id: z.string(),
|
||||
});
|
||||
|
||||
const lyricLine = z.object({
|
||||
start: z.number().optional(),
|
||||
value: z.string(),
|
||||
});
|
||||
|
||||
const structuredLyric = z.object({
|
||||
displayArtist: z.string().optional(),
|
||||
displayTitle: z.string().optional(),
|
||||
lang: z.string(),
|
||||
line: z.array(lyricLine),
|
||||
offset: z.number().optional(),
|
||||
synced: z.boolean(),
|
||||
});
|
||||
|
||||
const structuredLyrics = z.object({
|
||||
lyricsList: z
|
||||
.object({
|
||||
structuredLyrics: z.array(structuredLyric).optional(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
|
||||
export const ssType = {
|
||||
_parameters: {
|
||||
albumList: albumListParameters,
|
||||
|
|
@ -232,6 +258,7 @@ export const ssType = {
|
|||
scrobble: scrobbleParameters,
|
||||
search3: search3Parameters,
|
||||
setRating: setRatingParameters,
|
||||
structuredLyrics: structuredLyricsParameters,
|
||||
topSongsList: topSongsListParameters,
|
||||
},
|
||||
_response: {
|
||||
|
|
@ -252,6 +279,7 @@ export const ssType = {
|
|||
serverInfo,
|
||||
setRating,
|
||||
song,
|
||||
structuredLyrics,
|
||||
topSongsList,
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1092,17 +1092,11 @@ export type InternetProviderLyricSearchResponse = {
|
|||
source: LyricSource;
|
||||
};
|
||||
|
||||
export type SynchronizedLyricMetadata = {
|
||||
lyrics: SynchronizedLyricsArray;
|
||||
export type FullLyricsMetadata = {
|
||||
lyrics: LyricsResponse;
|
||||
remote: boolean;
|
||||
} & Omit<InternetProviderLyricResponse, 'lyrics'>;
|
||||
|
||||
export type UnsynchronizedLyricMetadata = {
|
||||
lyrics: string;
|
||||
remote: boolean;
|
||||
} & Omit<InternetProviderLyricResponse, 'lyrics'>;
|
||||
|
||||
export type FullLyricsMetadata = SynchronizedLyricMetadata | UnsynchronizedLyricMetadata;
|
||||
source: string;
|
||||
} & Omit<InternetProviderLyricResponse, 'id' | 'lyrics' | 'source'>;
|
||||
|
||||
export type LyricOverride = Omit<InternetProviderLyricResponse, 'lyrics'>;
|
||||
|
||||
|
|
@ -1153,3 +1147,21 @@ export type ServerInfo = {
|
|||
id?: string;
|
||||
version: string;
|
||||
};
|
||||
|
||||
export type StructuredLyricsArgs = {
|
||||
query: LyricsQuery;
|
||||
} & BaseEndpointArgs;
|
||||
|
||||
export type StructuredUnsyncedLyric = {
|
||||
lyrics: string;
|
||||
synced: false;
|
||||
} & Omit<FullLyricsMetadata, 'lyrics'>;
|
||||
|
||||
export type StructuredSyncedLyric = {
|
||||
lyrics: SynchronizedLyricsArray;
|
||||
synced: true;
|
||||
} & Omit<FullLyricsMetadata, 'lyrics'>;
|
||||
|
||||
export type StructuredLyric = {
|
||||
lang: string;
|
||||
} & (StructuredUnsyncedLyric | StructuredSyncedLyric);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue