Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e8f905a
feat(settings): hide spoilers for unwatched episodes, per profile
Quick104 Sep 30, 2026
3a7b017
fix(settings): reload spoiler settings when the server or profile cha…
Quick104 Sep 30, 2026
838035a
fix(settings): preserve episode spoiler protection across updates
Quick104 Sep 30, 2026
5ea9a58
fix(tv): refresh marquee spoilers after watch updates
Quick104 Sep 30, 2026
9431eab
fix(spoilers): preserve series artwork with v2 provenance
Quick104 Sep 30, 2026
968c82c
fix(settings): require revision 16 for spoiler keys
Quick104 Sep 30, 2026
fa98b14
chore: update episode spoiler branch from main
Quick104 Sep 30, 2026
155eccc
fix(downloads): protect unwatched episode artwork
Quick104 Oct 1, 2026
668e887
fix(tv): publish safe artwork for protected Watch Next episodes
Quick104 Oct 1, 2026
c7f547b
fix(downloads): refresh episode watch state before artwork projection
Quick104 Oct 1, 2026
5f52d52
fix(tv): preserve Watch Next tiles on ordinary startup
Quick104 Oct 1, 2026
96b7f70
fix: track watch and playback mutations separately
Quick104 Oct 1, 2026
4aa9c61
fix: protect episode artwork in catalog grids
Quick104 Oct 1, 2026
e559c5f
fix: clear catalog progress on unwatched resets
Quick104 Oct 1, 2026
07c384d
fix(settings): treat spoiler keys the server refuses as unsupported
Quick104 Oct 10, 2026
353ac27
fix(downloads): read episode watch state only for image protection
Quick104 Oct 10, 2026
63258b0
fix(tv): keep Watch Next safe through failed lookups and interrupted …
Quick104 Oct 10, 2026
6158463
fix: keep resume guards for rows written before positionUpdatedAtMs
Quick104 Oct 10, 2026
e6446f5
fix(mobile): reset episode progress when marking it watched or unwatched
Quick104 Oct 10, 2026
eae8f4f
fix(tv): rebuild the hero backdrop when the item's watch state changes
Quick104 Oct 10, 2026
590f092
Merge main into feat/episode-spoiler-protection
Quick104 Oct 10, 2026
84a95de
chore(settings): gate spoiler settings on contract revision 17
Quick104 Oct 10, 2026
efb5a0a
fix(player): keep shuffled movie overviews visible with spoiler prote…
Quick104 Oct 10, 2026
9478b55
fix(spoilers): honor artwork provenance and close review races
Quick104 Oct 10, 2026
4b6a4e7
fix(detail): undo a failed watched toggle even after new progress
Quick104 Oct 10, 2026
8b4a118
fix(settings): pin spoiler writes to the profile that made them
Quick104 Oct 10, 2026
a68c70c
fix(settings): pin the spoiler value read to the captured profile
Quick104 Oct 10, 2026
5ab98ba
fix(watch-party): apply spoiler protection to party previews
Quick104 Oct 10, 2026
e1a4b8c
fix(watch-party): keep protected stills hidden while artwork changes
Quick104 Oct 10, 2026
002cfa6
fix(watch-party): hide the current backdrop at once when protection t…
Quick104 Oct 10, 2026
c57fcc8
fix(spoilers): close three remaining protection gaps
Quick104 Oct 10, 2026
b8e4677
fix(spoilers): keep cast identities off the launcher and report faile…
Quick104 Oct 10, 2026
4d8eaa7
fix(tv): apply a protection change to departing marquee layers
Quick104 Oct 10, 2026
994c31b
fix(tv): keep safe enriched artwork when protecting departing layers
Quick104 Oct 10, 2026
01bb7fd
fix(tv): fence Watch Next writes and picker spoilers to this profile
Quick104 Oct 10, 2026
917bf61
fix(tv): use this profile's watch state for poster cards too
Quick104 Oct 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,024 changes: 1,024 additions & 0 deletions android-shared/schemas/org.siloserver.silo.common.data.db.SiloDatabase/15.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.siloserver.silo.common.cards

import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.ProvidableCompositionLocal
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.staticCompositionLocalOf
import org.siloserver.silo.common.settings.EpisodeSpoilerStore
import org.siloserver.silo.model.settings.EpisodeSpoilerPrefs

/**
* The profile's spoiler protection for unwatched episodes, published once
* near each app shell. Surfaces pair it with
* [org.siloserver.silo.model.settings.EpisodeSpoilers.isUnwatched] to decide
* per episode. Outside a [ProvideEpisodeSpoilerPrefs] scope nothing is hidden.
*/
val LocalEpisodeSpoilerPrefs: ProvidableCompositionLocal<EpisodeSpoilerPrefs> =
staticCompositionLocalOf { EpisodeSpoilerPrefs.NONE }

/**
* Hydrates the [store] for [sessionKey] (the active profile id) and publishes
* its resolved prefs via [LocalEpisodeSpoilerPrefs]. Keyed on the session for
* the same reason as [ProvideCardPresentation]: the provider is first
* composed on the unauthenticated Login screen.
*/
@Composable
fun ProvideEpisodeSpoilerPrefs(
store: EpisodeSpoilerStore,
sessionKey: Any? = null,
content: @Composable () -> Unit,
) {
LaunchedEffect(store, sessionKey) {
if (sessionKey != null) store.hydrateIfNeeded()
}
val state by store.state.collectAsState()
CompositionLocalProvider(LocalEpisodeSpoilerPrefs provides state.prefs, content = content)
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import org.siloserver.silo.common.data.db.entity.UserItemStateEntity
MembershipProjectionEntity::class,
LegacyMembershipQuarantineEntity::class,
],
version = 14,
version = 15,
exportSchema = true,
autoMigrations = [
AutoMigration(from = 1, to = 2),
Expand All @@ -71,6 +71,7 @@ import org.siloserver.silo.common.data.db.entity.UserItemStateEntity
AutoMigration(from = 11, to = 12),
AutoMigration(from = 12, to = 13),
AutoMigration(from = 13, to = 14),
AutoMigration(from = 14, to = 15),
],
)
abstract class SiloDatabase : RoomDatabase() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface ContentItemStateDao {

// Revert a single optimistic field to "unknown" after its outbox op is dropped
// (terminal server rejection) — the overlay then defers to server state.
@Query("UPDATE content_item_state SET watched = NULL WHERE serverId = :serverId AND profileId = :profileId AND contentId = :contentId")
@Query("UPDATE content_item_state SET watched = NULL, watchedUpdatedAtMs = NULL WHERE serverId = :serverId AND profileId = :profileId AND contentId = :contentId")
suspend fun clearWatched(serverId: String, profileId: String, contentId: String)

@Query("UPDATE content_item_state SET favorite = NULL WHERE serverId = :serverId AND profileId = :profileId AND contentId = :contentId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ interface DirtyOperationDao {
"AND targetContentId = :contentId AND opKind IN ('SET_WATCHED', 'SET_RATING', 'SET_POSITION', 'PERSONAL_V2')")
suspend fun unresolvedPersonalCount(serverId: String, profileId: String, contentId: String): Int

@Query("SELECT contentId FROM content_item_state WHERE serverId = :serverId AND profileId = :profileId " +
"AND contentId IN (:contentIds) AND watchedUpdatedAtMs >= :sinceMs " +
"UNION SELECT contentId FROM user_item_state WHERE serverId = :serverId AND profileId = :profileId " +
"AND contentId IN (:contentIds) AND positionUpdatedAtMs >= :sinceMs " +
"UNION SELECT targetContentId FROM dirty_operations WHERE serverId = :serverId AND profileId = :profileId " +
"AND targetContentId IN (:contentIds) AND opKind IN ('SET_WATCHED', 'SET_POSITION')")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kody code-review Kody Rules high

Reconciliation can overwrite pending local watched or playback intent because the unresolved-operation query excludes PERSONAL_V2, although the DAO already recognizes those rows as unresolved personal writes; a write admitted before sinceMs can miss both timestamp branches and the outbox branch. Include PERSONAL_V2 in the unresolved-operation branch to preserve the item's local state until its write resolves.

Kody rule violation: Use genuinely fresh reconciliation reads without overwriting newer local intent

Prompt for LLM

File android-shared/src/androidMain/kotlin/org/siloserver/silo/common/data/db/dao/DirtyOperationDao.kt:

Line 33:

Reconciliation can overwrite pending local watched or playback intent because the unresolved-operation query excludes PERSONAL_V2, although the DAO already recognizes those rows as unresolved personal writes; a write admitted before sinceMs can miss both timestamp branches and the outbox branch. Include PERSONAL_V2 in the unresolved-operation branch to preserve the item's local state until its write resolves.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this. A PERSONAL_V2 row in personal_uncertain projects nothing into Room until the server acknowledges it. completePersonalWrite then writes watchedUpdatedAtMs = now() and clears progress at that time, so an acknowledgement after the snapshot started falls in the watchedUpdatedAtMs >= :sinceMs branch. While the write is still in flight, Room holds only the pre-write state, so preferring it over the snapshot would show older data. PERSONAL_V2 also covers ratings, which must not mask the server's watch state (ratingsAndTrackChangesDoNotPromoteStaleWatchState).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed—the suggestion conflated an unresolved write with local watch state already projected into Room.

Under the behavior you described:

  • An in-flight PERSONAL_V2 write in personal_uncertain leaves Room holding pre-write state. Protecting that state from reconciliation could preserve stale data.
  • When the write is acknowledged after the snapshot starts, completePersonalWrite stamps watchedUpdatedAtMs, so the existing timestamp branch protects the acknowledged watched/progress reset.
  • Including all PERSONAL_V2 operations would also let rating-only writes incorrectly shield stale watch state, contrary to ratingsAndTrackChangesDoNotPromoteStaleWatchState.

I withdraw the recommendation to add PERSONAL_V2 to this query. The unresolved-operation branch should protect pending projected watch/progress state—not every unresolved personal operation. No code change is warranted for the concern I raised.

Comment on lines +32 to +33

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include pending v2 watched intents in download protection

When a user marks a downloaded episode unwatched from Home or a catalog card and opens Downloads before that request settles, the current personal-write path inserts a PERSONAL_V2 row and deliberately leaves content_item_state and resume progress unchanged until the server acknowledges it. This query recognizes only legacy SET_WATCHED/SET_POSITION rows, so DownloadsViewModel accepts a concurrent server read that can still say played=true and renders the saved still sharply. Fresh evidence after the earlier download-state fix is that its pending-write detector does not cover the beginPersonalWrite path used by these UI actions; expose the pending v2 desired watched value and its progress reset to Downloads until the write succeeds or rolls back.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this. The fix would show a pending write's desired value before the server confirms it, which the personal-write model rules out on purpose. beginPersonalWrite records a personal_uncertain row and changes nothing local, so an unknown or rejected write never persists a false success after the UI rolls back (completePersonalWrite). Overlaying the row's desired value in localContentStates would also change Home, Browse, and Libraries, which read the same port.

While the write is in flight, the pre-write state is still the confirmed one. Once it's acknowledged, completePersonalWrite stamps watchedUpdatedAtMs and clears progress, the timestamp branch prefers that over the older server snapshot, and Downloads shows it on its next refresh (entry, resume, or a record change). Home and Browse pick up acknowledged writes the same way. The case needs Downloads opened during a sub-second online write. Offline, the write fails and rolls back, so the sharp still is correct.

suspend fun contentIdsWithPendingOrNewerUserState(
serverId: String, profileId: String, contentIds: List<String>, sinceMs: Long,
): List<String>

/** A newer desired-state write supersedes any v2 personal row the previous attempt left behind. */
@Query("DELETE FROM dirty_operations WHERE opKind = 'PERSONAL_V2' AND serverId = :serverId " +
"AND profileId = :profileId AND targetContentId = :contentId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface UserItemStateDao {

/** Clears resume state without discarding per-file playback or reading preferences. */
@Query(
"UPDATE user_item_state SET positionSeconds = 0, clientUpdatedAtMs = :updatedAtMs " +
"UPDATE user_item_state SET positionSeconds = 0, clientUpdatedAtMs = :updatedAtMs, positionUpdatedAtMs = :updatedAtMs " +
"WHERE serverId = :serverId AND profileId = :profileId AND contentId = :contentId " +
"AND positionSeconds <> 0",
)
Expand All @@ -43,17 +43,23 @@ interface UserItemStateDao {
updatedAtMs: Long,
)

/** A delayed watched acknowledgement must not clear a newer local resume sample. */
@Query("UPDATE user_item_state SET positionSeconds = 0, clientUpdatedAtMs = :updatedAtMs " +
/**
* A delayed watched acknowledgement must not clear a newer local resume sample.
* Rows written before positionUpdatedAtMs existed fall back to clientUpdatedAtMs.
*/
@Query("UPDATE user_item_state SET positionSeconds = 0, clientUpdatedAtMs = :updatedAtMs, positionUpdatedAtMs = :updatedAtMs " +
"WHERE serverId = :serverId AND profileId = :profileId AND contentId = :contentId " +
"AND clientUpdatedAtMs < :admittedAtMs")
"AND COALESCE(positionUpdatedAtMs, clientUpdatedAtMs) < :admittedAtMs")
suspend fun clearPlaybackProgressBefore(serverId: String, profileId: String, contentId: String, admittedAtMs: Long, updatedAtMs: Long)

/** Restore a reset resume row only while it is still the untouched reset. */
/**
* Restore a reset resume row only while it is still the untouched reset.
* A reset made before positionUpdatedAtMs existed is matched by clientUpdatedAtMs.
*/
@Query(
"UPDATE user_item_state SET positionSeconds = :positionSeconds, clientUpdatedAtMs = :previousUpdatedAtMs " +
"UPDATE user_item_state SET positionSeconds = :positionSeconds, clientUpdatedAtMs = CASE WHEN clientUpdatedAtMs = :clearedAtMs THEN :previousUpdatedAtMs ELSE clientUpdatedAtMs END, positionUpdatedAtMs = :previousPositionUpdatedAtMs " +
"WHERE serverId = :serverId AND profileId = :profileId AND contentId = :contentId " +
"AND fileId = :fileId AND positionSeconds = 0 AND clientUpdatedAtMs = :clearedAtMs",
"AND fileId = :fileId AND positionSeconds = 0 AND COALESCE(positionUpdatedAtMs, clientUpdatedAtMs) = :clearedAtMs",
)
suspend fun restorePlaybackProgressIfUnchanged(
serverId: String,
Expand All @@ -62,6 +68,7 @@ interface UserItemStateDao {
fileId: Int,
positionSeconds: Double,
previousUpdatedAtMs: Long,
previousPositionUpdatedAtMs: Long?,
clearedAtMs: Long,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ data class ContentItemStateEntity(
val favorite: Boolean?,
val clientUpdatedAtMs: Long,
val serverUpdatedAtMs: Long?,
/** Timestamp of the watch/progress mutation, excluding ratings and track choices. */
val watchedUpdatedAtMs: Long? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,6 @@ data class DownloadEntity(
val offlineSeriesPosterPath: String? = null,
/** ThumbHash of the parent series poster (episode downloads only). */
val seriesPosterThumbhash: String? = null,
val posterIsEpisodeStill: Boolean? = null,
val episodeUserDataJson: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ data class UserItemStateEntity(
val readProgress: Double?,
val clientUpdatedAtMs: Long,
val serverUpdatedAtMs: Long?,
/** Timestamp of the watch/progress mutation, excluding ratings and track choices. */
val positionUpdatedAtMs: Long? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ class RoomUserItemStateRepository(
current.watched == saved["previous_watched"]?.jsonPrimitive?.booleanOrNull &&
current.ratingValue == saved["previous_rating"]?.jsonPrimitive?.intOrNull
if (unchanged) {
val previous = current ?: ContentItemStateEntity(row.serverId, row.profileId, row.targetContentId, null, null, null, now(), null)
val nowMs = now()
val previous = current ?: ContentItemStateEntity(row.serverId, row.profileId, row.targetContentId, null, null, null, nowMs, null)
val projected = when (val command = handle.command) {
is PersonalWrite.Watched -> previous.copy(watched = command.watched)
is PersonalWrite.Watched -> previous.copy(watched = command.watched, watchedUpdatedAtMs = nowMs)
is PersonalWrite.Rating -> previous.copy(ratingValue = command.rating)
}
contentDao.upsert(projected.copy(clientUpdatedAtMs = now()))
contentDao.upsert(projected.copy(clientUpdatedAtMs = nowMs))
if (handle.command is PersonalWrite.Watched)
userStateDao.clearPlaybackProgressBefore(row.serverId, row.profileId, row.targetContentId, row.createdAtMs, now())
}
Expand Down Expand Up @@ -246,7 +247,7 @@ class RoomUserItemStateRepository(
clientUpdatedAtMs = nowMs,
serverUpdatedAtMs = null,
)
userStateDao.upsert(row)
userStateDao.upsert(row.copy(positionUpdatedAtMs = nowMs))

// V2 playback sends sequenced progress under its admitted session. Keep local resume,
// but never coalesce a new position into a legacy queue with unknown authority.
Expand Down Expand Up @@ -551,6 +552,15 @@ class RoomUserItemStateRepository(
.associate { it.contentId to LocalContentState(watched = it.watched, favorite = null) }
}

override suspend fun contentIdsWithPendingOrNewerUserState(contentIds: List<String>, sinceMs: Long): Set<String> {
val snapshot = snapshotProvider() ?: return emptySet()
val profileId = snapshot.profileId ?: return emptySet()
// The UNION binds the ID list three times; stay below SQLite's older 999-variable limit.
return contentIds.distinct().chunked(MAX_IN_LIST_IDS / 3).flatMap {
outboxDao.contentIdsWithPendingOrNewerUserState(snapshot.serverId, profileId, it, sinceMs)
}.toSet()
}

private suspend fun record(
contentId: String,
opKind: String,
Expand Down Expand Up @@ -578,7 +588,8 @@ class RoomUserItemStateRepository(
clientUpdatedAtMs = nowMs,
serverUpdatedAtMs = null,
)
contentDao.upsert(applyField(existing).copy(clientUpdatedAtMs = nowMs))
contentDao.upsert(applyField(existing).copy(clientUpdatedAtMs = nowMs,
watchedUpdatedAtMs = if (opKind == OutboxOperation.SET_WATCHED) nowMs else existing.watchedUpdatedAtMs))

var operationPayload = payloadJson
if (clearPlaybackProgress) {
Expand All @@ -598,6 +609,7 @@ class RoomUserItemStateRepository(
fileId = row.fileId,
positionSeconds = row.positionSeconds,
previousClientUpdatedAtMs = row.clientUpdatedAtMs,
previousPositionUpdatedAtMs = row.positionUpdatedAtMs,
clearedAtMs = nowMs,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ internal suspend fun UserItemStateDao.restorePlaybackProgressForTerminalOp(op: D
fileId = progress.fileId,
positionSeconds = progress.positionSeconds,
previousUpdatedAtMs = progress.previousClientUpdatedAtMs,
previousPositionUpdatedAtMs = progress.previousPositionUpdatedAtMs,
clearedAtMs = progress.clearedAtMs,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ data class OutboxOperation(
val positionSeconds: Double,
val previousClientUpdatedAtMs: Long,
val clearedAtMs: Long,
val previousPositionUpdatedAtMs: Long? = null,
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import org.siloserver.silo.common.player.SleepTimerController
import org.siloserver.silo.common.settings.AndroidPlayerSettingsStore
import org.siloserver.silo.common.settings.CardPresentationStore
import org.siloserver.silo.common.settings.DefaultCardPresentationStore
import org.siloserver.silo.common.settings.DefaultEpisodeSpoilerStore
import org.siloserver.silo.common.settings.DefaultLibraryPlaybackPrefsStore
import org.siloserver.silo.common.settings.DefaultOverlayPrefsStore
import org.siloserver.silo.common.settings.DefaultSeekIntervalStore
import org.siloserver.silo.common.settings.DefaultServerSettingsFlusher
import org.siloserver.silo.common.settings.EpisodeSpoilerStore
import org.siloserver.silo.common.settings.LibraryPlaybackPrefsStore
import org.siloserver.silo.common.settings.OverlayPrefsStore
import org.siloserver.silo.common.settings.PlayerSettingsStore
Expand Down Expand Up @@ -201,6 +203,27 @@ val playerInfraModule = module {
)
}

// Spoiler protection for unwatched episodes (see EpisodeSpoilers.MIN_CONTRACT_REVISION). Both
// keys are profile-scope only, so the store writes the profile row itself
// rather than going through the profile_device flusher. Resets and
// re-resolves on a server or profile change, like SeekIntervalStore:
// Add Server → sign in → pick profile clears nothing on its own.
single<EpisodeSpoilerStore> {
val identityChanges = get<ServerRegistry>().activeEntry
.map { it?.url to it?.profileId }
.distinctUntilChanged()
.map { Unit }
DefaultEpisodeSpoilerStore(
context = androidContext(),
repository = get<SettingsRepository>(),
scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate),
getActiveProfileId = { get<ProfileRepository>().getActiveProfileId() },
getServerUrl = { get<TokenManager>().getServerUrl() },
captureAuthority = { get<TokenManager>().snapshotCurrentScope() },
identityChanges = identityChanges,
)
}

// "Show title art" (settings revision 16) for this device. Every title
// surface and both settings screens read this one instance, so a change
// reaches an open detail page without a restart.
Expand All @@ -226,6 +249,7 @@ val playerInfraModule = module {
libraryPlaybackPrefsStore = get(),
playerSettingsStore = get(),
seekIntervalStore = get(),
episodeSpoilerStore = get(),
titleArtStore = get(),
hiddenLibrariesStore = get(),
hasAuthenticatedProfile = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class DownloadEnqueuer(
episodeNumber: Int?,
episodeTitle: String?,
posterUrl: String? = null,
posterIsEpisodeStill: Boolean? = null,
downloadQualityOverride: DownloadQuality? = null,
): ApiResult<Unit> {
val authority = authorities?.snapshotDurableLoginAuthority()
Expand Down Expand Up @@ -139,6 +140,8 @@ class DownloadEnqueuer(
title = seriesTitle,
subtitle = listOfNotNull(episodeCode, shownEpisodeTitle).joinToString(" · ").ifEmpty { null },
posterUrl = posterUrl,
posterIsEpisodeStill = posterIsEpisodeStill,
episodeUserData = episodeDetail?.userData,
seriesTitle = seriesTitle,
seriesContentId = seriesContentId,
seasonNumber = seasonNumber,
Expand Down Expand Up @@ -213,6 +216,8 @@ class DownloadEnqueuer(
} ?: "Series episode",
posterUrl = posterUrl,
posterThumbhash = seriesDetail?.posterThumbhash,
posterIsEpisodeStill = false,
episodeUserData = episodeDetail?.userData,
seriesTitle = seriesTitle,
seriesContentId = seriesContentId,
seasonNumber = ep?.seasonNumber,
Expand Down Expand Up @@ -274,6 +279,7 @@ class DownloadEnqueuer(
episodeNumber = ep.episodeNumber,
episodeTitle = ep.title,
posterUrl = posterUrl,
posterIsEpisodeStill = false,
// Season batch is original-only (server rejects a non-original
// batch with 501 bulk_quality_unavailable). Force Original even
// though startEpisode itself honors quality for single episodes.
Expand Down Expand Up @@ -468,6 +474,8 @@ class DownloadEnqueuer(
title = detail?.title ?: fallbackTitle,
posterUrl = detail?.posterUrl,
posterThumbhash = detail?.posterThumbhash,
posterIsEpisodeStill = detail?.posterIsEpisodeStill,
episodeUserData = detail?.userData.takeIf { detail?.type == "episode" },
year = detail?.year?.takeIf { it > 0 },
seriesTitle = detail?.seriesTitle,
// Stable TV grouping key — present for episode detail downloads via the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.siloserver.silo.common.downloads

import org.siloserver.silo.common.data.db.entity.DownloadEntity
import org.siloserver.silo.model.catalog.VersionChapter
import org.siloserver.silo.model.catalog.LeafItemUserData
import org.siloserver.silo.model.download.DownloadRecord
import org.siloserver.silo.model.download.DownloadSidecar
import org.siloserver.silo.model.download.OfflineTrackInfo
Expand Down Expand Up @@ -34,6 +35,8 @@ fun DownloadSidecar.toEntity(serverId: String, profileId: String): DownloadEntit
subtitle = subtitle,
posterUrl = posterUrl,
posterThumbhash = posterThumbhash,
posterIsEpisodeStill = posterIsEpisodeStill,
episodeUserDataJson = episodeUserData?.let { mappingJson.encodeToString(it) },
year = year,
seriesTitle = seriesTitle,
seriesContentId = seriesContentId,
Expand Down Expand Up @@ -87,6 +90,10 @@ fun DownloadEntity.toSidecar(): DownloadSidecar =
subtitle = subtitle,
posterUrl = posterUrl,
posterThumbhash = posterThumbhash,
posterIsEpisodeStill = posterIsEpisodeStill,
episodeUserData = episodeUserDataJson?.let {
runCatching { mappingJson.decodeFromString<LeafItemUserData>(it) }.getOrNull()
},
year = year,
seriesTitle = seriesTitle,
seriesContentId = seriesContentId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import org.siloserver.silo.model.download.DownloadMediaType
import org.siloserver.silo.model.download.DownloadSidecar
import java.io.File

/** Image source and blur-up placeholder for a download's 2:3 tile. */
data class DownloadTileArtwork(val url: String?, val thumbhash: String?)
/**
* Image source and blur-up placeholder for a download's 2:3 tile.
* [isEpisodeStill] is the provenance of [url]: false for a saved poster, the
* catalog's answer for a catalog URL, and null when that is unknown.
*/
data class DownloadTileArtwork(val url: String?, val thumbhash: String?, val isEpisodeStill: Boolean? = null)

/**
* The 2:3 tile artwork for one download. A movie uses its saved poster, else
Expand All @@ -27,9 +31,11 @@ fun List<DownloadSidecar>.tileArtwork(isFile: (String) -> Boolean = ::isSavedArt
?: firstNotNullOfOrNull { sidecar ->
sidecar.offlinePosterPath?.takeIf { !sidecar.isEpisodeDownload() && isFile(it) }
}
val catalog = firstOrNull { it.posterUrl != null }
return DownloadTileArtwork(
url = saved?.let(::localArtworkUrl) ?: firstNotNullOfOrNull { it.posterUrl },
url = saved?.let(::localArtworkUrl) ?: catalog?.posterUrl,
thumbhash = firstNotNullOfOrNull { it.seriesPosterThumbhash } ?: firstNotNullOfOrNull { it.posterThumbhash },
isEpisodeStill = if (saved != null) false else catalog?.posterIsEpisodeStill,
)
}

Expand Down
Loading
Loading