Skip to content

Instantly share code, notes, and snippets.

@kennydude
Created August 19, 2011 13:38
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kennydude/1156807 to your computer and use it in GitHub Desktop.
Fix tags
'''
Problem tags?
For now it only fixes ogg files, sorry!
Just run it where it's just under your music folder or modify the code as needed
'''
print "TAG FIXER!"
import glob, subprocess, os, mutagen
from mutagen.easyid3 import EasyID3
daglob = glob.glob('./Music/*/*/*.mp3') + glob.glob('./Music/*/*/*.ogg')
for f in daglob:
parts = f.split('/')
try:
fmt = f.split('.')[-1]
if fmt == "mp3":
tags = EasyID3(f)
else:
tags = mutagen.File(f)
if tags.get('artist', None) == None:
print "E with ", f, " I will fix that for you right now"
if fmt == "ogg":
print "ogg fixer. tags will be guesed"
print "a ", parts[-3]
tags.update({
"artist" : parts[-3],
"album" : parts[-2],
"title" : parts[-1].split('.', 2)[0],
})
tags.save()
except Exception as e:
print "ERORR with Header", e, f
print "Your tags should now be in check"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment