ID-first fallback for replace-track + remove-track too
Same latent bug as add-track — replace-track and remove-track only looked up the Plex playlist by name. Plex deletes + recreates playlists on edit so the rating key the frontend cached can be stale, name lookups can also fail (special chars, encoding). Both now use the same id-first / name-fallback chain as the GET tracks endpoint, with a diagnostic log when both lookups fail. Pre-existing latent bug, not a refactor regression.
This commit is contained in:
parent
218af65606
commit
397a1c73df
1 changed files with 26 additions and 3 deletions
|
|
@ -18364,10 +18364,21 @@ def server_playlist_replace_track(playlist_id):
|
||||||
active_server = config_manager.get_active_media_server()
|
active_server = config_manager.get_active_media_server()
|
||||||
|
|
||||||
if active_server == 'plex' and media_server_engine.client('plex'):
|
if active_server == 'plex' and media_server_engine.client('plex'):
|
||||||
# Use raw Plex API - fetch playlist directly
|
# ID-first, name-fallback (Plex deletes + recreates on edit
|
||||||
|
# so the cached rating key can be stale).
|
||||||
|
plex_server = media_server_engine.client('plex').server
|
||||||
|
raw_playlist = None
|
||||||
try:
|
try:
|
||||||
raw_playlist = media_server_engine.client('plex').server.playlist(playlist_name)
|
raw_playlist = plex_server.fetchItem(int(playlist_id))
|
||||||
except Exception:
|
except Exception:
|
||||||
|
pass
|
||||||
|
if not raw_playlist and playlist_name:
|
||||||
|
try:
|
||||||
|
raw_playlist = plex_server.playlist(playlist_name)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
if not raw_playlist:
|
||||||
|
logger.warning(f"[ServerPlaylist] replace-track: playlist not found by id={playlist_id} or name='{playlist_name}'")
|
||||||
return jsonify({"success": False, "error": "Playlist not found on server"}), 404
|
return jsonify({"success": False, "error": "Playlist not found on server"}), 404
|
||||||
|
|
||||||
# Build new track list with replacement
|
# Build new track list with replacement
|
||||||
|
|
@ -18537,9 +18548,21 @@ def server_playlist_remove_track(playlist_id):
|
||||||
active_server = config_manager.get_active_media_server()
|
active_server = config_manager.get_active_media_server()
|
||||||
|
|
||||||
if active_server == 'plex' and media_server_engine.client('plex'):
|
if active_server == 'plex' and media_server_engine.client('plex'):
|
||||||
|
# ID-first, name-fallback (Plex deletes + recreates on edit
|
||||||
|
# so the cached rating key can be stale).
|
||||||
|
plex_server = media_server_engine.client('plex').server
|
||||||
|
raw_playlist = None
|
||||||
try:
|
try:
|
||||||
raw_playlist = media_server_engine.client('plex').server.playlist(playlist_name)
|
raw_playlist = plex_server.fetchItem(int(playlist_id))
|
||||||
except Exception:
|
except Exception:
|
||||||
|
pass
|
||||||
|
if not raw_playlist and playlist_name:
|
||||||
|
try:
|
||||||
|
raw_playlist = plex_server.playlist(playlist_name)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
if not raw_playlist:
|
||||||
|
logger.warning(f"[ServerPlaylist] remove-track: playlist not found by id={playlist_id} or name='{playlist_name}'")
|
||||||
return jsonify({"success": False, "error": "Playlist not found"}), 404
|
return jsonify({"success": False, "error": "Playlist not found"}), 404
|
||||||
|
|
||||||
# Rebuild without the target track
|
# Rebuild without the target track
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue