-
Notifications
You must be signed in to change notification settings - Fork 0
/
mplayer_icy_notifier.py
executable file
·43 lines (39 loc) · 1.27 KB
/
mplayer_icy_notifier.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/python2
# Author: Reynaldo Baquerizo <reynaldomic@gmail.com>
# Date: August 2010
from __future__ import print_function
import sys
import time
import errno
import signal
import subprocess
def read_and_notify(mplayerfd, output=None):
current_song = None
def handler(num, stack):
if current_song:
print("You requested current song's title:", current_song,
file=sys.stderr)
if output:
output.writelines('[' + time.asctime() + ']' + " " + current_song + "\n")
output.flush()
args = ["notify-send", "Current song:\n" + current_song]
subprocess.call(args)
# Register the handler
signal.signal(signal.SIGUSR1, handler)
while True:
try:
line = mplayerfd.readline()
if "ICY" in line:
start = line.find("=") + 1
end = line.find(";")
current_song = line[start:end]
print(current_song)
except IOError as detail:
if not detail.errno == errno.EINTR:
raise
except KeyboardInterrupt:
output.close()
break
if __name__ == "__main__":
output = open(".favorites.song", "a")
read_and_notify(sys.stdin, output)