Skip to content

Commit

Permalink
Merge pull request #6674 from Bnyro/master
Browse files Browse the repository at this point in the history
fix: import and export of FreeTube newline format
  • Loading branch information
Bnyro authored Oct 28, 2024
2 parents 6fda5ef + 62c6714 commit a1cd869
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/src/main/java/com/github/libretube/helpers/ImportHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -164,7 +165,9 @@ object ImportHelper {
val playlistFile = activity.contentResolver.openInputStream(uri)?.use { inputStream ->
val text = inputStream.bufferedReader().readText()
runCatching {
JsonHelper.json.decodeFromString<List<FreeTubeImportPlaylist>>(text)
text.lines().map { line ->
JsonHelper.json.decodeFromString<FreeTubeImportPlaylist>(line)
}
}.getOrNull() ?: runCatching {
listOf(JsonHelper.json.decodeFromString<FreeTubeImportPlaylist>(text))
}.getOrNull()
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit a1cd869

Please sign in to comment.