Skip to content

Instantly share code, notes, and snippets.

@blacklight
Created October 17, 2013 19:01
Show Gist options
  • Save blacklight/7030355 to your computer and use it in GitHub Desktop.
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
#!/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