Description
This script can be placed in a folder and when it runs, it scans all the mp3 files contained in the subfolders. Once eveything is scanned, it displays a list of folders that has mp3 files with a bitrate below 300 kbps.
Before running, the library mutagen must be installed:
pip install mutagenCode
import os
from mutagen.mp3 import MP3
def check_mp3_bitrate(base_folder, threshold=300):
low_bitrate_folders = []
for root, _, files in os.walk(base_folder):
contains_low_bitrate = False
for file in files:
if file.lower().endswith(".mp3"):
file_path = os.path.join(root, file)
try:
audio = MP3(file_path)
bitrate = audio.info.bitrate // 1000 # Convert to kbps
if bitrate < threshold:
contains_low_bitrate = True
except Exception as e:
print(f"Error processing file: {file_path}, Error: {e}")
if contains_low_bitrate:
relative_path = os.path.relpath(root, base_folder)
low_bitrate_folders.append(relative_path.replace(os.sep, " > "))
if low_bitrate_folders:
print("\nFolders containing MP3 files with bitrate below", threshold, "kbps:")
for folder in low_bitrate_folders:
print(folder)
else:
print("No folders found with MP3 files below the specified bitrate.")
if __name__ == "__main__":
base_folder = os.getcwd()
print(f"Scanning folder: {base_folder}")
check_mp3_bitrate(base_folder)