fix: ignore youtube import entries with missing title url

This commit is contained in:
Bnyro 2024-11-17 23:07:00 +01:00
parent f4a8d7b6b1
commit 2c463da52a
2 changed files with 16 additions and 15 deletions

View File

@ -162,16 +162,17 @@ object ImportHelper {
} }
ImportFormat.FREETUBE -> { ImportFormat.FREETUBE -> {
val playlistFile = activity.contentResolver.openInputStream(uri)?.use { inputStream -> val playlistFile =
val text = inputStream.bufferedReader().readText() activity.contentResolver.openInputStream(uri)?.use { inputStream ->
runCatching { val text = inputStream.bufferedReader().readText()
text.lines().map { line -> runCatching {
JsonHelper.json.decodeFromString<FreeTubeImportPlaylist>(line) text.lines().map { line ->
} JsonHelper.json.decodeFromString<FreeTubeImportPlaylist>(line)
}.getOrNull() ?: runCatching { }
listOf(JsonHelper.json.decodeFromString<FreeTubeImportPlaylist>(text)) }.getOrNull() ?: runCatching {
}.getOrNull() listOf(JsonHelper.json.decodeFromString<FreeTubeImportPlaylist>(text))
} }.getOrNull()
}
val playlists = playlistFile.orEmpty().map { playlist -> val playlists = playlistFile.orEmpty().map { playlist ->
// convert FreeTube videos to list of string // convert FreeTube videos to list of string
@ -287,7 +288,7 @@ object ImportHelper {
JsonHelper.json.decodeFromStream<List<YouTubeWatchHistoryFileItem>>(it) JsonHelper.json.decodeFromStream<List<YouTubeWatchHistoryFileItem>>(it)
} }
.orEmpty() .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() .reversed()
.map { .map {
val videoId = it.titleUrl.substring(it.titleUrl.length - 11) val videoId = it.titleUrl.substring(it.titleUrl.length - 11)

View File

@ -4,10 +4,10 @@ import kotlinx.serialization.Serializable
@Serializable @Serializable
data class YouTubeWatchHistoryFileItem( data class YouTubeWatchHistoryFileItem(
val header: String, val header: String = "",
val time: String, val time: String = "",
val title: String, val title: String = "",
val titleUrl: String, val titleUrl: String = "",
val activityControls: List<String> = emptyList(), val activityControls: List<String> = emptyList(),
val products: List<String> = emptyList(), val products: List<String> = emptyList(),
val subtitles: List<YouTubeWatchHistoryChannelInfo> = emptyList() val subtitles: List<YouTubeWatchHistoryChannelInfo> = emptyList()