Skip to content

Commit

Permalink
feat(lyrics): add lrclib as provider closes z-huang#27 closes z-huang#50
Browse files Browse the repository at this point in the history
  • Loading branch information
Malopieds committed Apr 11, 2024
1 parent 14ca8c4 commit 7ccbf3c
Show file tree
Hide file tree
Showing 11 changed files with 324 additions and 162 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ dependencies {

implementation(projects.innertube)
implementation(projects.kugou)
implementation(projects.lrclib)

coreLibraryDesugaring(libs.desugaring)

Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/com/zionhuang/music/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import coil.ImageLoaderFactory
import coil.disk.DiskCache
import com.zionhuang.innertube.YouTube
import com.zionhuang.innertube.models.YouTubeLocale
import com.zionhuang.kugou.KuGou
import com.zionhuang.music.constants.*
import com.zionhuang.music.extensions.*
import com.zionhuang.music.utils.dataStore
Expand Down Expand Up @@ -44,9 +43,6 @@ class App : Application(), ImageLoaderFactory {
?: languageTag.takeIf { it in LanguageCodeToName }
?: "en"
)
if (languageTag == "zh-TW") {
KuGou.useTraditionalChinese = true
}

if (dataStore[ProxyEnabledKey] == true) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.zionhuang.music.lyrics

import android.content.Context
import com.zionhuang.lrclib.LrcLib

object LrcLibLyricsProvider : LyricsProvider {
override val name = "LrcLib"
override fun isEnabled(context: Context) = true

override suspend fun getLyrics(id: String, title: String, artist: String, duration: Int): Result<String> =
LrcLib.getLyrics(title, artist, duration)

override suspend fun getAllLyrics(id: String, title: String, artist: String, duration: Int, callback: (String) -> Unit) {
LrcLib.getAllLyrics(title, artist, duration, null, callback)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import javax.inject.Inject
class LyricsHelper @Inject constructor(
@ApplicationContext private val context: Context,
) {
private val lyricsProviders = listOf(YouTubeSubtitleLyricsProvider, KuGouLyricsProvider, YouTubeLyricsProvider)
private val lyricsProviders = listOf(LrcLibLyricsProvider,KuGouLyricsProvider, YouTubeSubtitleLyricsProvider, YouTubeLyricsProvider)
private val cache = LruCache<String, List<LyricsResult>>(MAX_CACHE_SIZE)

suspend fun getLyrics(mediaMetadata: MediaMetadata): String {
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ hilt = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt
hilt-compiler = { group = "com.google.dagger", name = "hilt-android-compiler", version.ref = "hilt" }

ktor-client-core = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktor" }
ktor_client_cio = { module = "io.ktor:ktor-client-cio", version.ref = "ktor" }
ktor-client-okhttp = { group = "io.ktor", name = "ktor-client-okhttp", version.ref = "ktor" }
ktor-client-content-negotiation = { group = "io.ktor", name = "ktor-client-content-negotiation", version.ref = "ktor" }
ktor-client-encoding = { group = "io.ktor", name = "ktor-client-encoding", version.ref = "ktor" }
Expand Down
Loading

0 comments on commit 7ccbf3c

Please # to comment.