Skip to content

Commit

Permalink
Merge pull request #116 from kerollosy/musixmatch
Browse files Browse the repository at this point in the history
Fix: Ensure Lyrics Are Embedded During Batch Download When Selected
  • Loading branch information
Lambada10 authored Dec 9, 2024
2 parents 99785b8 + de748b3 commit 56d497d
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions app/src/main/java/pl/lambada/songsync/util/LyricsUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -251,38 +251,42 @@ private suspend fun downloadLyricsForSong(
}
.onFailure(onFailedLyricsResponse)
.onSuccess {
formatAndSaveLyricsForSong(
song,
context,
viewModel.userSettingsController.sdCardPath,
val lrcContent = formatLyrics(
songInfo,
it,
context,
viewModel.userSettingsController.directlyModifyTimestamps
)

if(viewModel.userSettingsController.embedLyricsIntoFiles) {
embedLyricsInFile(
context,
song.filePath ?: throw NullPointerException("File path is null"),
lrcContent
)
} else {
writeLyricsToFile(song.filePath.toLrcFile(), lrcContent, context, song,viewModel.userSettingsController.sdCardPath)
}

onLyricsSaved()
}
}
}

private fun formatAndSaveLyricsForSong(
song: Song,
context: Context,
sdCardPath: String?,
private fun formatLyrics(
songInfo: SongInfo,
lyrics: String,
context: Context,
directOffset: Boolean
) {
val targetFile = song.filePath.toLrcFile()

): String {
val lrcContent = generateLrcContent(
songInfo,
lyrics,
context.getString(R.string.generated_using),
directOffset = directOffset
)

writeLyricsToFile(targetFile, lrcContent, context, song, sdCardPath)
return lrcContent
}

fun saveToExternalPath(
Expand Down

0 comments on commit 56d497d

Please sign in to comment.