Created
June 27, 2012 06:30
Revisions
-
There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,32 +1,36 @@ # Requires Mutagen: http://code.google.com/p/mutagen/wiki/Tutorial # sudo easy_install mutagen from mutagen.easyid3 import EasyID3 from mutagen import File import os, sys if len(sys.argv) < 2: print "Usage: python music-dump.py <path to music>" exit() # Walk through all directories recursively for root, _, files in os.walk(sys.argv[1]): # We will assume all files in a given directory are for that album coll = [] total_time = 0 for f in files: ext = os.path.splitext(f)[1] try: # The ID3 gives us all the information except the length, which we # use the mutagen filetype reader for. The ID3 returns are all lists # of length 1 for some reason. path = os.path.join(root, f) audio = File(path) info = EasyID3(path) length = int(audio.info.length) total_time += length coll.append("%02d %s - %s (%d:%02d)" % (int(info['tracknumber'][0]), info['artist'][0], info['title'][0], length/60, length%60)) except Exception as e: print "Error reading %s: %s" % (f, e) # Album name and full length print "%s (%d:%02d)" % (filter(lambda s: s != "", root.split('/'))[-1], total_time/60, total_time%60) # Tracks for track in sorted(coll): print track print -
There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ # Requires Mutagen: http://code.google.com/p/mutagen/wiki/Tutorial # sudo easy_install mutagen from mutagen.easyid3 import EasyID3 from mutagen.mp3 import MP3 from mutagen.m4a import M4A import os, sys supported_filetypes = { '.mp3': MP3, '.m4a': M4A, } if len(sys.argv) < 2: print "Usage: python music-dump.py <path to music>" exit() for root, _, files in os.walk(sys.argv[1]): print filter(lambda s: s != "", root.split('/'))[-1] coll = [] for f in files: ext = os.path.splitext(f)[1] if ext in supported_filetypes: reader = supported_filetypes[ext] audio = reader(os.path.join(root, f)) info = EasyID3(os.path.join(root, f)) length = audio.info.length coll.append("%02d %s - %s (%d:%02d)" % (int(info['tracknumber'][0]), info['artist'][0], info['title'][0], int(length)/60, int(length)%60)) for track in sorted(coll): print track print