Created
July 16, 2014 11:57
-
-
Save v0i0/550fdacf838688c75fdf to your computer and use it in GitHub Desktop.
python script to tag mp3 files by directory structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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