Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: import and export of FreeTube newline format #6674

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading