Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix no "try again" on providers that support this, closes #89 #94

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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 {
musixmatchSongInfo = it
} ?: throw NoTrackFoundException()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,10 +41,16 @@ class LRCLibAPI {

val json = json.decodeFromString<List<LRCLibResponse>>(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
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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 artistName = withContext(Dispatchers.IO) {
URLEncoder.encode(
"${query.artistName}",
Expand All @@ -46,7 +46,7 @@ class MusixmatchAPI {
return null

val result = json.decodeFromString<MusixmatchSearchResponse>(responseBody)

return SongInfo(
songName = result.songName,
artistName = result.artistName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ 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 &&
viewModel.userSettingsController.selectedProvider != Providers.MUSIXMATCH
)

is QueryStatus.Failed -> FailedDialogue(
Expand Down
Loading