Created
April 22, 2014 10:27
-
-
Save fatchat/11173351 to your computer and use it in GitHub Desktop.
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
# python 2.7 | |
import eyed3 | |
import argparse | |
# This uses the eyed3 library (http://eyed3.nicfit.net/) for Python | |
# eyed3 provides a command line tool to set your MP3 tags | |
# This script is useful for settings tags for multiple files at once | |
# The supported tags are the Artist and Album tags. Genre would be nice to add one day | |
# - rohit chatterjee | |
parser = argparse.ArgumentParser () | |
parser.add_argument("-r", "--artist") | |
parser.add_argument("-l", "--album") | |
parser.add_argument("-f", "--files", nargs='+', required=True) | |
args = parser.parse_args() | |
def ProcessFile (_file, artist, album): | |
#print ("file=[%s] artist=[%s] album=[%s]" %(_file, artist, album)) | |
try: | |
audiofile = eyed3.load(_file) | |
#print ("Artist=[%s],Album=[%s],Title=[%s]" % (audiofile.tag.artist, audiofile.tag.album, audiofile.tag.title)) | |
if (artist != None): | |
audiofile.tag.artist = artist | |
print("Setting artist tag of %s to %s" % (_file, artist)) | |
if (album != None): | |
audiofile.tag.album = album | |
print("Setting album tag of %s to %s" % (_file, album)) | |
audiofile.tag.save() | |
except Exception as e: | |
print ("Error opening file [%s], exception was %s" % (_file, e)) | |
# -- start -- | |
if (args.artist == None and args.album == None): | |
print("You must specify one of --artist and --album") | |
else: | |
for _file in args.files: | |
ProcessFile (_file.strip(), args.artist, args.album) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment