From ab5e81e51372ff607d66059f4cf6b5fd5f25fab1 Mon Sep 17 00:00:00 2001
From: Lambada10 <62511588+Lambada10@users.noreply.github.com>
Date: Thu, 17 Oct 2024 15:42:09 +0200
Subject: [PATCH 1/2] Fix no "try again" on providers that support this, #89
---
.idea/gradle.xml | 3 ++-
.../lyrics_providers/LyricsProviderService.kt | 6 +++---
.../remote/lyrics_providers/others/LRCLibAPI.kt | 14 ++++++++++----
.../lyrics_providers/others/MusixmatchAPI.kt | 8 ++++++--
.../ui/screens/lyricsFetch/LyricsFetchScreen.kt | 3 +--
5 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index 194f297..ecd50f0 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -4,6 +4,7 @@
-
+
\ No newline at end of file
diff --git a/app/src/main/java/pl/lambada/songsync/data/remote/lyrics_providers/LyricsProviderService.kt b/app/src/main/java/pl/lambada/songsync/data/remote/lyrics_providers/LyricsProviderService.kt
index b915d81..fb02bbe 100644
--- a/app/src/main/java/pl/lambada/songsync/data/remote/lyrics_providers/LyricsProviderService.kt
+++ b/app/src/main/java/pl/lambada/songsync/data/remote/lyrics_providers/LyricsProviderService.kt
@@ -52,11 +52,11 @@ class LyricsProviderService {
UnknownHostException::class, FileNotFoundException::class, NoTrackFoundException::class,
EmptyQueryException::class, InternalErrorException::class
)
- suspend fun getSongInfo(query: SongInfo, offset: Int? = 0, provider: Providers): SongInfo? {
+ suspend fun getSongInfo(query: SongInfo, offset: Int = 0, provider: Providers): SongInfo? {
return try {
when (provider) {
Providers.SPOTIFY -> spotifyAPI.getSongInfo(query, offset)
- Providers.LRCLIB -> LRCLibAPI().getSongInfo(query).also {
+ Providers.LRCLIB -> LRCLibAPI().getSongInfo(query, offset).also {
lrcLibID = it?.lrcLibID ?: 0
} ?: throw NoTrackFoundException()
@@ -68,7 +68,7 @@ class LyricsProviderService {
appleID = it?.appleID ?: 0
} ?: throw NoTrackFoundException()
- Providers.MUSIXMATCH -> MusixmatchAPI().getSongInfo(query).also {
+ Providers.MUSIXMATCH -> MusixmatchAPI().getSongInfo(query, offset).also {
musixmatchID = it?.musixmatchID ?: 0
} ?: throw NoTrackFoundException()
}
diff --git a/app/src/main/java/pl/lambada/songsync/data/remote/lyrics_providers/others/LRCLibAPI.kt b/app/src/main/java/pl/lambada/songsync/data/remote/lyrics_providers/others/LRCLibAPI.kt
index 43a4a9e..f09c355 100644
--- a/app/src/main/java/pl/lambada/songsync/data/remote/lyrics_providers/others/LRCLibAPI.kt
+++ b/app/src/main/java/pl/lambada/songsync/data/remote/lyrics_providers/others/LRCLibAPI.kt
@@ -20,7 +20,7 @@ class LRCLibAPI {
* @param query The SongInfo object with songName and artistName fields filled.
* @return Search result as a SongInfo object.
*/
- suspend fun getSongInfo(query: SongInfo): SongInfo? {
+ suspend fun getSongInfo(query: SongInfo, offset: Int = 0): SongInfo? {
val search = withContext(Dispatchers.IO) {
URLEncoder.encode(
"${query.songName}", // it doesn't work with artist name and song name together
@@ -41,10 +41,16 @@ class LRCLibAPI {
val json = json.decodeFromString>(responseBody)
+ val song = try {
+ json[offset]
+ } catch (e: IndexOutOfBoundsException) {
+ return null
+ }
+
return SongInfo(
- songName = json[0].trackName,
- artistName = json[0].artistName,
- lrcLibID = json[0].id
+ songName = song.trackName,
+ artistName = song.artistName,
+ lrcLibID = song.id
)
}
diff --git a/app/src/main/java/pl/lambada/songsync/data/remote/lyrics_providers/others/MusixmatchAPI.kt b/app/src/main/java/pl/lambada/songsync/data/remote/lyrics_providers/others/MusixmatchAPI.kt
index be0fa9e..6de0b1f 100644
--- a/app/src/main/java/pl/lambada/songsync/data/remote/lyrics_providers/others/MusixmatchAPI.kt
+++ b/app/src/main/java/pl/lambada/songsync/data/remote/lyrics_providers/others/MusixmatchAPI.kt
@@ -20,7 +20,7 @@ class MusixmatchAPI {
* @param query The SongInfo object with songName and artistName fields filled.
* @return Search result as a SongInfo object.
*/
- suspend fun getSongInfo(query: SongInfo): SongInfo? {
+ suspend fun getSongInfo(query: SongInfo, offset: Int = 0): SongInfo? {
val search = withContext(Dispatchers.IO) {
URLEncoder.encode(
"${query.songName} ${query.artistName}",
@@ -41,7 +41,11 @@ class MusixmatchAPI {
val json = json.decodeFromString>(responseBody)
- val result = json[0]
+ val result = try {
+ json[offset]
+ } catch (e: IndexOutOfBoundsException) {
+ return null
+ }
return SongInfo(
songName = result.songName,
diff --git a/app/src/main/java/pl/lambada/songsync/ui/screens/lyricsFetch/LyricsFetchScreen.kt b/app/src/main/java/pl/lambada/songsync/ui/screens/lyricsFetch/LyricsFetchScreen.kt
index 59b3ba9..a455546 100644
--- a/app/src/main/java/pl/lambada/songsync/ui/screens/lyricsFetch/LyricsFetchScreen.kt
+++ b/app/src/main/java/pl/lambada/songsync/ui/screens/lyricsFetch/LyricsFetchScreen.kt
@@ -175,8 +175,7 @@ fun SharedTransitionScope.LyricsFetchScreen(
lyricsFetchState = viewModel.lyricsFetchState,
animatedVisibilityScope = animatedVisibilityScope,
disableMarquee = viewModel.userSettingsController.disableMarquee,
- allowTryingAgain = viewModel.userSettingsController.selectedProvider != Providers.LRCLIB
- && viewModel.userSettingsController.selectedProvider != Providers.APPLE
+ allowTryingAgain = viewModel.userSettingsController.selectedProvider != Providers.APPLE
)
is QueryStatus.Failed -> FailedDialogue(
From 6116e6c9d4cb030eb959911bf9838524a4d5ba15 Mon Sep 17 00:00:00 2001
From: Lambada10 <62511588+Lambada10@users.noreply.github.com>
Date: Thu, 24 Oct 2024 11:41:06 +0200
Subject: [PATCH 2/2] Musixmatch provider no longer supports retry
---
.../data/remote/lyrics_providers/others/MusixmatchAPI.kt | 8 +-------
.../songsync/ui/screens/lyricsFetch/LyricsFetchScreen.kt | 4 +++-
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/app/src/main/java/pl/lambada/songsync/data/remote/lyrics_providers/others/MusixmatchAPI.kt b/app/src/main/java/pl/lambada/songsync/data/remote/lyrics_providers/others/MusixmatchAPI.kt
index ffb4e4f..57c5159 100644
--- a/app/src/main/java/pl/lambada/songsync/data/remote/lyrics_providers/others/MusixmatchAPI.kt
+++ b/app/src/main/java/pl/lambada/songsync/data/remote/lyrics_providers/others/MusixmatchAPI.kt
@@ -45,13 +45,7 @@ class MusixmatchAPI {
if (response.status.value !in 200..299)
return null
- val json = json.decodeFromString(responseBody)
-
- val result = try {
- json[offset]
- } catch (e: IndexOutOfBoundsException) {
- return null
- }
+ val result = json.decodeFromString(responseBody)
return SongInfo(
songName = result.songName,
diff --git a/app/src/main/java/pl/lambada/songsync/ui/screens/lyricsFetch/LyricsFetchScreen.kt b/app/src/main/java/pl/lambada/songsync/ui/screens/lyricsFetch/LyricsFetchScreen.kt
index a455546..57dd6f7 100644
--- a/app/src/main/java/pl/lambada/songsync/ui/screens/lyricsFetch/LyricsFetchScreen.kt
+++ b/app/src/main/java/pl/lambada/songsync/ui/screens/lyricsFetch/LyricsFetchScreen.kt
@@ -175,7 +175,9 @@ fun SharedTransitionScope.LyricsFetchScreen(
lyricsFetchState = viewModel.lyricsFetchState,
animatedVisibilityScope = animatedVisibilityScope,
disableMarquee = viewModel.userSettingsController.disableMarquee,
- allowTryingAgain = viewModel.userSettingsController.selectedProvider != Providers.APPLE
+ allowTryingAgain =
+ viewModel.userSettingsController.selectedProvider != Providers.APPLE &&
+ viewModel.userSettingsController.selectedProvider != Providers.MUSIXMATCH
)
is QueryStatus.Failed -> FailedDialogue(