Filter out invalid TV guide programs (#334)

Filters out TV programs that end before the guide start time. In theory,
the server shouldn't return these, but it seems to for some users.

Related to #276
This commit is contained in:
damontecres 2025-11-28 10:36:12 -05:00 committed by GitHub
parent 10c08c5515
commit babfe011a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -147,11 +147,13 @@ class LiveTvViewModel
minEndDate = minEndDate,
channelIds = channelsToFetch.map { it.id },
sortBy = listOf(ItemSortBy.START_DATE),
userId = serverRepository.currentUser.value?.id,
)
val fetchedPrograms =
api.liveTvApi
.getPrograms(request)
.content.items
.filter { it.endDate?.isAfter(guideStart) == true }
val programsByChannel = mutableMapOf<UUID, List<TvProgram>>()
val fetchedGroupedBy = fetchedPrograms.groupBy { it.channelId }
fetchedGroupedBy.forEach { (channelId, programs) ->
@ -188,7 +190,10 @@ class LiveTvViewModel
subtitle = dto.episodeTitle.takeIf { dto.isSeries ?: false },
seasonEpisode =
if (dto.indexNumber != null && dto.parentIndexNumber != null) {
SeasonEpisode(dto.parentIndexNumber!!, dto.indexNumber!!)
SeasonEpisode(
dto.parentIndexNumber!!,
dto.indexNumber!!,
)
} else {
null
},
@ -216,7 +221,7 @@ class LiveTvViewModel
}
}
listing.add(p)
} else if (index > 0) {
} else if (index > 0 && listing.isNotEmpty()) {
var previous = listing.last()
while (previous.endHours < p.startHours) {
// Fill gaps between programs