Set duration tolerance when searching synchronized lyrics
This commit is contained in:
parent
eb562b9d7f
commit
7bc919ce89
1 changed files with 13 additions and 4 deletions
|
@ -53,15 +53,24 @@ object KuGou {
|
|||
suspend fun lyrics(artist: String, title: String, duration: Long): Result<Lyrics?>? {
|
||||
return runCatching {
|
||||
val keyword = keyword(artist, title)
|
||||
val infoByKeyword = searchSong(keyword)
|
||||
|
||||
for (info in searchSong(keyword)) {
|
||||
if (info.duration >= duration - 2 && info.duration <= duration + 2) {
|
||||
if (infoByKeyword.isNotEmpty()) {
|
||||
var tolerance = 0
|
||||
|
||||
while (tolerance <= 5) {
|
||||
for (info in infoByKeyword) {
|
||||
if (info.duration >= duration - tolerance && info.duration <= duration + tolerance) {
|
||||
searchLyricsByHash(info.hash).firstOrNull()?.let { candidate ->
|
||||
return@runCatching downloadLyrics(candidate.id, candidate.accessKey).normalize()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tolerance++
|
||||
}
|
||||
}
|
||||
|
||||
searchLyricsByKeyword(keyword).firstOrNull()?.let { candidate ->
|
||||
return@runCatching downloadLyrics(candidate.id, candidate.accessKey).normalize()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue