def _cmd(self, method=None, param=[], target=None, version=None): true = True false = False null = None if method: self.params["method"] = method if param: self.params["params"] = self._truefalse(param) else: self.params["params"] = [] # Add a version to the JSON parameters if version: self.params['version'] = version try: if target: result = eval(comp_urllib.urlopen( self.QX_ADDR + "/sony/" + target, json.dumps(self.params)).read()) else: result = eval(comp_urllib.urlopen( self.QX_ADDR + "/sony/camera", json.dumps(self.params)).read()) except Exception as e: result = "[ERROR] camera doesn't work: " + str(e) return result
def _cmd(self, method=None, param=[], target=None): true = True false = False null = None if not method in ["getAvailableApiList", "liveview"]: camera_api_list = self.getAvailableApiList()["result"][0] if method not in camera_api_list: return "[ERROR] this api is not support in this camera" if method: self.params["method"] = method if param: self.params["params"] = self._truefalse(param) else: self.params["params"] = [] try: if target: url = self.QX_ADDR + "/sony/" + target else: url = self.QX_ADDR + "/sony/camera" json_dump = json.dumps(self.params) json_dump_bytes = bytearray(json_dump, 'utf8') read = comp_urllib.urlopen(url, json_dump_bytes).read() result = eval(read) except Exception as e: result = "[ERROR] camera doesn't work: " + str(e) return result
def _read_device_definition(self, url): """ Fetch and parse the device definition, and extract the URL endpoint for the camera API service. """ r = comp_urllib.urlopen(url) services = self._parse_device_definition(r.read()) return services['camera']
def liveview(self, param=None): if not param: liveview = self._cmd(method="startLiveview") else: liveview = self._cmd(method="startLiveviewWithSize", param=param) if isinstance(liveview, dict): try: url = liveview['result'][0].replace('\\', '') result = comp_urllib.urlopen(url) except: result = "[ERROR] liveview is dict type but there are no result: " + str( liveview['result']) else: print("[WORN] liveview is not a dict type") result = liveview return result