Audio File Renamer
A Python command-line tool for batch renaming and tagging audio files with DJ-friendly metadata. Cleans filenames, normalizes formatting, removes domains, and writes standardized comment tags.
Overview
As a DJ, I found myself constantly dealing with poorly formatted audio filenames from various sources – duplicate prefixes, all-caps titles, embedded URLs, and inconsistent formatting. This tool was born from the need to maintain a clean, organized music library that works seamlessly with DJ software like Rekordbox, Serato, and Traktor.
The renamer automates the tedious process of cleaning up hundreds of files at once, while also writing standardized metadata tags that persist across platforms and software.
Key Features
- →Prefix Normalization: Automatically converts single-letter prefixes like [B9] to double-letter format [BB9] for consistency
- →Domain Removal: Strips out URLs and domain names from filenames (e.g., "Track Name - website.com" becomes "Track Name")
- →Case Normalization: Converts ALL-CAPS and inconsistent casing to clean Title Case
- →DJ-Friendly Tags: Writes metadata to MP3 (COMM + TXXX), FLAC, and M4A/AAC formats compatible with major DJ software
- →Batch Processing: Processes entire directories at once with dry-run mode for safety
- →Flexible Tagging: Prepend or replace existing comments, skip tagging entirely if needed
Installation
Requirements
- • Python 3.7+
- • mutagen library for audio metadata handling
pip install mutagenUsage
Basic Usage
python renamer.py /path/to/music/folderCommand Options
--dry-runPreview changes without modifying files. Highly recommended for first run!
python renamer.py /music --dry-run--no-tagsOnly rename files without writing metadata tags
python renamer.py /music --no-tags--replace-commentsReplace existing comment tags instead of prepending
python renamer.py /music --replace-commentsExamples
Filename Transformations
[B9] ARTIST NAME - TRACK TITLE (beatport.com).mp3[BB9] Artist Name - Track Title.mp3some track from soundcloud.com (www.example.net).flacSome Track From.flacWorkflow Example
# 1. Preview changes first
python renamer.py ~/Music/NewTracks --dry-run
# 2. Execute rename and tag
python renamer.py ~/Music/NewTracks
# 3. If you only want to rename (no tags)
python renamer.py ~/Music/NewTracks --no-tagsHow It Works
Processing Pipeline
- 1.Pattern Detection: Identifies existing prefix patterns using regex ([B9], [BB9], etc.)
- 2.Domain Removal: Strips URLs, domains, and website references from filenames
- 3.Case Normalization: Detects all-caps text and converts to Title Case
- 4.Prefix Standardization: Ensures double-letter prefix format for consistency
- 5.File Renaming: Safely renames files (skips if target exists)
- 6.Metadata Writing: Writes comment tags in DJ-friendly format for each file type
Supported Formats
- • COMM frame (eng, "")
- • COMM frame (eng, "comment")
- • TXXX:COMMENT
- • COMMENT tag
- • DESCRIPTION tag
- • ©cmt atom
Development Story
This tool emerged from my frustration managing a growing DJ music library. After downloading tracks from various sources (Beatport, Bandcamp, SoundCloud, promotional emails), I'd end up with hundreds of files with inconsistent naming conventions, promotional URLs embedded in filenames, and varying case styles.
The breaking point came when importing a new batch of 300+ tracks into Rekordbox. The library view was a mess – some tracks were all caps, others had [B9] and [BB9] prefixes mixed together, and URLs cluttered the display. Manual renaming would have taken hours.
I initially built a simple rename script, but quickly realized the filenames would revert after reimporting from USB drives or syncing across devices. That's when I dove into the Mutagen library to understand audio metadata standards. The challenge was making tags work consistently across different DJ software – each platform (Rekordbox, Serato, Traktor) has slightly different metadata preferences.
The solution writes multiple metadata fields to ensure maximum compatibility. For MP3s, it writes both COMM frames (standard comments) and TXXX frames (extended text), covering all bases. The tool has processed over 10,000 files in my library and has become an essential part of my DJ workflow.
Technical Implementation
Key Dependencies
- •mutagen: Audio metadata manipulation (ID3, FLAC, MP4 tags)
- •re (regex): Pattern matching for prefixes, domains, and text cleanup
- •os/sys: File system operations and CLI argument handling
Core Functions
transform_name()Main transformation logic for filename cleaning
normalize_case()Converts text to Title Case, handles all-caps detection
remove_domains()Strips URLs and domains using regex patterns
write_comment_tag()Handles metadata writing for different audio formats