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
@@ -54,14 +54,50 @@ struct MediaMenu {
|
||||
playlistKey: nil, extra: [], confirmDownload: true, stemmed: stemmed(cov))
|
||||
}
|
||||
|
||||
func playlist(_ pl: Playlist, extra: [SheetAction] = []) -> [SheetAction] {
|
||||
/// [changed] hears the playlist after a rename or a new cover, so an open page can follow.
|
||||
func playlist(_ pl: Playlist, extra: [SheetAction] = [], changed: ((Playlist) -> Void)? = nil) -> [SheetAction] {
|
||||
let plex = g.plex
|
||||
let copy = SheetAction("Copy to Stem Playlist…", icon: "doc.on.doc") { copyToStems(pl) }
|
||||
let gr = DownloadGroup(kind: .playlist, key: pl.ratingKey, title: pl.title, subtitle: "Playlist", thumb: pl.thumb)
|
||||
return collection(pl.title, gr, { try await plex.playlistTracks(pl.ratingKey) }, playlistKey: pl.ratingKey, extra: [copy] + extra,
|
||||
return collection(pl.title, gr, { try await plex.playlistTracks(pl.ratingKey) }, playlistKey: pl.ratingKey,
|
||||
extra: [copy] + (pl.smart ? [] : playlistEdits(pl, changed)) + extra,
|
||||
confirmDownload: pl.trackCount > 50)
|
||||
}
|
||||
|
||||
/// Rename and Change Cover, saved on the playlist's own server (Plex or Jellyfin).
|
||||
private func playlistEdits(_ pl: Playlist, _ changed: ((Playlist) -> Void)?) -> [SheetAction] {
|
||||
let plex = g.plex
|
||||
let overlays = overlays
|
||||
let ui = ui
|
||||
let rename = SheetAction("Rename…", icon: "pencil") {
|
||||
overlays.prompt("Rename Playlist", nil, initial: pl.title, "Save") { name in
|
||||
Task {
|
||||
do {
|
||||
try await plex.renamePlaylist(pl.ratingKey, title: name)
|
||||
var p = pl; p.title = name
|
||||
ui.playlistEdits += 1
|
||||
changed?(p)
|
||||
} catch { overlays.hud("Couldn't rename: \(error.localizedDescription)", "exclamationmark.triangle") }
|
||||
}
|
||||
}
|
||||
}
|
||||
let cover = SheetAction("Change Cover…", icon: "photo") {
|
||||
overlays.pickPhoto { data in
|
||||
guard let jpeg = StemPlaylists.coverJpeg(data) else { overlays.hud("Couldn't use that photo", "exclamationmark.triangle"); return }
|
||||
Task {
|
||||
do {
|
||||
let thumb = try await plex.setPlaylistArt(pl.ratingKey, jpeg: jpeg)
|
||||
var p = pl; p.thumb = thumb ?? pl.thumb
|
||||
ui.playlistEdits += 1
|
||||
changed?(p)
|
||||
overlays.hud("Cover updated")
|
||||
} catch { overlays.hud("Couldn't upload: \(error.localizedDescription)", "exclamationmark.triangle") }
|
||||
}
|
||||
}
|
||||
}
|
||||
return [rename, cover]
|
||||
}
|
||||
|
||||
func stemPlaylist(_ pl: StemPlaylist, extra: [SheetAction] = [], onPage: Bool = false) -> [SheetAction] {
|
||||
var a = [
|
||||
SheetAction("Play Next", icon: "text.line.first.and.arrowtriangle.forward") {
|
||||
|
||||
@@ -74,6 +74,8 @@ final class Ui {
|
||||
/// Split only: which of the deck's pages is showing.
|
||||
var deckPage: DeckPage = .Stems
|
||||
let overlays: Overlays
|
||||
/// Bumped when a playlist is renamed or gets a new cover, so the lists reload.
|
||||
var playlistEdits = 0
|
||||
|
||||
init(overlays: Overlays) { self.overlays = overlays }
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ struct PlaylistsScreen: View {
|
||||
Button { kind == .Plex ? newPlaylist() : newStemPlaylist() } label: { Image(systemName: "plus") }
|
||||
}
|
||||
}
|
||||
.task(id: "\(g.settings.libraryKey)|\(sort.token)|\(reload)") {
|
||||
.task(id: "\(g.settings.libraryKey)|\(sort.token)|\(reload)|\(ui.playlistEdits)") {
|
||||
// /playlists may not take sort=random, so Random shuffles here.
|
||||
let random = sort.option.random
|
||||
await LoadState.load($lists) { try await random ? g.plex.playlists().shuffled() : g.plex.playlists(sort: sort.param) }
|
||||
@@ -221,6 +221,7 @@ struct PlaylistScreen: View {
|
||||
@State private var tracks: LoadState<[Track]> = .loading
|
||||
@State private var reload = 0
|
||||
@State private var title: String
|
||||
@State private var thumb: String?
|
||||
@State private var editing = false
|
||||
@State private var items: [Track] = []
|
||||
@State private var removed: [Track] = []
|
||||
@@ -230,6 +231,7 @@ struct PlaylistScreen: View {
|
||||
init(playlist: Playlist) {
|
||||
self.playlist = playlist
|
||||
_title = State(initialValue: playlist.title)
|
||||
_thumb = State(initialValue: playlist.thumb)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
@@ -284,7 +286,7 @@ struct PlaylistScreen: View {
|
||||
|
||||
private func header(_ list: [Track]) -> some View {
|
||||
VStack(spacing: 0) {
|
||||
Artwork(thumb: playlist.thumb, size: 230, corner: 10, placeholder: "music.note.list")
|
||||
Artwork(thumb: thumb, size: 230, corner: 10, placeholder: "music.note.list")
|
||||
Text(title).font(.title2.bold()).foregroundStyle(p.label).multilineTextAlignment(.center).lineLimit(2)
|
||||
.padding(.horizontal, 32).padding(.top, 14)
|
||||
if !list.isEmpty {
|
||||
@@ -312,13 +314,6 @@ struct PlaylistScreen: View {
|
||||
var extra: [SheetAction] = []
|
||||
let plex = g.plex
|
||||
let key = playlist.ratingKey
|
||||
if !playlist.smart {
|
||||
extra.append(SheetAction("Rename…", icon: "pencil") {
|
||||
ui.overlays.prompt("Rename Playlist", nil, initial: title, "Save") { name in
|
||||
Task { if (try? await plex.renamePlaylist(key, title: name)) != nil { title = name } }
|
||||
}
|
||||
})
|
||||
}
|
||||
extra.append(SheetAction("Delete Playlist", icon: "trash", destructive: true) {
|
||||
ui.overlays.confirm("Delete “\(title)”?", "This removes it from Plex for every app.", "Delete") {
|
||||
Task { if (try? await plex.deletePlaylist(key)) != nil { ui.pop() } }
|
||||
@@ -326,8 +321,9 @@ struct PlaylistScreen: View {
|
||||
})
|
||||
var pl = playlist
|
||||
pl.title = title
|
||||
pl.thumb = thumb
|
||||
pl.trackCount = list.count
|
||||
return ui.menu.playlist(pl, extra: extra)
|
||||
return ui.menu.playlist(pl, extra: extra) { title = $0.title; thumb = $0.thumb }
|
||||
}
|
||||
|
||||
/// Sends removals, then replays the new order as "move after" calls against a simulated server list.
|
||||
|
||||
Reference in new issue
Block a user