diff options
| author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-07-21 22:03:18 +0200 |
|---|---|---|
| committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-07-21 22:03:18 +0200 |
| commit | 56bf00060ff4ca9feb1c6795693ca3585bd9f758 (patch) | |
| tree | a36053423868b4558179c267d0f1bdfb19d95554 | |
| parent | cf77b741f4e4746aca8248eac2e7d5d86e1e33e4 (diff) | |
| download | mmbtools-aux-56bf00060ff4ca9feb1c6795693ca3585bd9f758.tar.gz mmbtools-aux-56bf00060ff4ca9feb1c6795693ca3585bd9f758.tar.bz2 mmbtools-aux-56bf00060ff4ca9feb1c6795693ca3585bd9f758.zip | |
icy-info: disable select call
| -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) |
