mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-02 19:01:40 +00:00
Add lyric search selection and override
This commit is contained in:
parent
f8ecb3fc53
commit
2f0634dc03
6 changed files with 140 additions and 35 deletions
|
|
@ -5,6 +5,7 @@ import {
|
|||
SynchronizedLyricsArray,
|
||||
InternetProviderLyricResponse,
|
||||
FullLyricsMetadata,
|
||||
LyricGetQuery,
|
||||
} from '/@/renderer/api/types';
|
||||
import { QueryHookArgs } from '/@/renderer/lib/react-query';
|
||||
import { getServerById, useLyricsSettings } from '/@/renderer/store';
|
||||
|
|
@ -43,7 +44,10 @@ const formatLyrics = (lyrics: string) => {
|
|||
const alternateSynchronizedLines = lyrics.matchAll(alternateTimeExp);
|
||||
for (const line of alternateSynchronizedLines) {
|
||||
const [, timeInMilis, , text] = line;
|
||||
const cleanText = text.replaceAll(/\(\d+,\d+\)/g, '');
|
||||
const cleanText = text
|
||||
.replaceAll(/\(\d+,\d+\)/g, '')
|
||||
.replaceAll(/\s,/g, ',')
|
||||
.replaceAll(/\s\./g, '.');
|
||||
formattedLyrics.push([Number(timeInMilis), cleanText]);
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +77,7 @@ export const useServerLyrics = (
|
|||
});
|
||||
};
|
||||
|
||||
export const useSongLyrics = (
|
||||
export const useSongLyricsBySong = (
|
||||
args: QueryHookArgs<LyricsQuery>,
|
||||
song: QueueSong | undefined,
|
||||
): UseQueryResult<FullLyricsMetadata> => {
|
||||
|
|
@ -120,7 +124,7 @@ export const useSongLyrics = (
|
|||
|
||||
if (fetch) {
|
||||
const remoteLyricsResult: InternetProviderLyricResponse | null =
|
||||
await lyricsIpc?.fetchRemoteLyrics(song);
|
||||
await lyricsIpc?.getRemoteLyricsBySong(song);
|
||||
|
||||
if (remoteLyricsResult) {
|
||||
return {
|
||||
|
|
@ -137,3 +141,26 @@ export const useSongLyrics = (
|
|||
staleTime: 1000 * 60 * 2,
|
||||
});
|
||||
};
|
||||
|
||||
export const useSongLyricsByRemoteId = (
|
||||
args: QueryHookArgs<Partial<LyricGetQuery>>,
|
||||
): UseQueryResult<string | null> => {
|
||||
const { query } = args;
|
||||
|
||||
return useQuery({
|
||||
cacheTime: 1000 * 60 * 10,
|
||||
enabled: !!query.remoteSongId && !!query.remoteSource,
|
||||
onError: () => {},
|
||||
queryFn: async () => {
|
||||
const remoteLyricsResult: string | null = await lyricsIpc?.getRemoteLyricsByRemoteId(query);
|
||||
|
||||
if (remoteLyricsResult) {
|
||||
return formatLyrics(remoteLyricsResult);
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
queryKey: queryKeys.songs.lyricsByRemoteId(query),
|
||||
staleTime: 1000 * 60 * 5,
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue