Skip to content

Instantly share code, notes, and snippets.

@v0i0
Created July 16, 2014 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save v0i0/550fdacf838688c75fdf to your computer and use it in GitHub Desktop.
Save v0i0/550fdacf838688c75fdf to your computer and use it in GitHub Desktop.
python script to tag mp3 files by directory structure
from mutagen.mp3 import MP3
from mutagen.id3 import TIT2, TPE1, TALB
import os
import sys
for artist in sys.argv[1:]:
print 'artist=%s' % artist
for root, directories, filenames in os.walk(artist):
print 'Entering %s' % root
album = os.path.basename(root)
for filename in filenames:
title, ext = os.path.splitext(filename)
if ext.upper() == '.MP3':
print 'Found %s' % title
try:
audio = MP3(root + '/' + filename)
audio["TIT2"] = TIT2(encoding=3, text=title)
audio["TPE1"] = TPE1(encoding=3, text=artist)
audio["TALB"] = TALB(encoding=3, text=album)
audio.save()
except:
print 'Failed to tag %s' % filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment