mirror of
https://github.com/antebudimir/feishin.git
synced 2025-12-31 10:03:33 +00:00
add option to set local lyric priority
This commit is contained in:
parent
64866c59bd
commit
620b810191
4 changed files with 47 additions and 8 deletions
|
|
@ -536,6 +536,8 @@
|
|||
"floatingQueueArea_description": "display a hover icon on the right side of the screen to view the play queue",
|
||||
"followLyric": "follow current lyric",
|
||||
"followLyric_description": "scroll the lyric to the current playing position",
|
||||
"preferLocalLyrics": "prefer local lyrics",
|
||||
"preferLocalLyrics_description": "prefer local lyrics over remote lyrics when available",
|
||||
"font": "font",
|
||||
"font_description": "sets the font to use for the application",
|
||||
"fontType": "font type",
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ export const useSongLyricsBySong = (
|
|||
song: QueueSong | undefined,
|
||||
): UseQueryResult<FullLyricsMetadata | StructuredLyric[]> => {
|
||||
const { query } = args;
|
||||
const { fetch } = useLyricsSettings();
|
||||
const { fetch, preferLocalLyrics } = useLyricsSettings();
|
||||
const server = getServerById(song?.serverId);
|
||||
|
||||
return useQuery({
|
||||
|
|
@ -97,6 +97,9 @@ export const useSongLyricsBySong = (
|
|||
if (!server) throw new Error('Server not found');
|
||||
if (!song) return null;
|
||||
|
||||
let localLyrics: FullLyricsMetadata | null | StructuredLyric[] = null;
|
||||
let remoteLyrics: FullLyricsMetadata | null | StructuredLyric[] = null;
|
||||
|
||||
if (hasFeature(server, ServerFeature.LYRICS_MULTIPLE_STRUCTURED)) {
|
||||
const subsonicLyrics = await api.controller
|
||||
.getStructuredLyrics({
|
||||
|
|
@ -106,7 +109,7 @@ export const useSongLyricsBySong = (
|
|||
.catch(console.error);
|
||||
|
||||
if (subsonicLyrics?.length) {
|
||||
return subsonicLyrics;
|
||||
localLyrics = subsonicLyrics;
|
||||
}
|
||||
} else if (hasFeature(server, ServerFeature.LYRICS_SINGLE_STRUCTURED)) {
|
||||
const jfLyrics = await api.controller
|
||||
|
|
@ -117,7 +120,7 @@ export const useSongLyricsBySong = (
|
|||
.catch((err) => console.log(err));
|
||||
|
||||
if (jfLyrics) {
|
||||
return {
|
||||
localLyrics = {
|
||||
artist: song.artists?.[0]?.name,
|
||||
lyrics: jfLyrics,
|
||||
name: song.name,
|
||||
|
|
@ -126,7 +129,7 @@ export const useSongLyricsBySong = (
|
|||
};
|
||||
}
|
||||
} else if (song.lyrics) {
|
||||
return {
|
||||
localLyrics = {
|
||||
artist: song.artists?.[0]?.name,
|
||||
lyrics: formatLyrics(song.lyrics),
|
||||
name: song.name,
|
||||
|
|
@ -135,12 +138,16 @@ export const useSongLyricsBySong = (
|
|||
};
|
||||
}
|
||||
|
||||
if (preferLocalLyrics && localLyrics) {
|
||||
return localLyrics;
|
||||
}
|
||||
|
||||
if (fetch) {
|
||||
const remoteLyricsResult: InternetProviderLyricResponse | null =
|
||||
await lyricsIpc?.getRemoteLyricsBySong(song);
|
||||
|
||||
if (remoteLyricsResult) {
|
||||
return {
|
||||
remoteLyrics = {
|
||||
...remoteLyricsResult,
|
||||
lyrics: formatLyrics(remoteLyricsResult.lyrics),
|
||||
remote: true,
|
||||
|
|
@ -148,6 +155,14 @@ export const useSongLyricsBySong = (
|
|||
}
|
||||
}
|
||||
|
||||
if (remoteLyrics) {
|
||||
return remoteLyrics;
|
||||
}
|
||||
|
||||
if (localLyrics) {
|
||||
return localLyrics;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
queryKey: queryKeys.songs.lyrics(server?.id || '', query),
|
||||
|
|
@ -183,9 +198,7 @@ export const useSongLyricsByRemoteId = (
|
|||
);
|
||||
},
|
||||
queryFn: async () => {
|
||||
const remoteLyricsResult = await lyricsIpc?.getRemoteLyricsByRemoteId(
|
||||
query as LyricGetQuery,
|
||||
);
|
||||
const remoteLyricsResult = await lyricsIpc?.getRemoteLyricsByRemoteId(query as any);
|
||||
|
||||
if (remoteLyricsResult) {
|
||||
return formatLyrics(remoteLyricsResult);
|
||||
|
|
|
|||
|
|
@ -43,6 +43,28 @@ export const LyricSettings = () => {
|
|||
}),
|
||||
title: t('setting.followLyric', { postProcess: 'sentenceCase' }),
|
||||
},
|
||||
{
|
||||
control: (
|
||||
<Switch
|
||||
aria-label="Prefer local lyrics"
|
||||
defaultChecked={settings.preferLocalLyrics}
|
||||
onChange={(e) => {
|
||||
setSettings({
|
||||
lyrics: {
|
||||
...settings,
|
||||
preferLocalLyrics: e.currentTarget.checked,
|
||||
},
|
||||
});
|
||||
}}
|
||||
/>
|
||||
),
|
||||
description: t('setting.preferLocalLyrics', {
|
||||
context: 'description',
|
||||
postProcess: 'sentenceCase',
|
||||
}),
|
||||
isHidden: !isElectron(),
|
||||
title: t('setting.preferLocalLyrics', { postProcess: 'sentenceCase' }),
|
||||
},
|
||||
{
|
||||
control: (
|
||||
<Switch
|
||||
|
|
|
|||
|
|
@ -266,6 +266,7 @@ export interface SettingsState {
|
|||
fontSizeUnsync: number;
|
||||
gap: number;
|
||||
gapUnsync: number;
|
||||
preferLocalLyrics: boolean;
|
||||
showMatch: boolean;
|
||||
showProvider: boolean;
|
||||
sources: LyricSource[];
|
||||
|
|
@ -448,6 +449,7 @@ const initialState: SettingsState = {
|
|||
fontSizeUnsync: 24,
|
||||
gap: 24,
|
||||
gapUnsync: 24,
|
||||
preferLocalLyrics: true,
|
||||
showMatch: true,
|
||||
showProvider: true,
|
||||
sources: [LyricSource.NETEASE, LyricSource.LRCLIB],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue