one-file-projects/skipalbum.py

37 lines
926 B
Python

#!/usr/bin/env python
import mpd
from sys import argv,exit
host = "localhost"
port = 6600
if len(argv) > 1:
host = argv[1]
if len(argv) > 2:
try:
port = int(argv[2])
except Exception:
print("Port must be a number")
exit(1)
client = mpd.MPDClient(use_unicode=True)
try: #Connect
client.connect(host,port)
except SocketError:
print("Could not connect.")
exit(1)
firstsong = client.currentsong() #Get current song
if firstsong != {}: #Is there a song playing
client.next() #Skip it
currentsong = client.currentsong() #Get next song
while currentsong != {} and firstsong['artist'] == currentsong['artist'] and firstsong['album'] == currentsong['album']: #A song available and song still from same album
client.next() #Skip it
currentsong = client.currentsong() #Get next song
#Album skipped or playlist ended.
client.disconnect() #Disconnect :)