#!/usr/bin/env python from mutagen.easyid3 import EasyID3 import os, sys if len(sys.argv) != 4: sys.exit("usage: transmtp.py ") else: filename = sys.argv[3] try: audio = EasyID3(filename) except: sys.exit("Could not open file: " + filename) foldername = sys.argv[1] duration = sys.argv[2] path = filename title = str(audio['title'])[3:-2] artist = str(audio['artist'])[3:-2] album = str(audio['album'])[3:-2] genre = str(audio['genre'])[3:-2] tracknum = str(audio['tracknumber'])[3:-2] try: year = str(audio['year'])[3:-2] except: try: year = str(audio['date'])[3:-2] except KeyError: year = '0' print "**Could not read year/date**" except ValueError: year = '0' print "**Could not read year/date**" command = 'mtp-sendtr -t "' + title + '" -a "' + artist + '" -l "' + album + '" -c "mp3" -g "' + genre + '" -n "' + tracknum + '" -y "' + year + '" -d "' + duration + '" -f "' + foldername + '" "' + path + '"' print command inp = raw_input("Continue? ") if inp.lower() == 'no' or inp.lower() == 'n' or inp.lower() == 'q' or inp.lower() == 'quit': sys.exit(0) os.system(command)