Skip to content

Commit 1ff5453

Browse files
authored
Merge pull request #6744 from Bnyro/master
fix: ignore youtube import entries with missing title url
2 parents 96532d6 + 2c463da commit 1ff5453

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

app/src/main/java/com/github/libretube/helpers/ImportHelper.kt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,17 @@ object ImportHelper {
162162
}
163163

164164
ImportFormat.FREETUBE -> {
165-
val playlistFile = activity.contentResolver.openInputStream(uri)?.use { inputStream ->
166-
val text = inputStream.bufferedReader().readText()
167-
runCatching {
168-
text.lines().map { line ->
169-
JsonHelper.json.decodeFromString<FreeTubeImportPlaylist>(line)
170-
}
171-
}.getOrNull() ?: runCatching {
172-
listOf(JsonHelper.json.decodeFromString<FreeTubeImportPlaylist>(text))
173-
}.getOrNull()
174-
}
165+
val playlistFile =
166+
activity.contentResolver.openInputStream(uri)?.use { inputStream ->
167+
val text = inputStream.bufferedReader().readText()
168+
runCatching {
169+
text.lines().map { line ->
170+
JsonHelper.json.decodeFromString<FreeTubeImportPlaylist>(line)
171+
}
172+
}.getOrNull() ?: runCatching {
173+
listOf(JsonHelper.json.decodeFromString<FreeTubeImportPlaylist>(text))
174+
}.getOrNull()
175+
}
175176

176177
val playlists = playlistFile.orEmpty().map { playlist ->
177178
// convert FreeTube videos to list of string
@@ -287,7 +288,7 @@ object ImportHelper {
287288
JsonHelper.json.decodeFromStream<List<YouTubeWatchHistoryFileItem>>(it)
288289
}
289290
.orEmpty()
290-
.filter { it.activityControls.contains("YouTube watch history") && it.subtitles.isNotEmpty() }
291+
.filter { it.activityControls.contains("YouTube watch history") && it.subtitles.isNotEmpty() && it.titleUrl.isNotEmpty() }
291292
.reversed()
292293
.map {
293294
val videoId = it.titleUrl.substring(it.titleUrl.length - 11)

app/src/main/java/com/github/libretube/obj/YouTubeWatchHistoryFileItem.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import kotlinx.serialization.Serializable
44

55
@Serializable
66
data class YouTubeWatchHistoryFileItem(
7-
val header: String,
8-
val time: String,
9-
val title: String,
10-
val titleUrl: String,
7+
val header: String = "",
8+
val time: String = "",
9+
val title: String = "",
10+
val titleUrl: String = "",
1111
val activityControls: List<String> = emptyList(),
1212
val products: List<String> = emptyList(),
1313
val subtitles: List<YouTubeWatchHistoryChannelInfo> = emptyList()

0 commit comments

Comments
 (0)