diff --git a/app/connections.py b/app/connections.py index df11647f..66101273 100644 --- a/app/connections.py +++ b/app/connections.py @@ -361,8 +361,11 @@ class HttpAPI: elif req_type is HttpRequestType.PLAY or req_type is HttpRequestType.PLAYER_REMOVE: url += "{}{}".format(ref_prefix, urllib.parse.quote(ref).replace("%3A", "%253A")) + def done_callback(f): + callback(f.result()) + future = self._executor.submit(get_response, req_type, url, self._data) - future.add_done_callback(lambda f: callback(f.result())) + future.add_done_callback(done_callback) @run_task def init(self): @@ -386,7 +389,7 @@ def get_response(req_type, url, data=None): try: with urlopen(Request(url, data=data), timeout=10) as f: if req_type is HttpRequestType.STREAM or req_type is HttpRequestType.STREAM_CURRENT: - return f.read().decode("utf-8") + return {"m3u": f.read().decode("utf-8")} elif req_type is HttpRequestType.CURRENT: for el in ETree.fromstring(f.read().decode("utf-8")).iter("e2event"): return {el.tag: el.text for el in el.iter()} # return first[current] event from the list diff --git a/app/ui/main_app_window.py b/app/ui/main_app_window.py index 9a97eead..9547002f 100644 --- a/app/ui/main_app_window.py +++ b/app/ui/main_app_window.py @@ -1854,12 +1854,11 @@ class Application(Gtk.Application): else: self._http_api.send(HttpRequestType.STREAM_CURRENT, None, self.record) - def record(self, m3u): - if m3u: - url = [s for s in m3u.split("\n") if not s.startswith("#")] - if url: - self._recorder.record(url[0], self._service_name_label.get_text()) - GLib.timeout_add_seconds(1, self.update_record_button, priority=GLib.PRIORITY_LOW) + def record(self, data): + url = self.get_url_from_m3u(data) + if url: + self._recorder.record(url, self._service_name_label.get_text()) + GLib.timeout_add_seconds(1, self.update_record_button, priority=GLib.PRIORITY_LOW) def update_record_button(self): is_rec = self._recorder.is_record() @@ -1924,11 +1923,20 @@ class Application(Gtk.Application): """ Switch to the channel and watch in the player """ self._http_api.send(HttpRequestType.STREAM_CURRENT, None, self.watch) - def watch(self, m3u): + def watch(self, data): + url = self.get_url_from_m3u(data) + if url: + GLib.timeout_add_seconds(1, self.play, url) + + def get_url_from_m3u(self, data): + error_code = data.get("error_code", 0) + if error_code or self._http_status_image.get_visible(): + self.show_error_dialog("No connection to the receiver!") + return + + m3u = data.get("m3u", None) if m3u: - url = [s for s in m3u.split("\n") if not s.startswith("#")] - if url: - GLib.timeout_add_seconds(1, self.play, url[0]) + return [s for s in m3u.split("\n") if not s.startswith("#")][0] @run_idle def on_zap(self, callback=None): diff --git a/app/ui/main_window.glade b/app/ui/main_window.glade index 56997870..85c2228d 100644 --- a/app/ui/main_window.glade +++ b/app/ui/main_window.glade @@ -2900,7 +2900,7 @@ Author: Dmitriy Yefremov False - No connection to the receiver + No connection to the receiver! 10 10 network-offline