Skip to content

Commit

Permalink
Merge pull request #6744 from Bnyro/master
Browse files Browse the repository at this point in the history
fix: ignore youtube import entries with missing title url
  • Loading branch information
Bnyro authored Nov 17, 2024
2 parents 96532d6 + 2c463da commit 1ff5453
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
23 changes: 12 additions & 11 deletions app/src/main/java/com/github/libretube/helpers/ImportHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,17 @@ object ImportHelper {
}

ImportFormat.FREETUBE -> {
val playlistFile = activity.contentResolver.openInputStream(uri)?.use { inputStream ->
val text = inputStream.bufferedReader().readText()
runCatching {
text.lines().map { line ->
JsonHelper.json.decodeFromString<FreeTubeImportPlaylist>(line)
}
}.getOrNull() ?: runCatching {
listOf(JsonHelper.json.decodeFromString<FreeTubeImportPlaylist>(text))
}.getOrNull()
}
val playlistFile =
activity.contentResolver.openInputStream(uri)?.use { inputStream ->
val text = inputStream.bufferedReader().readText()
runCatching {
text.lines().map { line ->
JsonHelper.json.decodeFromString<FreeTubeImportPlaylist>(line)
}
}.getOrNull() ?: runCatching {
listOf(JsonHelper.json.decodeFromString<FreeTubeImportPlaylist>(text))
}.getOrNull()
}

val playlists = playlistFile.orEmpty().map { playlist ->
// convert FreeTube videos to list of string
Expand Down Expand Up @@ -287,7 +288,7 @@ object ImportHelper {
JsonHelper.json.decodeFromStream<List<YouTubeWatchHistoryFileItem>>(it)
}
.orEmpty()
.filter { it.activityControls.contains("YouTube watch history") && it.subtitles.isNotEmpty() }
.filter { it.activityControls.contains("YouTube watch history") && it.subtitles.isNotEmpty() && it.titleUrl.isNotEmpty() }
.reversed()
.map {
val videoId = it.titleUrl.substring(it.titleUrl.length - 11)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import kotlinx.serialization.Serializable

@Serializable
data class YouTubeWatchHistoryFileItem(
val header: String,
val time: String,
val title: String,
val titleUrl: String,
val header: String = "",
val time: String = "",
val title: String = "",
val titleUrl: String = "",
val activityControls: List<String> = emptyList(),
val products: List<String> = emptyList(),
val subtitles: List<YouTubeWatchHistoryChannelInfo> = emptyList()
Expand Down

0 comments on commit 1ff5453

Please sign in to comment.