Created
October 17, 2013 19:01
-
-
Save blacklight/7030355 to your computer and use it in GitHub Desktop.
Script for loading and playing a random album from your MPD playlist using python-mpd2 API
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/python | |
from mpd import MPDClient | |
from random import randint, shuffle | |
client = MPDClient() | |
client.connect('localhost', 6600) | |
albums = client.list("album") | |
shuffle(albums) | |
randAlbum = albums[randint(0, len(albums)-1)] | |
artists = client.list("artist", "album", randAlbum) | |
if len(artists) > 1: | |
artist = artists[randint(0, len(artists)-1)] | |
else: | |
artist = artists[0] | |
files = client.list("filename", "album", randAlbum) | |
client.clear() | |
for file in files: | |
client.add(file) | |
client.play() | |
print("Playing \"%s - %s\"" % (artist, randAlbum)) | |
client.close() | |
client.disconnect() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment