mirror of
https://github.com/Equicord/Equicord.git
synced 2025-06-15 09:33:03 -04:00
Update SpotifyLyrics!! (#252)
* 1 * Update SpotifyLyrics!! * Update pnpm-lock.yaml --------- Co-authored-by: Crxa <c@crxaw.tech> Co-authored-by: thororen <78185467+thororen1234@users.noreply.github.com>
This commit is contained in:
parent
c9d8f3cc72
commit
fa7f7f2d81
3 changed files with 19 additions and 44 deletions
|
@ -49,7 +49,7 @@ export async function getLyricsLrclib(track: Track): Promise<LyricsData | null>
|
||||||
if (!data.syncedLyrics) return null;
|
if (!data.syncedLyrics) return null;
|
||||||
|
|
||||||
const lyrics = data.syncedLyrics;
|
const lyrics = data.syncedLyrics;
|
||||||
const lines = lyrics.split("\n");
|
const lines = lyrics.split("\n").filter(line => line.trim() !== "");
|
||||||
|
|
||||||
return {
|
return {
|
||||||
useLyric: Provider.Lrclib,
|
useLyric: Provider.Lrclib,
|
||||||
|
|
|
@ -102,38 +102,20 @@ export const SpotifyLrcStore = proxyLazyWebpack(() => {
|
||||||
store.emitChange();
|
store.emitChange();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// stops spamming noftications for translation when there is no lyrics x1
|
|
||||||
if (provider === Provider.Translated || provider === Provider.Romanized) {
|
if (provider === Provider.Translated || provider === Provider.Romanized) {
|
||||||
if (!currentInfo?.useLyric || !currentInfo.lyricsVersions[currentInfo.useLyric]) {
|
if (!currentInfo?.lyricsVersions[Provider.Spotify] && !currentInfo?.lyricsVersions[Provider.Lrclib]) {
|
||||||
console.log("Failed to Translate");
|
showNotif("No lyrics", `No lyrics to ${provider === Provider.Translated ? "translate" : "romanize"}`);
|
||||||
const now = Date.now();
|
return;
|
||||||
if (!window.__lastTranslateFailure) {
|
|
||||||
window.__lastTranslateFailure = now;
|
|
||||||
} else if (now - window.__lastTranslateFailure < 120000) { // 2 minutes
|
|
||||||
window.__lastTranslateFailure = null;
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
window.__lastTranslateFailure = now;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetcher = provider === Provider.Translated ? translateLyrics : romanizeLyrics;
|
const fetcher = provider === Provider.Translated ? translateLyrics : romanizeLyrics;
|
||||||
|
|
||||||
const fetchResult = await fetcher(currentInfo.lyricsVersions[currentInfo.useLyric]);
|
const fetchResult = await fetcher(currentInfo.lyricsVersions[currentInfo.useLyric]);
|
||||||
// stops spamming noftications for when there is no lyrics / cannot be translated x2
|
|
||||||
if (!fetchResult) {
|
if (!fetchResult) {
|
||||||
console.log("Lyrics fetch failed", `Failed to fetch ${provider === Provider.Translated ? "translation" : "romanization"}`);
|
showNotif("Lyrics fetch failed", `Failed to fetch ${provider === Provider.Translated ? "translation" : "romanization"}`);
|
||||||
const now = Date.now();
|
return;
|
||||||
if (!window.__lastTranslateFailure) {
|
|
||||||
window.__lastTranslateFailure = now;
|
|
||||||
} else if (now - window.__lastTranslateFailure < 120000) { // 2 minutes
|
|
||||||
window.__lastTranslateFailure = null;
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
window.__lastTranslateFailure = now;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
store.lyricsInfo = {
|
store.lyricsInfo = {
|
||||||
|
@ -141,7 +123,7 @@ export const SpotifyLrcStore = proxyLazyWebpack(() => {
|
||||||
useLyric: provider,
|
useLyric: provider,
|
||||||
lyricsVersions: {
|
lyricsVersions: {
|
||||||
...currentInfo.lyricsVersions,
|
...currentInfo.lyricsVersions,
|
||||||
[Provider.Translated]: fetchResult
|
[provider]: fetchResult
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -152,19 +134,9 @@ export const SpotifyLrcStore = proxyLazyWebpack(() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const newLyricsInfo = await lyricFetchers[e.provider](store.track!);
|
const newLyricsInfo = await lyricFetchers[e.provider](store.track!);
|
||||||
// stops spamming noftications for when there is no lyrics / cannot be translated x3
|
|
||||||
if (!newLyricsInfo) {
|
if (!newLyricsInfo) {
|
||||||
console.log("Lyrics fetch failed", `Failed to fetch ${e.provider} lyrics`);
|
showNotif("Lyrics fetch failed", `Failed to fetch ${e.provider} lyrics`);
|
||||||
const now = Date.now();
|
return;
|
||||||
if (!window.__lastLyricsFetchFailure) {
|
|
||||||
window.__lastLyricsFetchFailure = now;
|
|
||||||
} else if (now - window.__lastLyricsFetchFailure < 120000) { // 2 minutes
|
|
||||||
window.__lastLyricsFetchFailure = null;
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
window.__lastLyricsFetchFailure = now;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
store.lyricsInfo = newLyricsInfo;
|
store.lyricsInfo = newLyricsInfo;
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { definePluginSettings } from "@api/Settings";
|
||||||
import { makeRange, SettingSliderComponent } from "@components/PluginSettings/components";
|
import { makeRange, SettingSliderComponent } from "@components/PluginSettings/components";
|
||||||
import { useAwaiter } from "@utils/react";
|
import { useAwaiter } from "@utils/react";
|
||||||
import { OptionType } from "@utils/types";
|
import { OptionType } from "@utils/types";
|
||||||
import { Button, showToast, Text, Toasts } from "@webpack/common";
|
import { Button, showToast, Text, Toasts, useMemo } from "@webpack/common";
|
||||||
|
|
||||||
import { clearLyricsCache, getLyricsCount, removeTranslations } from "./api";
|
import { clearLyricsCache, getLyricsCount, removeTranslations } from "./api";
|
||||||
import { Lyrics } from "./components/lyrics";
|
import { Lyrics } from "./components/lyrics";
|
||||||
|
@ -24,10 +24,13 @@ const sliderOptions = {
|
||||||
function Details() {
|
function Details() {
|
||||||
const { lyricsInfo } = useLyrics();
|
const { lyricsInfo } = useLyrics();
|
||||||
|
|
||||||
const [count, error, loading] = useAwaiter(getLyricsCount, {
|
const [count, error, loading] = useAwaiter(
|
||||||
onError: () => console.error("Failed to get lyrics count"),
|
useMemo(() => getLyricsCount, []),
|
||||||
fallbackValue: null,
|
{
|
||||||
});
|
onError: () => console.error("Failed to get lyrics count"),
|
||||||
|
fallbackValue: null,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue