small rework of screenshot mode

This commit is contained in:
DYefremov
2020-06-08 19:32:18 +03:00
parent b4fb684af4
commit 105b907392
2 changed files with 21 additions and 5 deletions

View File

@@ -51,7 +51,7 @@ class HttpRequestType(Enum):
PLAYER_PREV = "mediaplayercmd?command=previous" PLAYER_PREV = "mediaplayercmd?command=previous"
PLAYER_STOP = "mediaplayercmd?command=stop" PLAYER_STOP = "mediaplayercmd?command=stop"
PLAYER_REMOVE = "mediaplayerremove?file=" PLAYER_REMOVE = "mediaplayerremove?file="
GRUB = "grab?format=jpg&mode=" GRUB = "grab?format=jpg&"
class TestException(Exception): class TestException(Exception):
@@ -329,6 +329,7 @@ class HttpAPI:
self._main_url = None self._main_url = None
self._base_url = None self._base_url = None
self._data = None self._data = None
self._is_owif = True
self.init() self.init()
from concurrent.futures import ThreadPoolExecutor as PoolExecutor from concurrent.futures import ThreadPoolExecutor as PoolExecutor
@@ -339,18 +340,20 @@ class HttpAPI:
return return
url = self._base_url + req_type.value url = self._base_url + req_type.value
data = self._data
if req_type is HttpRequestType.ZAP or req_type is HttpRequestType.STREAM: if req_type is HttpRequestType.ZAP or req_type is HttpRequestType.STREAM:
url += urllib.parse.quote(ref) url += urllib.parse.quote(ref)
elif req_type is HttpRequestType.PLAY or req_type is HttpRequestType.PLAYER_REMOVE: elif req_type is HttpRequestType.PLAY or req_type is HttpRequestType.PLAYER_REMOVE:
url += "{}{}".format(ref_prefix, urllib.parse.quote(ref).replace("%3A", "%253A")) url += "{}{}".format(ref_prefix, urllib.parse.quote(ref).replace("%3A", "%253A"))
elif req_type is HttpRequestType.GRUB: elif req_type is HttpRequestType.GRUB:
data = None # Must be disabled for token-based security.
url = "{}/{}{}".format(self._main_url, req_type.value, ref) url = "{}/{}{}".format(self._main_url, req_type.value, ref)
def done_callback(f): def done_callback(f):
callback(f.result()) callback(f.result())
future = self._executor.submit(get_response, req_type, url, self._data) future = self._executor.submit(get_response, req_type, url, data)
future.add_done_callback(done_callback) future.add_done_callback(done_callback)
@run_task @run_task
@@ -365,6 +368,19 @@ class HttpAPI:
if s_id != "0": if s_id != "0":
self._data = urllib.parse.urlencode({"user": user, "password": password, "sessionid": s_id}).encode("utf-8") self._data = urllib.parse.urlencode({"user": user, "password": password, "sessionid": s_id}).encode("utf-8")
self.send(HttpRequestType.INFO, None, self.init_callback)
def init_callback(self, info):
if info:
version = info.get("e2webifversion", "").upper()
self._is_owif = "OWIF" in version
log("HTTP API initialized. Web Interface version: {}".format(version))
@property
def is_owif(self):
""" Returns true if the web interface is OpenWebif. """
return self._is_owif
@run_task @run_task
def close(self): def close(self):
self._shutdown = True self._shutdown = True

View File

@@ -2246,13 +2246,13 @@ class Application(Gtk.Application):
# ******************** Screenshots ************************# # ******************** Screenshots ************************#
def on_screenshot_all(self, action, value=None): def on_screenshot_all(self, action, value=None):
self._http_api.send(HttpRequestType.GRUB, "all", self.on_screenshot) self._http_api.send(HttpRequestType.GRUB, "mode=all" if self._http_api.is_owif else "d=", self.on_screenshot)
def on_screenshot_video(self, action, value=None): def on_screenshot_video(self, action, value=None):
self._http_api.send(HttpRequestType.GRUB, "video", self.on_screenshot) self._http_api.send(HttpRequestType.GRUB, "mode=video" if self._http_api.is_owif else "v=", self.on_screenshot)
def on_screenshot_osd(self, action, value=None): def on_screenshot_osd(self, action, value=None):
self._http_api.send(HttpRequestType.GRUB, "osd", self.on_screenshot) self._http_api.send(HttpRequestType.GRUB, "mode=osd" if self._http_api.is_owif else "o=", self.on_screenshot)
def on_screenshot(self, data): def on_screenshot(self, data):
if "error_code" in data: if "error_code" in data: