diff --git a/README.md b/README.md index efb52ece..25e9a4d7 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ Clipboard is **"rubber"**. There is an accumulation before the insertion! * **Ctrl + L** - parental lock. * **Ctrl + H** - hide/skip. * **Ctrl + P** - start play IPTV or other stream in the bouquet list. +* **Ctrl + W** - switch to the channel and watch in the program. * **Ctrl + Z** - switch(**zap**) the channel(works when the HTTP API is enabled, Enigma2 only). * **Space** - select/deselect. * **Left/Right** - remove selection. diff --git a/app/connections.py b/app/connections.py index 07180935..4b958902 100644 --- a/app/connections.py +++ b/app/connections.py @@ -34,6 +34,7 @@ class HttpRequestType(Enum): ZAP = "zap?sRef=" INFO = "about" SIGNAL = "tunersignal" + STREAM = "streamcurrentm3u" class TestException(Exception): @@ -267,10 +268,15 @@ def http_request(host, port, user, password): url = base_url + HttpRequestType.INFO.value elif req_type is HttpRequestType.SIGNAL: url = base_url + HttpRequestType.SIGNAL.value + elif req_type is HttpRequestType.STREAM: + url = base_url + HttpRequestType.STREAM.value try: with urlopen(url, timeout=5) as f: - yield json.loads(f.read().decode("utf-8")) + if req_type is HttpRequestType.STREAM: + yield f.read().decode("utf-8") + else: + yield json.loads(f.read().decode("utf-8")) except (URLError, HTTPError): yield None diff --git a/app/ui/main_app_window.py b/app/ui/main_app_window.py index c8b71c06..7a5d730c 100644 --- a/app/ui/main_app_window.py +++ b/app/ui/main_app_window.py @@ -1057,6 +1057,8 @@ class Application(Gtk.Application): elif ctrl and model_name == self._FAV_LIST_NAME: if key is KeyboardKey.P: self.on_play_stream() + if key is KeyboardKey.W: + self.on_zap(self.on_watch) if key is KeyboardKey.Z: self.on_zap() elif key is KeyboardKey.CTRL_L or key is KeyboardKey.CTRL_R: @@ -1368,19 +1370,37 @@ class Application(Gtk.Application): GLib.timeout_add_seconds(1, self.update_receiver_info) @run_idle - def on_zap(self): + def on_watch(self): + """ Switch to the channel and watch in the player """ + m3u = self._http_api.send((HttpRequestType.STREAM, None)) + next(self._http_api) + 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]) + + @run_task + def on_zap(self, callback=None): + """ Switch(zap) the channel """ path, column = self._fav_view.get_cursor() if not path or not self._http_api: return + if self._player and self._player.is_playing(): + self._player.stop() + row = self._fav_model[path][:] srv = self._services.get(row[-2], None) if srv and srv.transponder: ref = srv.picon_id.rstrip(".png").replace("_", ":") + req = self._http_api.send((HttpRequestType.ZAP, ref)) next(self._http_api) if req and req.get("result", False): GLib.timeout_add_seconds(2, self.update_service_info) + GLib.idle_add(scroll_to, path, self._fav_view) + if callback is not None: + callback() @run_task def update_receiver_info(self): diff --git a/app/ui/uicommons.py b/app/ui/uicommons.py index 17d383a9..e0918034 100644 --- a/app/ui/uicommons.py +++ b/app/ui/uicommons.py @@ -39,6 +39,7 @@ class KeyboardKey(Enum): X = 53 C = 54 V = 55 + W = 25 Z = 52 INSERT = 118 HOME = 110