Fix: Only create destination folder if MP3 files exist in source directory
This commit is contained in:
12
src/app.py
12
src/app.py
@@ -38,7 +38,7 @@ def analyze_bpm_librosa(file_path):
|
||||
try:
|
||||
y, sr = librosa.load(file_path, mono=True)
|
||||
tempo, _ = librosa.beat.beat_track(y=y, sr=sr)
|
||||
return int(round(float(tempo[0])))
|
||||
return int(round(float(tempo)))
|
||||
except Exception as e:
|
||||
print(f"Error analyzing BPM for {file_path.name}: {e}")
|
||||
return None
|
||||
@@ -87,11 +87,6 @@ def main():
|
||||
print(f"Error: {source_media_path} is not a valid directory.")
|
||||
sys.exit(1)
|
||||
|
||||
parent = source_media_path.parent
|
||||
folder_name = source_media_path.name
|
||||
dest_media_path = parent / f"[CDs-{run_date}]{folder_name}"
|
||||
dest_media_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
all_tracks = []
|
||||
for file in source_media_path.rglob("*.mp3"):
|
||||
bpm = get_bpm(file)
|
||||
@@ -118,6 +113,11 @@ def main():
|
||||
print("No MP3 files found.")
|
||||
sys.exit(0)
|
||||
|
||||
parent = source_media_path.parent
|
||||
folder_name = source_media_path.name
|
||||
dest_media_path = parent / f"[CDs-{run_date}]{folder_name}"
|
||||
dest_media_path.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
total_size = sum(t["size"] for t in all_tracks)
|
||||
num_cds = max(1, (total_size + CD_SIZE - 1) // CD_SIZE)
|
||||
|
||||
|
Reference in New Issue
Block a user