Skip to content

Instantly share code, notes, and snippets.

@oz123
Last active December 24, 2015 12:19
Show Gist options
  • Save oz123/6797264 to your computer and use it in GitHub Desktop.
Save oz123/6797264 to your computer and use it in GitHub Desktop.
Rppy - my little script to enjoy Radio Paradise. The script uses mplayer to play and libnotify to send messages with the song information to the desktop notification area. I tested it on Debian and Mate-Desktop
from subprocess import Popen
import pty
import os
import sys
import pynotify
def parse_ICY(line):
aline = line.split('\r\n')[-1]
junk, info = aline.split('=', 1)
try:
info, junk = info.split(';', 1)
except ValueError:
pass
artist, title = info.split('-')
return artist.strip("'"), title.strip("'")
cmd = ['mplayer',
'-playlist', 'http://www.radioparadise.com/musiclinks/rp_128aac.m3u']
if sys.argv[1:]:
cmd = cmd[:1] + sys.argv[1:] + cmd[1:]
master, slave = pty.openpty()
proc = Popen(cmd, stdout=slave, stderr=slave)
stdout = os.fdopen(master)
ICYSTRING = ''
while True:
line = stdout.readline(1)
ICYSTRING = ICYSTRING + line
if 'ICY Info' in ICYSTRING:
for i in range(80):
ICYSTRING = ICYSTRING + stdout.readline(1)
a, t = parse_ICY(ICYSTRING)
ICYSTRING = ''
n = pynotify.Notification(a, t)
n.set_timeout(10000) # 10 sec
n.set_category("device")
pynotify.init("Timekpr notification")
n.show()
pynotify.uninit()
ICYSTRING = ''
sys.stdout.write(line)
# See screenshot here http://imgur.com/LsZ9NfP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment