support .txt

This commit is contained in:
Kendall Garner 2023-06-03 00:39:50 -07:00 committed by Jeff
parent 58f38b2655
commit 9eef570740
5 changed files with 20 additions and 13 deletions

View file

@ -47,7 +47,7 @@ import type {
SearchArgs, SearchArgs,
SearchResponse, SearchResponse,
LyricsArgs, LyricsArgs,
SynchronizedLyricsArray, LyricsResponse,
} from '/@/renderer/api/types'; } from '/@/renderer/api/types';
import { ServerType } from '/@/renderer/types'; import { ServerType } from '/@/renderer/types';
import { DeletePlaylistResponse, RandomSongListArgs } from './types'; import { DeletePlaylistResponse, RandomSongListArgs } from './types';
@ -78,7 +78,7 @@ export type ControllerEndpoint = Partial<{
getFolderList: () => void; getFolderList: () => void;
getFolderSongs: () => void; getFolderSongs: () => void;
getGenreList: (args: GenreListArgs) => Promise<GenreListResponse>; getGenreList: (args: GenreListArgs) => Promise<GenreListResponse>;
getLyrics: (args: LyricsArgs) => Promise<SynchronizedLyricsArray>; getLyrics: (args: LyricsArgs) => Promise<LyricsResponse>;
getMusicFolderList: (args: MusicFolderListArgs) => Promise<MusicFolderListResponse>; getMusicFolderList: (args: MusicFolderListArgs) => Promise<MusicFolderListResponse>;
getPlaylistDetail: (args: PlaylistDetailArgs) => Promise<PlaylistDetailResponse>; getPlaylistDetail: (args: PlaylistDetailArgs) => Promise<PlaylistDetailResponse>;
getPlaylistList: (args: PlaylistListArgs) => Promise<PlaylistListResponse>; getPlaylistList: (args: PlaylistListArgs) => Promise<PlaylistListResponse>;

View file

@ -45,7 +45,7 @@ import {
RandomSongListResponse, RandomSongListResponse,
RandomSongListArgs, RandomSongListArgs,
LyricsArgs, LyricsArgs,
SynchronizedLyricsArray, LyricsResponse,
} from '/@/renderer/api/types'; } from '/@/renderer/api/types';
import { jfApiClient } from '/@/renderer/api/jellyfin/jellyfin-api'; import { jfApiClient } from '/@/renderer/api/jellyfin/jellyfin-api';
import { jfNormalize } from './jellyfin-normalize'; import { jfNormalize } from './jellyfin-normalize';
@ -849,7 +849,7 @@ const getRandomSongList = async (args: RandomSongListArgs): Promise<RandomSongLi
}; };
}; };
const getLyrics = async (args: LyricsArgs): Promise<SynchronizedLyricsArray> => { const getLyrics = async (args: LyricsArgs): Promise<LyricsResponse> => {
const { query, apiClientProps } = args; const { query, apiClientProps } = args;
if (!apiClientProps.server?.userId) { if (!apiClientProps.server?.userId) {
@ -867,7 +867,11 @@ const getLyrics = async (args: LyricsArgs): Promise<SynchronizedLyricsArray> =>
throw new Error('Failed to get lyrics'); throw new Error('Failed to get lyrics');
} }
return res.body.Lyrics.map((lyric) => [lyric.Start / 1e4, lyric.Text]); if (res.body.Lyrics.length > 0 && res.body.Lyrics[0].Start === undefined) {
return res.body.Lyrics[0].Text;
}
return res.body.Lyrics.map((lyric) => [lyric.Start! / 1e4, lyric.Text]);
}; };
export const jfController = { export const jfController = {

View file

@ -632,7 +632,7 @@ const searchParameters = paginationParameters.merge(baseParameters);
const search = z.any(); const search = z.any();
const lyricText = z.object({ const lyricText = z.object({
Start: z.number(), Start: z.number().optional(),
Text: z.string(), Text: z.string(),
}); });

View file

@ -1027,6 +1027,8 @@ export type LyricsArgs = {
export type SynchronizedLyricsArray = Array<[number, string]>; export type SynchronizedLyricsArray = Array<[number, string]>;
export type LyricsResponse = SynchronizedLyricsArray | string;
export const instanceOfCancellationError = (error: any) => { export const instanceOfCancellationError = (error: any) => {
return 'revert' in error; return 'revert' in error;
}; };

View file

@ -9,7 +9,7 @@ import { LyricLine } from '/@/renderer/features/lyrics/lyric-line';
import { Center, Group } from '@mantine/core'; import { Center, Group } from '@mantine/core';
import { RiInformationFill } from 'react-icons/ri'; import { RiInformationFill } from 'react-icons/ri';
import { TextTitle } from '/@/renderer/components'; import { TextTitle } from '/@/renderer/components';
import { SynchronizedLyricsArray } from '/@/renderer/api/types'; import { LyricsResponse, SynchronizedLyricsArray } from '/@/renderer/api/types';
import { useSongLyrics } from '/@/renderer/features/lyrics/queries/lyric-query'; import { useSongLyrics } from '/@/renderer/features/lyrics/queries/lyric-query';
const lyrics = isElectron() ? window.electron.lyrics : null; const lyrics = isElectron() ? window.electron.lyrics : null;
@ -25,7 +25,7 @@ export const Lyrics = () => {
const [override, setOverride] = useState<string | null>(null); const [override, setOverride] = useState<string | null>(null);
const [source, setSource] = useState<string | null>(null); const [source, setSource] = useState<string | null>(null);
const [songLyrics, setSongLyrics] = useState<SynchronizedLyricsArray | string | null>(null); const [songLyrics, setSongLyrics] = useState<LyricsResponse | null>(null);
const remoteLyrics = useSongLyrics({ const remoteLyrics = useSongLyrics({
query: { songId: currentSong?.id ?? '' }, query: { songId: currentSong?.id ?? '' },
@ -48,7 +48,7 @@ export const Lyrics = () => {
}, []); }, []);
useEffect(() => { useEffect(() => {
if (currentSong && !currentSong.lyrics && !remoteLyrics.isLoading && !remoteLyrics.isSuccess) { if (currentSong && !currentSong.lyrics && !remoteLyrics.isLoading && !remoteLyrics.data) {
lyrics?.fetchLyrics(currentSong); lyrics?.fetchLyrics(currentSong);
} }
@ -56,7 +56,7 @@ export const Lyrics = () => {
setOverride(null); setOverride(null);
setSource(null); setSource(null);
}, [currentSong, remoteLyrics.isLoading, remoteLyrics.isSuccess]); }, [currentSong, remoteLyrics.isLoading, remoteLyrics.data]);
useEffect(() => { useEffect(() => {
let lyrics: string | null = null; let lyrics: string | null = null;
@ -67,9 +67,10 @@ export const Lyrics = () => {
setSource(currentServer?.name ?? 'music server'); setSource(currentServer?.name ?? 'music server');
} else if (override) { } else if (override) {
lyrics = override; lyrics = override;
} else if (remoteLyrics.isSuccess) { } else if (remoteLyrics.data) {
console.log(remoteLyrics.data);
setSource(currentServer?.name ?? 'music server'); setSource(currentServer?.name ?? 'music server');
setSongLyrics(remoteLyrics.data!); setSongLyrics(remoteLyrics.data);
return; return;
} }
@ -96,7 +97,7 @@ export const Lyrics = () => {
} else { } else {
setSongLyrics(null); setSongLyrics(null);
} }
}, [currentServer?.name, currentSong, override, remoteLyrics.data, remoteLyrics.isSuccess]); }, [currentServer?.name, currentSong, override, remoteLyrics.data]);
return ( return (
<ErrorBoundary FallbackComponent={ErrorFallback}> <ErrorBoundary FallbackComponent={ErrorFallback}>