Füge Funktion zum Löschen leerer Hot Cues und Memory Cues hinzu und erweitere das CLI mit einem Cleanup-Befehl.
This commit is contained in:
		
							
								
								
									
										50
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										50
									
								
								main.py
									
									
									
									
									
								
							| @@ -202,6 +202,44 @@ def convert_hot_cues_to_memory_cues(xml_file_path, output_file_path=None, backup | ||||
|         raise Exception(f"Fehler beim Speichern der XML-Datei: {e}") | ||||
|  | ||||
|  | ||||
| def cleanup_empty_cues(xml_file_path, output_file_path=None, backup=True): | ||||
|     """ | ||||
|     Löscht alle Hot Cues und Memory Cues, deren Name leer ist oder nur aus Leerzeichen besteht. | ||||
|     Args: | ||||
|         xml_file_path (str): Pfad zur Rekordbox XML Datei | ||||
|         output_file_path (str, optional): Ausgabedatei. Wenn None, wird die Original-Datei überschrieben | ||||
|         backup (bool): Erstellt ein Backup der Original-Datei | ||||
|     """ | ||||
|     xml_path = Path(xml_file_path) | ||||
|     if not xml_path.exists(): | ||||
|         raise FileNotFoundError(f"XML-Datei nicht gefunden: {xml_file_path}") | ||||
|     if backup: | ||||
|         backup_path = xml_path.with_suffix(xml_path.suffix + '.backup') | ||||
|         shutil.copy2(xml_path, backup_path) | ||||
|         print(f"Backup erstellt: {backup_path}") | ||||
|     try: | ||||
|         tree = ET.parse(xml_path) | ||||
|         root = tree.getroot() | ||||
|     except ET.ParseError as e: | ||||
|         raise Exception(f"Fehler beim Parsen der XML-Datei: {e}") | ||||
|  | ||||
|     cues_deleted = 0 | ||||
|     for track in root.findall(".//TRACK"): | ||||
|         position_marks = list(track.findall(".//POSITION_MARK")) | ||||
|         for position_mark in position_marks: | ||||
|             name = position_mark.get("Name", "") | ||||
|             if name.strip() == "": | ||||
|                 track.remove(position_mark) | ||||
|                 cues_deleted += 1 | ||||
|     output_path = Path(output_file_path) if output_file_path else xml_path | ||||
|     try: | ||||
|         tree.write(output_path, encoding="utf-8", xml_declaration=True) | ||||
|         print(f"\nErgebnis gespeichert in: {output_path}") | ||||
|         print(f"Gelöschte Cues: {cues_deleted}") | ||||
|     except Exception as e: | ||||
|         raise Exception(f"Fehler beim Speichern der XML-Datei: {e}") | ||||
|  | ||||
|  | ||||
| def main(): | ||||
|     parser = argparse.ArgumentParser( | ||||
|         description="Rekordbox XML Hot Cue Tools", | ||||
| @@ -235,6 +273,12 @@ Beispiele: | ||||
|     convert_parser.add_argument("xml_file", help="Pfad zur Rekordbox XML Datei") | ||||
|     convert_parser.add_argument("-o", "--output", help="Ausgabedatei (optional)") | ||||
|     convert_parser.add_argument("--no-backup", action="store_true", help="Kein Backup erstellen") | ||||
|  | ||||
|     # Cleanup command | ||||
|     cleanup_parser = subparsers.add_parser("cleanup", help="Leere Hot Cues und Memory Cues löschen") | ||||
|     cleanup_parser.add_argument("xml_file", help="Pfad zur Rekordbox XML Datei") | ||||
|     cleanup_parser.add_argument("-o", "--output", help="Ausgabedatei (optional)") | ||||
|     cleanup_parser.add_argument("--no-backup", action="store_true", help="Kein Backup erstellen") | ||||
|      | ||||
|     args = parser.parse_args() | ||||
|      | ||||
| @@ -255,6 +299,12 @@ Beispiele: | ||||
|                 args.output,  | ||||
|                 backup=not args.no_backup | ||||
|             ) | ||||
|         elif args.command == "cleanup": | ||||
|             cleanup_empty_cues( | ||||
|                 args.xml_file, | ||||
|                 args.output, | ||||
|                 backup=not args.no_backup | ||||
|             ) | ||||
|     except Exception as e: | ||||
|         print(f"Fehler: {e}") | ||||
|         return 1 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user