@@ -110,7 +110,9 @@ def maybe_report() -> None:
110110 if parsed_count == 0 :
111111 return
112112 if parsed_count == 1 or parsed_count % _PARSE_PROGRESS_INTERVAL == 0 :
113- _logger .info ("inCrate import: parsing progress — %s tracks so far" , parsed_count )
113+ _logger .info (
114+ "inCrate import: parsing progress — %s tracks so far" , parsed_count
115+ )
114116 progress_callback (parsed_count , - 1 )
115117
116118 context = ET .iterparse (xml_path , events = ("start" , "end" ))
@@ -122,7 +124,9 @@ def maybe_report() -> None:
122124 continue
123125 # event == "end"
124126 if elem .tag == "TRACK" and in_collection :
125- tid = (elem .get ("TrackID" ) or elem .get ("ID" ) or elem .get ("Key" ) or "" ).strip ()
127+ tid = (
128+ elem .get ("TrackID" ) or elem .get ("ID" ) or elem .get ("Key" ) or ""
129+ ).strip ()
126130 if not tid :
127131 _logger .debug (
128132 "[reliability] Skipping TRACK with missing TrackID in %s" ,
@@ -370,10 +374,24 @@ def _parse_nodes(parent_elem: ET.Element, path_prefix: str) -> List[Dict[str, An
370374 tracks .append (track )
371375 pl = Playlist (name = name , tracks = tracks )
372376 playlists_by_path [full_path ] = pl
373- nodes .append ({"type" : "playlist" , "name" : name , "path" : full_path , "track_count" : len (track_ids )})
377+ nodes .append (
378+ {
379+ "type" : "playlist" ,
380+ "name" : name ,
381+ "path" : full_path ,
382+ "track_count" : len (track_ids ),
383+ }
384+ )
374385 else :
375386 children = _parse_nodes (node_elem , full_path )
376- nodes .append ({"type" : "folder" , "name" : name , "path" : full_path , "children" : children })
387+ nodes .append (
388+ {
389+ "type" : "folder" ,
390+ "name" : name ,
391+ "path" : full_path ,
392+ "children" : children ,
393+ }
394+ )
377395 return nodes
378396
379397 playlists_root = root .find (".//PLAYLISTS" )
@@ -580,22 +598,38 @@ def get_playlist_track_ids(xml_path: str, playlist_name: str) -> List[str]:
580598 """
581599 _ , playlists_by_path = parse_playlist_tree (xml_path )
582600 if playlist_name in playlists_by_path :
583- return [t .track_id for t in playlists_by_path [playlist_name ].tracks if t .track_id ]
601+ return [
602+ t .track_id for t in playlists_by_path [playlist_name ].tracks if t .track_id
603+ ]
584604 # Try path without ROOT prefix (with or without slash; some callers pass "ROOTUntitled" or "ROOT/Untitled")
585605 path_without_root = playlist_name .strip ()
586606 if path_without_root .upper ().startswith ("ROOT/" ):
587607 path_without_root = path_without_root [5 :].lstrip ()
588608 elif path_without_root .upper ().startswith ("ROOT" ):
589609 path_without_root = path_without_root [4 :].lstrip ()
590610 if path_without_root and path_without_root in playlists_by_path :
591- return [t .track_id for t in playlists_by_path [path_without_root ].tracks if t .track_id ]
611+ return [
612+ t .track_id
613+ for t in playlists_by_path [path_without_root ].tracks
614+ if t .track_id
615+ ]
592616 # Try canonical path with slash (ROOT/Name) when input had no slash (e.g. from CSV filename)
593617 if path_without_root :
594618 canonical = f"ROOT/{ path_without_root } "
595619 if canonical in playlists_by_path :
596- return [t .track_id for t in playlists_by_path [canonical ].tracks if t .track_id ]
620+ return [
621+ t .track_id for t in playlists_by_path [canonical ].tracks if t .track_id
622+ ]
597623 # Fallback: resolve by playlist name (last path segment or exact name)
598- name_only = path_without_root if path_without_root else (playlist_name .split ("/" )[- 1 ].strip () if "/" in playlist_name else playlist_name )
624+ name_only = (
625+ path_without_root
626+ if path_without_root
627+ else (
628+ playlist_name .split ("/" )[- 1 ].strip ()
629+ if "/" in playlist_name
630+ else playlist_name
631+ )
632+ )
599633 for path , pl in playlists_by_path .items ():
600634 if pl .name == playlist_name or pl .name == name_only :
601635 return [t .track_id for t in pl .tracks if t .track_id ]
@@ -638,7 +672,9 @@ def write_updated_collection_xml(
638672 collection = root .find (".//COLLECTION" )
639673 if collection is not None :
640674 for elem in collection .findall ("TRACK" ):
641- tid = (elem .get ("TrackID" ) or elem .get ("ID" ) or elem .get ("Key" ) or "" ).strip ()
675+ tid = (
676+ elem .get ("TrackID" ) or elem .get ("ID" ) or elem .get ("Key" ) or ""
677+ ).strip ()
642678 if tid in updates :
643679 for attr_name , attr_value in updates [tid ].items ():
644680 elem .set (attr_name , attr_value )
@@ -678,6 +714,7 @@ def _short_key(key: Optional[str]) -> str:
678714 if not key :
679715 return ""
680716 import re
717+
681718 s = (key or "" ).strip ()
682719 s = s .replace ("\u266d " , "b" ).replace ("\u266f " , "#" ) # Unicode flat/sharp
683720 s = re .sub (r"\s+" , " " , s )
@@ -725,7 +762,9 @@ def build_rekordbox_updates(
725762 opts = sync_options
726763 if opts is None :
727764 key_fmt = "camelot" if use_camelot_key else "normal"
728- write_key = write_year = write_bpm = write_label = write_genre = write_comment = True
765+ write_key = write_year = write_bpm = write_label = write_genre = (
766+ write_comment
767+ ) = True
729768 comment_text = "ok"
730769 else :
731770 key_fmt = (opts .get ("key_format" ) or "normal" ).lower ()
@@ -754,9 +793,9 @@ def build_rekordbox_updates(
754793 updates [tid ]["Comment" ] = comment_text
755794 if write_key :
756795 if key_fmt == "camelot" :
757- key_val = (r . beatport_key_camelot and str ( r . beatport_key_camelot ). strip ()) or (
758- _camelot_key ( r . beatport_key ) if r . beatport_key else ""
759- )
796+ key_val = (
797+ r . beatport_key_camelot and str ( r . beatport_key_camelot ). strip ()
798+ ) or ( _camelot_key ( r . beatport_key ) if r . beatport_key else "" )
760799 elif key_fmt == "short" :
761800 key_val = _short_key (r .beatport_key ) if r .beatport_key else ""
762801 if not key_val and r .beatport_key :
@@ -772,14 +811,18 @@ def build_rekordbox_updates(
772811 if write_bpm and r .beatport_bpm is not None :
773812 try :
774813 bpm_val = float (r .beatport_bpm )
775- updates [tid ]["BPM" ] = str (int (bpm_val )) if bpm_val == int (bpm_val ) else f"{ bpm_val :.1f} "
814+ updates [tid ]["BPM" ] = (
815+ str (int (bpm_val )) if bpm_val == int (bpm_val ) else f"{ bpm_val :.1f} "
816+ )
776817 except (TypeError , ValueError ):
777818 updates [tid ]["BPM" ] = str (r .beatport_bpm )
778819 if write_label and r .beatport_label and str (r .beatport_label ).strip ():
779820 updates [tid ]["Label" ] = str (r .beatport_label ).strip ()
780821 if write_genre and r .beatport_genres and str (r .beatport_genres ).strip ():
781822 genres = str (r .beatport_genres ).strip ()
782- updates [tid ]["Genre" ] = genres .split ("," )[0 ].strip () if "," in genres else genres
823+ updates [tid ]["Genre" ] = (
824+ genres .split ("," )[0 ].strip () if "," in genres else genres
825+ )
783826 return updates
784827
785828
@@ -973,7 +1016,9 @@ def write_tags_to_paths(
9731016 opts = sync_options
9741017 if opts is None :
9751018 key_fmt = "normal"
976- write_key = write_year = write_bpm = write_label = write_genre = write_comment = True
1019+ write_key = write_year = write_bpm = write_label = write_genre = (
1020+ write_comment
1021+ ) = True
9771022 comment_text = "ok"
9781023 else :
9791024 key_fmt = (opts .get ("key_format" ) or "normal" ).lower ()
@@ -1001,9 +1046,9 @@ def write_tags_to_paths(
10011046 key_val = None
10021047 if write_key :
10031048 if key_fmt == "camelot" :
1004- key_val = (r . beatport_key_camelot and str ( r . beatport_key_camelot ). strip ()) or (
1005- _camelot_key ( r . beatport_key ) if r . beatport_key else ""
1006- )
1049+ key_val = (
1050+ r . beatport_key_camelot and str ( r . beatport_key_camelot ). strip ()
1051+ ) or ( _camelot_key ( r . beatport_key ) if r . beatport_key else "" )
10071052 elif key_fmt == "short" :
10081053 key_val = _short_key (r .beatport_key ) if r .beatport_key else ""
10091054 if not key_val and r .beatport_key :
@@ -1012,15 +1057,21 @@ def write_tags_to_paths(
10121057 key_val = (r .beatport_key and str (r .beatport_key ).strip ()) or ""
10131058 if not key_val :
10141059 key_val = None
1015- year_val = _normalize_year (r .beatport_year ) if write_year and r .beatport_year else None
1060+ year_val = (
1061+ _normalize_year (r .beatport_year ) if write_year and r .beatport_year else None
1062+ )
10161063 bpm_val = None
10171064 if write_bpm and r .beatport_bpm is not None :
10181065 try :
10191066 b = float (r .beatport_bpm )
10201067 bpm_val = str (int (b )) if b == int (b ) else f"{ b :.1f} "
10211068 except (TypeError , ValueError ):
10221069 bpm_val = str (r .beatport_bpm )
1023- label_val = (r .beatport_label and str (r .beatport_label ).strip ()) if write_label else None
1070+ label_val = (
1071+ (r .beatport_label and str (r .beatport_label ).strip ())
1072+ if write_label
1073+ else None
1074+ )
10241075 genre_val = None
10251076 if write_genre and r .beatport_genres and str (r .beatport_genres ).strip ():
10261077 g = str (r .beatport_genres ).strip ()
0 commit comments