From 62c6714cafc37e48e3bcba7c28e28112694a320a Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 28 Oct 2024 17:44:05 +0100 Subject: [PATCH] fix: import and export of FreeTube newline format --- .../java/com/github/libretube/helpers/ImportHelper.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/github/libretube/helpers/ImportHelper.kt b/app/src/main/java/com/github/libretube/helpers/ImportHelper.kt index f0453f75d..d6fed20a5 100644 --- a/app/src/main/java/com/github/libretube/helpers/ImportHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/ImportHelper.kt @@ -26,6 +26,7 @@ import com.github.libretube.obj.YouTubeWatchHistoryFileItem import com.github.libretube.ui.dialogs.ShareDialog import com.github.libretube.util.TextUtils import kotlinx.serialization.ExperimentalSerializationApi +import kotlinx.serialization.encodeToString import kotlinx.serialization.json.decodeFromStream import kotlinx.serialization.json.encodeToStream import java.util.stream.Collectors @@ -164,7 +165,9 @@ object ImportHelper { val playlistFile = activity.contentResolver.openInputStream(uri)?.use { inputStream -> val text = inputStream.bufferedReader().readText() runCatching { - JsonHelper.json.decodeFromString>(text) + text.lines().map { line -> + JsonHelper.json.decodeFromString(line) + } }.getOrNull() ?: runCatching { listOf(JsonHelper.json.decodeFromString(text)) }.getOrNull() @@ -263,8 +266,11 @@ object ImportHelper { ImportFormat.FREETUBE -> { val playlists = PlaylistsHelper.exportFreeTubePlaylists() + val freeTubeExportDb = playlists.joinToString("\n") { playlist -> + JsonHelper.json.encodeToString(playlist) + } activity.contentResolver.openOutputStream(uri)?.use { - JsonHelper.json.encodeToStream(playlists, it) + it.write(freeTubeExportDb.toByteArray()) } activity.toastFromMainDispatcher(R.string.exportsuccess) }