Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | 45x 45x 7x 3x 3x 3x 2x 1x 1x 1x 1x 1x 1x | import {
GetLyrics,
IlrclibResponse,
ILyrics,
LyricsAction,
} from "types/lyrics";
import { baseUrl, lyricsApiUrl, normalizeLrcLibLyrics } from "utils";
export async function getLyrics(
artistName: string,
title: string,
trackId?: string | null,
action?: LyricsAction
): Promise<GetLyrics> {
if (action === LyricsAction.Fullscreen) {
Iif (lyricsApiUrl) {
const resSyncedLyrics = await fetch(
lyricsApiUrl ?? `${baseUrl}/api/synced-lyrics`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ trackId }),
}
);
Iif (resSyncedLyrics.ok) {
const data = (await resSyncedLyrics.json()) as ILyrics;
Iif (data) {
return { ...data, isFullscreen: true };
}
}
}
const lrclibRes = await fetch(
`https://lrclib.net/api/get?artist_name=${encodeURIComponent(artistName)}&track_name=${encodeURIComponent(title)}`
);
if (lrclibRes.ok) {
const data = (await lrclibRes.json()) as IlrclibResponse;
const nomarlizedData = normalizeLrcLibLyrics(data);
return {
...nomarlizedData,
isFullscreen: true,
};
}
}
const res = await fetch(`${baseUrl}/api/lyrics`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ artistName, title }),
});
Iif (res.ok) {
const lyrics = (await res.json()) as string | null;
return { lyrics, isFullscreen: false };
}
return null;
}
|