Skip to content

Instantly share code, notes, and snippets.

@np1
Last active December 27, 2015 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save np1/7281766 to your computer and use it in GitHub Desktop.
Save np1/7281766 to your computer and use it in GitHub Desktop.
Get current playing station and song (if available) from radiotray requires python-dbus
#!/usr/bin/python
import dbus
import pickle as pickle
jar = "/dev/shm/radiotray-now-playing"
dname = "net.sourceforge.radiotray"
dobj = "/net/sourceforge/radiotray"
def getsong():
lastsong = ""
laststation = ""
stalesong = False
try:
data = pickle.load(open(jar, "r"))
lastsong = data['song']
laststation = data['station']
stalesong = data['stalesong']
except (IOError, EOFError):
pass
sb = dbus.SessionBus()
proxy = sb.get_object(dname, dobj)
methodname = "getCurrentRadio"
method = proxy.get_dbus_method(methodname)
station = method()
methodname = "getCurrentMetaData"
method = proxy.get_dbus_method(methodname)
song = method()
if len(song.split(" - ")) == 3:
song = " - ".join(song.split(" - ")[1:])
if station != laststation and song == lastsong:
stalesong = True
if lastsong != song:
stalesong = False
data = dict(song=song, station=station, stalesong=stalesong)
pickle.dump(data, open(jar, "wb"), 2)
if not stalesong:
output = "%s: %s" % (station, song)
else:
output = station
if song.startswith(station):
output = song
return(output)
print(getsong())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment