Skip to content

AaryanDahalNp/music-library-cleaner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Music Library Cleaner

A lightweight Python script to remove numeric prefixes from audio filenames in your music library.

What It Does

Removes numeric prefixes like 001 , 042 , 123 from MP3 and M4A files:

001 Ae Dil Hai Mushkil.mp3  →  Ae Dil Hai Mushkil.mp3
042 Ilahi.mp3               →  Ilahi.mp3

If the non-prefixed filename already exists, the numbered version is deleted.

What It Does NOT Do

  • Fix capitalization inconsistencies
  • Normalize spacing around hyphens or special characters
  • Handle other file formats (only .mp3 and .m4a)
  • Rename files with non-numeric prefixes

⚠️ Warning

This script can permanently delete files. Always run in DRY RUN mode first.

Installation

No dependencies required. Just Python 3.6+.

git clone https://github.com/Aaryan-source/music-library-cleaner.git
cd music-library-cleaner

Usage

Step 1: Dry Run (Safe)

python music_library_cleaner.py

This shows what would happen without making changes:

=== DRY RUN MODE (no changes will be made) ===

[RENAME] 001 Song.mp3 → Song.mp3
[DUPLICATE] Keeping: Another Song.mp3
[DUPLICATE] Removing: 042 Another Song.mp3

Scan complete.
Directory entries scanned: 245
Files renamed: 120
Duplicates removed: 3

Step 2: Actually Run (Destructive)

  1. Open music_library_cleaner.py
  2. Change line 11:
    DRY_RUN = False  # Was True
  3. Run again:
    python music_library_cleaner.py

How It Works

  1. Scans the current directory for .mp3 and .m4a files
  2. Identifies files starting with digits followed by a space (e.g., ^\d+ )
  3. Removes the numeric prefix
  4. If a conflict exists, deletes the numbered version and keeps the non-numbered one

Important: When a duplicate is detected, the script assumes the non-prefixed filename is the desired version and removes the numbered file. If you want to keep the numbered version instead, rename it manually before running the script.

Configuration

Edit these constants at the top of the script:

DRY_RUN = True                          # Safety switch
SUPPORTED_EXTENSIONS = ('.mp3', '.m4a') # Add more if needed

Example Output

=== DRY RUN MODE (no changes will be made) ===

[RENAME] 001 Ae Dil Hai Mushkil -Arijit Singh.mp3 → Ae Dil Hai Mushkil -Arijit Singh.mp3
[RENAME] 003 Alec Benjamin -Let Me Down Slowly.mp3 → Alec Benjamin -Let Me Down Slowly.mp3
[DUPLICATE] Keeping: Give Me Some Sunshine -3 Idiots.mp3
[DUPLICATE] Removing: 037 Give Me Some Sunshine -3 Idiots.mp3

Scan complete.
Directory entries scanned: 245
Files renamed: 187
Duplicates removed: 5

Safety Features

  • Dry run by default: Must explicitly disable to make changes
  • Clear logging: Every action is printed before execution
  • Duplicate detection: Won't overwrite existing files
  • File type filtering: Only processes audio files

License

MIT License - feel free to use and modify.

Contributing

This is a simple personal utility script, but suggestions are welcome! Open an issue or PR.


Pro tip: Always backup your music library before running any batch rename tool.

About

Safe Python utility to clean numeric prefixes from audio filenames

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages