Improved lyric syncing, fetch

- uses a somewhat more sane way to parse lyrics and teardown timeouts
- adds 'seeked' to setCurrentTime to make detecting seeks in lyric much easier
- adds ability to fetch lyrics from genius/netease (desktop only)
This commit is contained in:
Kendall Garner 2023-05-28 14:31:49 -07:00 committed by Jeff
parent 23f9bd4e9f
commit 85d2576bdc
25 changed files with 907 additions and 118 deletions

View file

@ -0,0 +1,26 @@
import { QueueSong } from '/@/renderer/api/types';
import { query as queryGenius } from './genius';
import { query as queryNetease } from './netease';
import { LyricSource } from '../../../../renderer/types';
import { ipcMain } from 'electron';
import { getMainWindow } from '../../../main';
import { store } from '../settings/index';
type SongFetcher = (song: QueueSong) => Promise<string | null>;
const FETCHERS: Record<LyricSource, SongFetcher> = {
[LyricSource.GENIUS]: queryGenius,
[LyricSource.NETEASE]: queryNetease,
};
ipcMain.on('lyric-fetch', async (_event, song: QueueSong) => {
const sources = store.get('lyrics', []) as LyricSource[];
for (const source of sources) {
const lyric = await FETCHERS[source](song);
if (lyric) {
getMainWindow()?.webContents.send('lyric-get', song.name, source, lyric);
break;
}
}
});