Python Id3 Tag From Containing Folder
Join the DZone community and get the full member experience.Join For Free
// Total noob python script for renaming the 'album' tag in an untagged mp3 file. I plug it into podnova (using advanced -> run command) as it downloads my podcasts so that they get sorted correctly when I copy them onto my ipod. PodNova organizes podcasts by folder. the iPod organizes podcasts by album tag. If you use GtkPod to copy podcasts from PodNova, this can help keep mp3 podcasts categorized properly.
#!/usr/bin/python import sys # requires ID3 module, easily googled from ID3 import * for arg in sys.argv: fullfilename = arg # This only works for mp3 files, I would love suggestions for mp4 tags id3info = ID3(fullfilename) # Print command useful for logging. print id3info # Check if album info exists if not id3info.has_key('ALBUM'): print 'appending album tag' # truncate to just containing directory: folder = fullfilename[1:rfind(fullfilename,'/')] # define album based on podcast's directory album = (folder[rfind(folder,'/'):]).strip('/') id3info.album = album if id3info.album == album: print 'success!' else: print 'nothing to change'
Opinions expressed by DZone contributors are their own.