From 06b96d0047f6526452917d5d324c69d06cd24535 Mon Sep 17 00:00:00 2001 From: kerollosy Date: Sat, 30 Nov 2024 20:24:25 +0200 Subject: [PATCH 1/2] Fix: Ensure Lyrics Are Embedded During Batch Download When Selected --- .../pl/lambada/songsync/util/LyricsUtils.kt | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/pl/lambada/songsync/util/LyricsUtils.kt b/app/src/main/java/pl/lambada/songsync/util/LyricsUtils.kt index 160b0a0..ca98d9c 100644 --- a/app/src/main/java/pl/lambada/songsync/util/LyricsUtils.kt +++ b/app/src/main/java/pl/lambada/songsync/util/LyricsUtils.kt @@ -251,20 +251,44 @@ 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 formatLyrics( + songInfo: SongInfo, + lyrics: String, + context: Context, + directOffset: Boolean +): String { + val lrcContent = generateLrcContent( + songInfo, + lyrics, + context.getString(R.string.generated_using), + directOffset = directOffset + ) + + return lrcContent +} + private fun formatAndSaveLyricsForSong( song: Song, context: Context, From de748b3118bcb24fedc09e3f382e9a104f0fecf9 Mon Sep 17 00:00:00 2001 From: kerollosy Date: Sat, 30 Nov 2024 21:52:36 +0200 Subject: [PATCH 2/2] Refactor: Remove unused formatAndSaveLyricsForSong function --- .../pl/lambada/songsync/util/LyricsUtils.kt | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/app/src/main/java/pl/lambada/songsync/util/LyricsUtils.kt b/app/src/main/java/pl/lambada/songsync/util/LyricsUtils.kt index ca98d9c..cbe5d67 100644 --- a/app/src/main/java/pl/lambada/songsync/util/LyricsUtils.kt +++ b/app/src/main/java/pl/lambada/songsync/util/LyricsUtils.kt @@ -289,26 +289,6 @@ private fun formatLyrics( return lrcContent } -private fun formatAndSaveLyricsForSong( - song: Song, - context: Context, - sdCardPath: String?, - songInfo: SongInfo, - lyrics: String, - directOffset: Boolean -) { - val targetFile = song.filePath.toLrcFile() - - val lrcContent = generateLrcContent( - songInfo, - lyrics, - context.getString(R.string.generated_using), - directOffset = directOffset - ) - - writeLyricsToFile(targetFile, lrcContent, context, song, sdCardPath) -} - fun saveToExternalPath( context: Context, sourceFilePath: String?,