Merge pull request #6846 from Bnyro/master

refactor: simplify ImportHelper#importPlaylists
This commit is contained in:
Bnyro 2024-12-02 21:57:11 +01:00 committed by GitHub
commit 26dd1c3c76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -191,9 +191,7 @@ object ImportHelper {
ImportFormat.YOUTUBECSV -> { ImportFormat.YOUTUBECSV -> {
val playlist = PipedImportPlaylist() val playlist = PipedImportPlaylist()
activity.contentResolver.openInputStream(uri)?.use { inputStream -> activity.contentResolver.openInputStream(uri)?.use { inputStream ->
val lines = inputStream.bufferedReader().use { reader -> val lines = inputStream.bufferedReader().readLines()
reader.lines().collect(Collectors.toList())
}
// invalid playlist file, hence returning // invalid playlist file, hence returning
if (lines.size < 2) return if (lines.size < 2) return
@ -214,12 +212,13 @@ object ImportHelper {
for (line in lines.subList(startIndex, lines.size)) { for (line in lines.subList(startIndex, lines.size)) {
if (line.isBlank()) continue if (line.isBlank()) continue
line.split(",") val videoId = line.split(",")
.firstOrNull() .firstOrNull()
?.takeIf { it.isNotBlank() } ?.takeIf { it.isNotBlank() }
?.let { videoId ->
playlist.videos += videoId.trim() if (videoId != null) {
} playlist.videos += videoId.trim()
}
} }
importPlaylists.add(playlist) importPlaylists.add(playlist)
} }