First commit

This commit is contained in:
2025-05-23 11:57:56 +02:00
commit 0e0223151e
2 changed files with 220 additions and 0 deletions

38
src/app.py Normal file
View File

@@ -0,0 +1,38 @@
import os
import shutil
from mutagen.mp3 import MP3
from mutagen.id3 import ID3, TBPM
from pathlib import Path
# Define paths
dir_a = Path(r"C:\Users\Edgar\Desktop\Peak Time BOF (ed1337x)\Already where in MP3")
dir_b = Path(r"C:\Users\Edgar\Desktop\Peak Time BOF (ed1337x)\CD")
# Ensure dir B exists
dir_b.mkdir(parents=True, exist_ok=True)
def get_bpm(file_path):
try:
tags = ID3(file_path)
bpm_tag = tags.get('TBPM')
if bpm_tag:
bpm_str = str(bpm_tag.text[0])
return int(float(bpm_str)) # Some BPMs are float strings
except Exception as e:
print(f"Could not read BPM from {file_path}: {e}")
return None
for file in dir_a.glob("*.mp3"):
bpm = get_bpm(file)
if bpm is not None:
lower_bound = (bpm // 5) * 5
upper_bound = lower_bound + 5
folder_name = f"{lower_bound}-to-{upper_bound}"
target_folder = dir_b / folder_name
target_folder.mkdir(exist_ok=True)
shutil.copy(file, target_folder / file.name)
print(f"Copied {file.name} to {folder_name}")
else:
print(f"No BPM found for {file.name}, skipping.")