66 lines
2.6 KiB
Python
66 lines
2.6 KiB
Python
#
|
|
# This program reads rekordbox CUE files and output a label track to be imported in Audacity.
|
|
# Usage: cue2audacity.py directory (where directory is the path where the CUE files are stored)
|
|
# Author: Manuel Weiser
|
|
# Date: 2025-07-03
|
|
#
|
|
|
|
import argparse
|
|
import glob
|
|
import re
|
|
import os
|
|
|
|
# Get argument on command line
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("thePathOfCueFiles", help="The path of the directory with the CUE files to process")
|
|
thePath = parser.parse_args().thePathOfCueFiles
|
|
|
|
# Read *.cue files in specified directory
|
|
for cueFileName in glob.glob(os.path.join(thePath, "*.cue")):
|
|
#print(cueFileName)
|
|
with open(cueFileName, "r", encoding="utf-8") as cueFile:
|
|
cueFileContent = cueFile.readlines()
|
|
#print(cueFileContent)
|
|
|
|
# Create label file
|
|
labelFileName = os.path.splitext(cueFileName)[0] + ".txt"
|
|
with open(labelFileName, "w", encoding="utf-8") as labelFile:
|
|
#print ("###" + labelFileName + "###")
|
|
|
|
# Process file
|
|
theTitle = "" # initialize title now in order to keep it available when scanning subsequent INDEX line
|
|
trackCount = 0
|
|
|
|
for lineNum, line in enumerate(cueFileContent, 1):
|
|
originalLine = line
|
|
line = line.strip() # Remove leading/trailing whitespace
|
|
|
|
# Match TITLE - try multiple patterns for different indentation (tabs or spaces)
|
|
theMatchTitle = re.search(r'TITLE\s+"([^"]+)"', line)
|
|
if theMatchTitle is not None:
|
|
theTitle = theMatchTitle.group(1)
|
|
|
|
# Match INDEX 01 - try multiple patterns for different formats (tabs or spaces)
|
|
theMatchIndex = re.search(r'INDEX\s+01\s+(\d{1,2}):(\d{2}):(\d{2})', line)
|
|
if theMatchIndex is not None:
|
|
theHours = int(theMatchIndex.group(1)) # Actually hours in HH:MM:SS format
|
|
theMinutes = int(theMatchIndex.group(2)) # Minutes
|
|
theSeconds = int(theMatchIndex.group(3)) # Seconds
|
|
|
|
trackCount += 1
|
|
|
|
# Convert HH:MM:SS to total seconds
|
|
theStartTime = (theHours * 3600) + (theMinutes * 60) + theSeconds
|
|
|
|
# format theStartTime
|
|
theStartTime = "{:.6f}".format(theStartTime)
|
|
|
|
# Write time and title to label file
|
|
labelFile.write(theStartTime + "\t" + theStartTime + "\t" + theTitle + "\n")
|
|
|
|
print(f"Created {trackCount} labels in {labelFileName}")
|
|
|
|
# end for line in cueFileContent
|
|
|
|
# end for cueFileName in glob.glob(thePath + "\\*.cue")
|