Last active
December 19, 2015 03:38
-
-
Save moopet/5891330 to your computer and use it in GitHub Desktop.
Just a quick hack to listen to xPL notifications and display them on screen. If you activate the xPL plugin on your squeezebox then you can get "now playing" popups. You can always replace pynotify with growl or whatever you use.
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 select | |
import socket | |
import sys | |
import re | |
import pynotify | |
MAX_MESSAGE_SIZE = 1500 | |
XPL_PORT = 3865 | |
UDPSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
try: | |
UDPSock.bind(("0.0.0.0", XPL_PORT)) | |
except: | |
print "Couldn't bind to xPL port" | |
sys.exit(1) | |
pynotify.init("Now Playing") | |
while True: | |
readable, writeable, exceptional = select.select([UDPSock], [], []) | |
last_message = "" | |
if len(readable) == 1: | |
data, addr = UDPSock.recvfrom(MAX_MESSAGE_SIZE) | |
artist = re.search("^ARTIST=(.+)$", data, re.MULTILINE) | |
album = re.search("^ALBUM=(.+)$", data, re.MULTILINE) | |
track = re.search("^TRACK=(.+)$", data, re.MULTILINE) | |
message = artist.group(1) if artist is not None else "" | |
if album is not None: | |
message += "\n" + album.group(1) | |
if track is not None: | |
message += "\n" + track.group(1) | |
if len(message) > 0 and message != last_message: | |
notice = pynotify.Notification('Now Playing', message) | |
notice.show() | |
last_message = message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment