Created
January 6, 2012 18:02
-
-
Save tremby/1571674 to your computer and use it in GitHub Desktop.
albumsbylength -- print out all albums in MPD library prefixed with their total length
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 characters
#!/usr/bin/env python | |
import mpd | |
HOST = "localhost" | |
PORT = 6600 | |
PASS = None | |
client = mpd.MPDClient() | |
client.connect(HOST, PORT) | |
if PASS: | |
client.password(PASS) | |
client.iterate = True | |
albums = {} | |
for song in client.listallinfo(): | |
try: | |
album = song["album"] | |
except KeyError: | |
continue | |
try: | |
artist = song["albumartist"] | |
except KeyError: | |
try: | |
artist = song["artist"] | |
except KeyError: | |
artist = "(unknown)" | |
try: | |
album = "%s -- %s (%s)" % (artist, album, song["date"][0:4]) | |
except KeyError: | |
pass | |
if not album in albums: | |
albums[album] = 0 | |
albums[album] += int(song["time"]) | |
client.close() | |
client.disconnect() | |
for album, length in albums.iteritems(): | |
print "%d:%02d\t%s" % (length / 60, length % 60, album) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment