Skip to content

Instantly share code, notes, and snippets.

@lardissone
Created July 8, 2013 20:17
Show Gist options
  • Save lardissone/5952123 to your computer and use it in GitHub Desktop.
Save lardissone/5952123 to your computer and use it in GitHub Desktop.
List all artists in a MP3 directory and subdirectories
from os import walk
from mutagen.mp3 import MP3
mypath = '/Volumes/Macintosh HD/Media/Music/iTunes/'
mypath = '/Volumes/Media HD/MP3/'
f = []
artists = []
a = 0
b = 0
output = open('output.txt', 'w')
for (dirpath, dirnames, filenames) in walk(mypath):
#b += 1
if filenames:
for fn in filenames:
if '.mp3' in fn:
filepath = '%s/%s' % (dirpath, fn)
try:
audio = MP3(filepath)
artist = audio['TPE1'].text[0]
if artist not in artists:
a += 1
print a, artist
artists.append(artist)
output.write('%s\n' % artist)
except:
pass
#if b == 20:
# break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment