Skip to content

Commit 240b06c

Browse files
committed
more more more fixes
1 parent 81563f7 commit 240b06c

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

src/cuepoint/data/rekordbox.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,51 @@ def _parse_nodes(parent_elem: ET.Element, path_prefix: str) -> List[Dict[str, An
401401
return (tree_roots, playlists_by_path)
402402

403403

404+
def resolve_playlist_key(
405+
playlist_name: str, playlists_by_path: Dict[str, Playlist]
406+
) -> Optional[str]:
407+
"""Resolve a user-provided playlist name to the path key used in playlists_by_path.
408+
409+
Accepts full path (e.g. ROOT/My Playlist), short name (My Playlist), or
410+
path without ROOT prefix. Returns the key to use for lookup, or None if not found.
411+
412+
Args:
413+
playlist_name: Name or path provided by user/CLI.
414+
playlists_by_path: Dict from parse_playlist_tree (path -> Playlist).
415+
416+
Returns:
417+
The key to use in playlists_by_path, or None.
418+
"""
419+
if not playlist_name or not playlists_by_path:
420+
return None
421+
if playlist_name in playlists_by_path:
422+
return playlist_name
423+
path_without_root = playlist_name.strip()
424+
if path_without_root.upper().startswith("ROOT/"):
425+
path_without_root = path_without_root[5:].lstrip()
426+
elif path_without_root.upper().startswith("ROOT"):
427+
path_without_root = path_without_root[4:].lstrip()
428+
if path_without_root and path_without_root in playlists_by_path:
429+
return path_without_root
430+
if path_without_root:
431+
canonical = f"ROOT/{path_without_root}"
432+
if canonical in playlists_by_path:
433+
return canonical
434+
name_only = (
435+
path_without_root
436+
if path_without_root
437+
else (
438+
playlist_name.split("/")[-1].strip()
439+
if "/" in playlist_name
440+
else playlist_name
441+
)
442+
)
443+
for path, pl in playlists_by_path.items():
444+
if pl.name == playlist_name or pl.name == name_only:
445+
return path
446+
return None
447+
448+
404449
def extract_artists_from_title(title: str) -> Optional[Tuple[str, str]]:
405450
"""Extract artist names from title if title follows "Artists - Title" format.
406451

src/cuepoint/services/processor_service.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
is_writable,
3232
parse_playlist_tree,
3333
read_playlist_index,
34+
resolve_playlist_key,
3435
)
3536
from cuepoint.models.config import SETTINGS
3637
from cuepoint.models.preflight import PreflightIssue, PreflightResult
@@ -1298,8 +1299,9 @@ def process_playlist_from_xml(
12981299
collector.start_stage(STAGE_SEARCH_CANDIDATES)
12991300
collector.sample_memory()
13001301

1301-
# Validate that requested playlist exists in the XML
1302-
if playlist_name not in playlists:
1302+
# Resolve user-provided name (e.g. "My Playlist") to path key (e.g. "ROOT/My Playlist")
1303+
resolved_key = resolve_playlist_key(playlist_name, playlists)
1304+
if resolved_key is None:
13031305
available_playlists = sorted(playlists.keys())
13041306
raise ProcessingError(
13051307
error_type=ErrorType.PLAYLIST_NOT_FOUND,
@@ -1316,6 +1318,7 @@ def process_playlist_from_xml(
13161318
],
13171319
recoverable=True,
13181320
)
1321+
playlist_name = resolved_key
13191322

13201323
# Get the requested playlist (already contains Track objects)
13211324
playlist = playlists[playlist_name]

0 commit comments

Comments
 (0)