Files
Folder-By-BPM/src/app.py

39 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import shutil
from mutagen.id3 import ID3, TBPM
from pathlib import Path
# Define source (dir A) and destination (dir B) directories
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")
# Make sure destination base 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 floats or strings
except Exception as e:
print(f"[!] Error reading BPM from {file_path.name}: {e}")
return None
for file in dir_a.glob("*.mp3"):
bpm = get_bpm(file)
if bpm is not None:
# Calculate non-overlapping 5-BPM bin
lower_bound = (bpm // 5) * 5
upper_bound = lower_bound + 4 # Inclusive range: e.g., 130134
folder_name = f"{lower_bound}-to-{upper_bound}"
target_folder = dir_b / folder_name
target_folder.mkdir(exist_ok=True)
target_file = target_folder / file.name
shutil.copy(file, target_file)
print(f"[+] Copied {file.name} to {folder_name}")
else:
print(f"[-] No BPM found for {file.name}, skipping.")