#!/usr/bin/python import sys, os, cddbsearch, pyid3lib """ Simple MP3 tagging script. Finds results of an album via CDDB. If specified with a -t tag, it will prompt you to choose a result. After returning the tracknames of that result, it will prompt you to tag the mp3s. """ if len(sys.argv) < 2: print "\nSyntax d.py -t \n" else: if len(sys.argv) > 2: tag = 1 dir = sys.argv[2] else: tag = 0 dir = sys.argv[1] if os.path.isdir(dir): cddb = cddbsearch.cddbsearch(dir) results = cddb.search() print "Found ", len(results), " results for " + cddb.discid + ":" x = 1 for i in results: print " [" + str(x) + "] " + " " + i['cddbid'] + " " + i['title'] x = x + 1 if tag: choice = raw_input("Pick a result (0 to exit): ") choice = int(choice) - 1 else: choice = -1 if choice != -1: x = 0 cddb.getResult(results[choice]['genre'], results[choice]['cddbid']) artist = results[choice]['title'].split(' / ')[0] album = results[choice]['title'].split(' / ')[1] total_tracks = len(cddb.tracknames) for track in cddb.tracknames: print track tag = raw_input("Tag? y/n: ") if tag.lower() == 'y': files = [] for file in os.listdir(dir): (name, ext) = os.path.splitext(file) if ext.lower() == '.mp3': files.append(os.path.join(dir, file)) files.sort() for file in files: mp3 = pyid3lib.tag(file) mp3.artist = artist mp3.album = album mp3.title = cddb.tracknames[x] mp3.track = (x+1, total_tracks) mp3.update() x = x + 1