Automated MP3 tags updation with python

Had a wonderful song collection of Old hindi songs, in the format of “somenumber title (moviename).mp3”. Had to find way to update the ID3 tag info. Opensource to help yet again.

Installed a module named python-id3, Using yum install python-id3. Then wrote a small script in python using regular expressions, glob and the newly installed MP3 ID3 tagging module

#!/bin/env python

import os, glob, re, sys
from ID3 import *

def strip(str):
	return str.lstrip().rstrip()

mp3s = glob.glob('*.mp3')

r = re.compile('([\d]+(([\s])*?[\w\s]+)\s?(\((.*?)\)?)?)\.mp3', re.I)

i = 1
for mp3 in mp3s:
	print str(i) + ": " + mp3
	gr = r.match(mp3)
	#print gr.groups()

	id3info = ID3(open(mp3, 'r+b'), mp3)
	title = ''
	album = ''
		if (len(gr.groups()) >= 4):
			print "Title: %s, Album: %s" % (strip(, strip(
			title = strip(
			album = strip(
			print "Title: %s" % (strip(
			title = strip(
		id3info.title = title
		id3info.album = album
		id3info.genre = 'Old Hindi'
		id3info.artist = ''
		print sys.exc_info()
	i = i + 1

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.