fix: catch NullPointerException in BaseItemDto to FindroidEpisode conversion

This error is caused by the seriesId or seasonId being null. Hide these episodes for now.

Closes #357
Closes #360
This commit is contained in:
Jarne Demeulemeester 2023-05-14 18:39:35 +02:00
parent fd33d52bba
commit 1c117d3c66
No known key found for this signature in database
GPG key ID: 1E5C6AFBD622E9F5
2 changed files with 30 additions and 26 deletions

View file

@ -35,34 +35,38 @@ data class FindroidEpisode(
suspend fun BaseItemDto.toFindroidEpisode(
jellyfinRepository: JellyfinRepository,
database: ServerDatabaseDao? = null
): FindroidEpisode {
): FindroidEpisode? {
val sources = mutableListOf<FindroidSource>()
sources.addAll(mediaSources?.map { it.toFindroidSource(jellyfinRepository, id) } ?: emptyList())
if (database != null) {
sources.addAll(database.getSources(id).map { it.toFindroidSource(database) })
}
return FindroidEpisode(
id = id,
name = name.orEmpty(),
originalTitle = originalTitle,
overview = overview.orEmpty(),
indexNumber = indexNumber ?: 0,
indexNumberEnd = indexNumberEnd,
parentIndexNumber = parentIndexNumber ?: 0,
sources = sources,
played = userData?.played ?: false,
favorite = userData?.isFavorite ?: false,
canPlay = playAccess != PlayAccess.NONE,
canDownload = canDownload ?: false,
runtimeTicks = runTimeTicks ?: 0,
playbackPositionTicks = userData?.playbackPositionTicks ?: 0L,
premiereDate = premiereDate,
seriesName = seriesName.orEmpty(),
seriesId = seriesId!!,
seasonId = seasonId!!,
communityRating = communityRating,
missing = locationType == LocationType.VIRTUAL,
)
return try {
FindroidEpisode(
id = id,
name = name.orEmpty(),
originalTitle = originalTitle,
overview = overview.orEmpty(),
indexNumber = indexNumber ?: 0,
indexNumberEnd = indexNumberEnd,
parentIndexNumber = parentIndexNumber ?: 0,
sources = sources,
played = userData?.played ?: false,
favorite = userData?.isFavorite ?: false,
canPlay = playAccess != PlayAccess.NONE,
canDownload = canDownload ?: false,
runtimeTicks = runTimeTicks ?: 0,
playbackPositionTicks = userData?.playbackPositionTicks ?: 0L,
premiereDate = premiereDate,
seriesName = seriesName.orEmpty(),
seriesId = seriesId!!,
seasonId = seasonId!!,
communityRating = communityRating,
missing = locationType == LocationType.VIRTUAL,
)
} catch (_: NullPointerException) {
null
}
}
fun FindroidEpisodeDto.toFindroidEpisode(database: ServerDatabaseDao, userId: UUID): FindroidEpisode {

View file

@ -74,7 +74,7 @@ class JellyfinRepositoryImpl(
jellyfinApi.userLibraryApi.getItem(
jellyfinApi.userId!!,
itemId
).content.toFindroidEpisode(this@JellyfinRepositoryImpl, database)
).content.toFindroidEpisode(this@JellyfinRepositoryImpl, database)!!
}
override suspend fun getMovie(itemId: UUID): FindroidMovie =
@ -254,7 +254,7 @@ class JellyfinRepositoryImpl(
seriesId = seriesId?.toString(),
).content.items
.orEmpty()
.map { it.toFindroidEpisode(this@JellyfinRepositoryImpl) }
.mapNotNull { it.toFindroidEpisode(this@JellyfinRepositoryImpl) }
}
override suspend fun getEpisodes(
@ -276,7 +276,7 @@ class JellyfinRepositoryImpl(
limit = limit,
).content.items
.orEmpty()
.map { it.toFindroidEpisode(this@JellyfinRepositoryImpl, database) }
.mapNotNull { it.toFindroidEpisode(this@JellyfinRepositoryImpl, database) }
} else {
database.getEpisodesBySeasonId(seasonId).map { it.toFindroidEpisode(database, jellyfinApi.userId!!) }
}