Created
April 18, 2017 17:37
-
-
Save buckbaskin/cfc424dde56981a9ab4b7aeaa8436f84 to your computer and use it in GitHub Desktop.
A Python script that traverses an organized iTunes Music directory and enumerates the artists and albums in the library.
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
import os | |
def traverse(): | |
artists = None | |
for dirpath, dnames, fnames in os.walk("./Music/"): | |
if artists is None and len(dnames) > 0: | |
artists = {el:[] for el in dnames} | |
elif len(dnames) > 0: | |
head, tail = os.path.split(dirpath) | |
if tail not in artists: | |
artists[tail] = [] | |
artists[tail].extend(dnames) | |
list_artists = list(artists.iteritems()) | |
list_artists.sort(key=lambda tup: tup[0].lower()) | |
for artist, albums in list_artists: | |
if len(albums) > 0: | |
print 'a:', artist | |
for title in albums: | |
print ' -', title | |
if __name__ == '__main__': | |
traverse() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output: