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