diff options
Diffstat (limited to 'icy-info.py')
-rwxr-xr-x | icy-info.py | 60 |
1 files changed, 41 insertions, 19 deletions
diff --git a/icy-info.py b/icy-info.py index f2db039..14ed558 100755 --- a/icy-info.py +++ b/icy-info.py @@ -14,10 +14,6 @@ import select import sys import time -# quite long, because it's only a fallback, and you don't -# want to overwrite real ICY info -wait_timeout=600 - re_icy = re.compile(r"""ICY Info: StreamTitle='([^']*)'.*""") if len(sys.argv) < 3: @@ -43,29 +39,55 @@ def new_dlstext(text): fd.write(text) fd.close() +wait_timeout = 5 +nodls_timeout = 0 + while True: - rfds, wfds, efds = select.select( [sys.stdin], [], [], wait_timeout) + # readline is blocking, therefore we cannot send a default text + # after some timeout + new_data = sys.stdin.readline() + if not new_data: + break + + match = re_icy.match(new_data) + + if match: + artist_title = match.groups()[0] + new_dlstext(artist_title) + else: + print("{}".format(new_data.strip())) + +if False: + # The select call creates a one ICY delay, and it's not clear why... + while True: + rfds, wfds, efds = select.select( [sys.stdin], [], [], wait_timeout) - if rfds: - # new data available on stdin - new_data = sys.stdin.readline() + if rfds: + # new data available on stdin + print("SELECT !") + new_data = sys.stdin.readline() + print("DATA ! {}".format(new_data)) - if not new_data: - break + if not new_data: + break - match = re_icy.match(new_data) + match = re_icy.match(new_data) + + if match: + artist_title = match.groups()[0] + new_dlstext(artist_title) + else: + print("{}".format(new_data.strip())) - if match: - artist_title = match.groups()[0] - new_dlstext(artist_title) else: - print("{}".format(new_data.strip())) + # timeout reading stdin + nodls_timeout += 1 - else: - # timeout reading stdin - new_dlstext("") + if nodls_timeout == 100: + new_dlstext("") + nodls_timeout = 0 - time.sleep(.1) + time.sleep(.1) |