tv-anarchy/Sources/PlumTVCore/Library/LibraryModels.swift
Natalie ff6f881648 feat(@applications/plum-tv): add library browsing UI and core library logic
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
2026-06-07 21:52:49 -07:00

81 lines
3 KiB
Swift

import Foundation
/// One episode file in the library. `metaPath` points at the `.meta` sidecar
/// once Phase 4 enrichment runs; nil until then.
public struct CachedEpisode: Codable, Sendable, Hashable, Identifiable {
public var path: String
public var season: Int
public var episode: Int
public var label: String
public var metaPath: String?
public var id: String { path }
public init(path: String, season: Int, episode: Int, label: String, metaPath: String? = nil) {
self.path = path; self.season = season; self.episode = episode
self.label = label; self.metaPath = metaPath
}
}
/// A show grouped from the scan. `posterPath`/`overview` are filled by Phase 4
/// (TMDB) and survive rescans (merged back in by rootDir).
public struct CachedShow: Codable, Sendable, Hashable, Identifiable {
public var name: String
public var rootDir: String
public var posterPath: String?
public var overview: String?
public var episodes: [CachedEpisode]
public var id: String { rootDir }
public init(name: String, rootDir: String, posterPath: String? = nil,
overview: String? = nil, episodes: [CachedEpisode]) {
self.name = name; self.rootDir = rootDir; self.posterPath = posterPath
self.overview = overview; self.episodes = episodes
}
/// Distinct season numbers, ascending.
public var seasons: [Int] {
Array(Set(episodes.map(\.season))).sorted()
}
public func episodes(inSeason s: Int) -> [CachedEpisode] {
episodes.filter { $0.season == s }.sorted { $0.episode < $1.episode }
}
}
/// The on-disk library snapshot browsable offline. Source records how it was
/// built ("scan" from ~/media, "registry" from media-recommender's list).
public struct LibrarySnapshot: Codable, Sendable {
public var shows: [CachedShow]
public var capturedAt: Date
public var source: String
public init(shows: [CachedShow], capturedAt: Date, source: String) {
self.shows = shows; self.capturedAt = capturedAt; self.source = source
}
}
/// A resume candidate for the "Continue watching" rail, unioned from the plum
/// watchlog and VLC's recents. `show`/`season`/`episode` are present for
/// watchlog entries (so black can `resume-show`); VLC recents carry only a path.
public struct ContinueItem: Sendable, Equatable, Identifiable {
public var title: String
public var path: String
public var show: String?
public var season: Int?
public var episode: Int?
public var positionSeconds: Double?
public var lastSeen: Date?
public var source: String
public var id: String { path }
public init(title: String, path: String, show: String? = nil, season: Int? = nil,
episode: Int? = nil, positionSeconds: Double? = nil,
lastSeen: Date? = nil, source: String) {
self.title = title; self.path = path; self.show = show; self.season = season
self.episode = episode; self.positionSeconds = positionSeconds
self.lastSeen = lastSeen; self.source = source
}
}