iOS: Use Stem Server switch for Plex-only playback, build 42
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7843ff562b
commit
0516362461
5 files changed
+64
-37
No files matched your search
@@ -5,6 +5,7 @@ enum StemServerStatus: Equatable {
|
||||
case unknown
|
||||
case online(tracks: Int, transcode: Bool)
|
||||
case offline(reason: String, cachedTracks: Int)
|
||||
case off
|
||||
|
||||
var isOnline: Bool { if case .online = self { true } else { false } }
|
||||
}
|
||||
@@ -65,7 +66,8 @@ final class StemServer: @unchecked Sendable {
|
||||
self.settings = settings
|
||||
indexFile = dir.appendingPathComponent("stem_index.json")
|
||||
etagFile = dir.appendingPathComponent("stem_index.etag")
|
||||
if let data = try? Data(contentsOf: indexFile),
|
||||
if settings.stemServerOff { status = .off }
|
||||
else if let data = try? Data(contentsOf: indexFile),
|
||||
let parsed = try? JSONDecoder().decode(StemIndexFile.self, from: data) {
|
||||
index = StemIndex(parsed.tracks, roots: roots())
|
||||
}
|
||||
@@ -111,7 +113,7 @@ final class StemServer: @unchecked Sendable {
|
||||
|
||||
/// Reads /api/queue. A change in the finished count pulls the new index straight away.
|
||||
func pollQueue() async {
|
||||
guard !base.isEmpty,
|
||||
guard !settings.stemServerOff, !base.isEmpty,
|
||||
let u = try? url("/api/queue"),
|
||||
let data = try? await http.data(req(u)),
|
||||
let q = try? JSONDecoder().decode(QueueInfo.self, from: data) else { return }
|
||||
@@ -146,6 +148,16 @@ final class StemServer: @unchecked Sendable {
|
||||
|
||||
func refresh(force: Bool = false) async {
|
||||
await refreshLock.run {
|
||||
if settings.stemServerOff {
|
||||
await MainActor.run {
|
||||
let had = self.index.size > 0
|
||||
self.index = StemIndex([])
|
||||
self.current = nil; self.pending = []; self.failed = []
|
||||
self.status = .off
|
||||
if had { self.indexListeners.forEach { $0() } }
|
||||
}
|
||||
return
|
||||
}
|
||||
do {
|
||||
let info = try JSONDecoder().decode(ServerInfo.self, from: try await http.data(req(try url("/api/info"))))
|
||||
transcode = info.ffmpeg
|
||||
@@ -185,6 +197,7 @@ final class StemServer: @unchecked Sendable {
|
||||
}
|
||||
|
||||
func find(_ track: Track) -> StemEntry? {
|
||||
if settings.stemServerOff { return nil }
|
||||
let idx = index
|
||||
if let k = track.stemKey { return idx.entries.first { $0.key == k } }
|
||||
let hit = idx.find(track.partFile, durationMs: track.durationMs)
|
||||
|
||||
Reference in new issue
Block a user