Plex/Jellyfin playlists: rename and custom cover from the long-press menu (build 60)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3ec9b043e3
commit
592f623bc2
9 files changed
+87
-19
No files matched your search
@@ -80,7 +80,8 @@ struct JItem: Decodable {
|
||||
func toArtist() -> Artist { Artist(ratingKey: id, title: name, sortTitle: sortName ?? name, thumb: thumb) }
|
||||
|
||||
func toPlaylist() -> Playlist {
|
||||
Playlist(ratingKey: id, title: name, thumb: thumb, trackCount: childCount ?? 0, durationMs: durationMs)
|
||||
// "id|tag": a new cover changes the tag, so the art cache doesn't keep the old one.
|
||||
Playlist(ratingKey: id, title: name, thumb: primaryTag.map { "\(id)|\($0)" } ?? thumb, trackCount: childCount ?? 0, durationMs: durationMs)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,6 +415,15 @@ final class JellyfinClient: MediaSource, @unchecked Sendable {
|
||||
try await send("DELETE", "/Items/\(key)")
|
||||
}
|
||||
|
||||
/// Jellyfin wants the image base64 encoded in the body.
|
||||
func setPlaylistArt(_ key: String, jpeg: Data) async throws {
|
||||
guard server.signedIn else { throw NotSignedIn() }
|
||||
var req = request(try url("/Items/\(key)/Images/Primary"), method: "POST")
|
||||
req.setValue("image/jpeg", forHTTPHeaderField: "Content-Type")
|
||||
req.httpBody = jpeg.base64EncodedData()
|
||||
_ = try await http.data(req)
|
||||
}
|
||||
|
||||
// ---- playback reporting ----------------------------------------------------------------
|
||||
|
||||
func scrobble(_ trackKey: String) async {
|
||||
@@ -431,8 +441,9 @@ final class JellyfinClient: MediaSource, @unchecked Sendable {
|
||||
// ---- URLs ---------------------------------------------------------------------------
|
||||
|
||||
func artUrl(_ thumb: String?, px: Int) -> URL? {
|
||||
guard let thumb, !thumb.isEmpty, server.signedIn, let u = URL(string: base + "/Items/\(thumb)/Images/Primary") else { return nil }
|
||||
return u.with([("fillWidth", px), ("fillHeight", px), ("quality", 90), ("api_key", server.token)])
|
||||
let parts = thumb?.split(separator: "|", maxSplits: 1).map(String.init) ?? []
|
||||
guard let id = parts.first, !id.isEmpty, server.signedIn, let u = URL(string: base + "/Items/\(id)/Images/Primary") else { return nil }
|
||||
return u.with([("fillWidth", px), ("fillHeight", px), ("quality", 90), ("tag", parts.count > 1 ? parts[1] : nil), ("api_key", server.token)])
|
||||
}
|
||||
|
||||
/// The original file, untouched, like Plex's part URL.
|
||||
|
||||
@@ -55,6 +55,8 @@ protocol MediaSource: AnyObject, Sendable {
|
||||
func removeFromPlaylist(_ key: String, playlistItemId: Int64) async throws
|
||||
func movePlaylistItem(_ key: String, playlistItemId: Int64, afterItemId: Int64?) async throws
|
||||
func renamePlaylist(_ key: String, title: String) async throws
|
||||
/// Uploads [jpeg] as the playlist's cover.
|
||||
func setPlaylistArt(_ key: String, jpeg: Data) async throws
|
||||
func deletePlaylist(_ key: String) async throws
|
||||
func scrobble(_ trackKey: String) async
|
||||
func timeline(_ track: Track, state: String, positionMs: Int64) async
|
||||
|
||||
@@ -235,6 +235,13 @@ final class PlexClient: @unchecked Sendable {
|
||||
try await s.deletePlaylist(k)
|
||||
}
|
||||
|
||||
/// Uploads the cover, then returns the playlist's new thumb.
|
||||
func setPlaylistArt(_ key: String, jpeg: Data) async throws -> String? {
|
||||
let (s, k) = try routed(key)
|
||||
try await s.setPlaylistArt(k, jpeg: jpeg)
|
||||
return try await s.playlists(sort: "titleSort").first { $0.ratingKey == k }?.thumb.tagged(s.server.id)
|
||||
}
|
||||
|
||||
// ---- playback reporting ---------------------------------------------------------
|
||||
|
||||
func scrobble(_ trackKey: String) async {
|
||||
|
||||
@@ -293,6 +293,15 @@ final class PlexServer: MediaSource, @unchecked Sendable {
|
||||
try await send("DELETE", "/playlists/\(key)")
|
||||
}
|
||||
|
||||
/// Plex takes the image as the raw body and selects it as the poster.
|
||||
func setPlaylistArt(_ key: String, jpeg: Data) async throws {
|
||||
guard signedIn else { throw NotSignedIn() }
|
||||
var req = request(try url("/library/metadata/\(key)/posters"), method: "POST")
|
||||
req.setValue("image/jpeg", forHTTPHeaderField: "Content-Type")
|
||||
req.httpBody = jpeg
|
||||
_ = try await http.data(req)
|
||||
}
|
||||
|
||||
// ---- playback reporting ---------------------------------------------------------
|
||||
|
||||
func scrobble(_ trackKey: String) async {
|
||||
|
||||
Reference in new issue
Block a user