Reputation:
Re-organizing a large MP3 library for my friend's MP3 Player, I have the need to name the Title ID3 tag the same as the file name, and doing this via Windows Properties takes forever, so I was wondering if anyone has an idea of how to make a Python script that does this to all MP3's in a directory in rapid succession. Or at least a link to a library installable on Windows.
Upvotes: 8
Views: 17316
Reputation: 430
Digging this out because it is still a topic (17k views) and packages linked here are out-dated.
As of 10/2023 a quick search showed:
Possible duplicate: ID3-mp3 editing in python - up-to-date package?
Upvotes: 0
Reputation: 2016
Here is a python script I wrote to do this https://gitlab.com/tomleo/id3_folder_rename
#! /usr/bin/python
import os
import re
import glob
import subprocess
from mutagen.easyid3 import EasyID3
path = os.getcwd()
fpath = u"%s/*.mp3" % path
files = glob.glob(fpath)
for fname in files:
_track = EasyID3(fname)
track_num = _track.get('tracknumber')[0]
track_title = re.sub(r'/', '_', _track.get('title')[0])
if '/' in track_num:
track_num = track_num.split('/')[0]
if len(track_num) == 1:
track_num = "0%s" % track_num
_valid_fname = u"%s/%s %s.mp3" % (path, track_num, track_title)
if fname != _valid_fname:
subprocess.call(["/bin/mv", fname, _valid_fname])
It uses the mutagen python library for parsing the ID3 info. You'll have to tweak the subprocess call it to make it work with windows, but this should give you an idea for how to do it. Hope this helps.
Upvotes: 4
Reputation: 2154
Look at this:
Also Dive Into Python uses MP3 ID3 tags as an example.
Don't forget about PyPI - the Python Package Index.
Upvotes: 10