mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-12-13 10:27:31 +00:00
Added fallback for AZLyrics
Now, it will fetch lyrics from genius.com if they're not found on AZLyrics.
This commit is contained in:
parent
40dae56fd9
commit
faa4af01a9
@ -33,11 +33,13 @@ class PlainLyrics extends HookConsumerWidget {
|
|||||||
final lyricsQuery =
|
final lyricsQuery =
|
||||||
useQueries.lyrics.spotifySynced(ref, playlist.activeTrack);
|
useQueries.lyrics.spotifySynced(ref, playlist.activeTrack);
|
||||||
final azLyricsQuery = useQueries.lyrics.azLyrics(playlist.activeTrack);
|
final azLyricsQuery = useQueries.lyrics.azLyrics(playlist.activeTrack);
|
||||||
|
final geniusLyricsQuery =
|
||||||
|
useQueries.lyrics.geniusLyrics(playlist.activeTrack);
|
||||||
final mediaQuery = MediaQuery.of(context);
|
final mediaQuery = MediaQuery.of(context);
|
||||||
final textTheme = Theme.of(context).textTheme;
|
final textTheme = Theme.of(context).textTheme;
|
||||||
|
|
||||||
final textZoomLevel = useState<int>(defaultTextZoom);
|
final textZoomLevel = useState<int>(defaultTextZoom);
|
||||||
bool useAZLyrics = false;
|
bool useAZLyrics = false, useGenius = false;
|
||||||
|
|
||||||
return Stack(
|
return Stack(
|
||||||
children: [
|
children: [
|
||||||
@ -78,9 +80,13 @@ class PlainLyrics extends HookConsumerWidget {
|
|||||||
return const ShimmerLyrics();
|
return const ShimmerLyrics();
|
||||||
} else if (lyricsQuery.hasError) {
|
} else if (lyricsQuery.hasError) {
|
||||||
if (azLyricsQuery.isLoading ||
|
if (azLyricsQuery.isLoading ||
|
||||||
azLyricsQuery.isRefreshing) {
|
azLyricsQuery.isRefreshing ||
|
||||||
|
geniusLyricsQuery.isLoading ||
|
||||||
|
geniusLyricsQuery.isRefreshing) {
|
||||||
return const ShimmerLyrics();
|
return const ShimmerLyrics();
|
||||||
} else if (azLyricsQuery.hasError) {
|
}
|
||||||
|
if (azLyricsQuery.hasError &&
|
||||||
|
geniusLyricsQuery.hasError) {
|
||||||
return Container(
|
return Container(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
@ -99,15 +105,24 @@ class PlainLyrics extends HookConsumerWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
} else if (azLyricsQuery.hasError) {
|
||||||
|
useGenius = true;
|
||||||
|
} else if (geniusLyricsQuery.hasError) {
|
||||||
|
useAZLyrics = true;
|
||||||
} else {
|
} else {
|
||||||
useAZLyrics = true;
|
useAZLyrics = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final lyrics = !useAZLyrics
|
String? lyrics;
|
||||||
? lyricsQuery.data?.lyrics.mapIndexed((i, e) {
|
if (useAZLyrics) {
|
||||||
final next = lyricsQuery.data?.lyrics
|
lyrics = azLyricsQuery.data;
|
||||||
.elementAtOrNull(i + 1);
|
} else if (useGenius) {
|
||||||
|
lyrics = geniusLyricsQuery.data;
|
||||||
|
} else {
|
||||||
|
lyrics = lyricsQuery.data?.lyrics.mapIndexed((i, e) {
|
||||||
|
final next =
|
||||||
|
lyricsQuery.data?.lyrics.elementAtOrNull(i + 1);
|
||||||
if (next != null &&
|
if (next != null &&
|
||||||
e.time - next.time >
|
e.time - next.time >
|
||||||
const Duration(milliseconds: 700)) {
|
const Duration(milliseconds: 700)) {
|
||||||
@ -115,8 +130,8 @@ class PlainLyrics extends HookConsumerWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return e.text;
|
return e.text;
|
||||||
}).join("\n")
|
}).join("\n");
|
||||||
: azLyricsQuery.data;
|
}
|
||||||
|
|
||||||
return AnimatedDefaultTextStyle(
|
return AnimatedDefaultTextStyle(
|
||||||
duration: const Duration(milliseconds: 200),
|
duration: const Duration(milliseconds: 200),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user