move moonlight.py from resources/ to lib/
This commit is contained in:
parent
ceb7ce5b90
commit
e8462a98b5
|
@ -38,76 +38,75 @@ class LibGameStream:
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self.address = ""
|
self.address = ""
|
||||||
self.key_dir = ""
|
self.key_dir = ""
|
||||||
|
|
||||||
def discover_server(self):
|
def discover_server(self):
|
||||||
addr = ctypes.create_string_buffer('\000' * 40)
|
addr = ctypes.create_string_buffer('\000' * 40)
|
||||||
self.gslib.gs_discover_server(addr)
|
self.gslib.gs_discover_server(addr)
|
||||||
return addr.value
|
return addr.value
|
||||||
|
|
||||||
def connect_server(self, address, key_dir = ""):
|
def connect_server(self, address, key_dir = ""):
|
||||||
self.server = ctypes.pointer(SERVER_DATA(address, False, False, 0, 0))
|
self.server = ctypes.pointer(SERVER_DATA(address, False, False, 0, 0))
|
||||||
self.address = address
|
self.address = address
|
||||||
|
|
||||||
if key_dir == "":
|
if key_dir == "":
|
||||||
if "XDG_CONFIG_DIR" in os.environ:
|
if "XDG_CONFIG_DIR" in os.environ:
|
||||||
key_dir = os.path.join(os.environ["XDG_CONFIG_DIR"], "moonlight")
|
key_dir = os.path.join(os.environ["XDG_CONFIG_DIR"], "moonlight")
|
||||||
else:
|
else:
|
||||||
key_dir = os.path.join(os.environ["HOME"], ".cache", "moonlight")
|
key_dir = os.path.join(os.environ["HOME"], ".cache", "moonlight")
|
||||||
|
|
||||||
self.key_dir = key_dir
|
self.key_dir = key_dir
|
||||||
ret = self.gslib.gs_init(self.server, ctypes.c_char_p(key_dir))
|
ret = self.gslib.gs_init(self.server, ctypes.c_char_p(key_dir))
|
||||||
if ret == GS_OK:
|
if ret == GS_OK:
|
||||||
self.connected = True
|
self.connected = True
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def isPaired(self):
|
def isPaired(self):
|
||||||
if not self.connected:
|
if not self.connected:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return self.server[0].paired
|
return self.server[0].paired
|
||||||
|
|
||||||
def applist(self):
|
def applist(self):
|
||||||
if not self.connected:
|
if not self.connected:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
lst = []
|
lst = []
|
||||||
applst_ptr = ctypes.POINTER(APP_LIST)
|
applst_ptr = ctypes.POINTER(APP_LIST)
|
||||||
applst = applst_ptr()
|
applst = applst_ptr()
|
||||||
|
|
||||||
ret = self.gslib.gs_applist(self.server, ctypes.byref(applst))
|
ret = self.gslib.gs_applist(self.server, ctypes.byref(applst))
|
||||||
if ret != GS_OK:
|
if ret != GS_OK:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
while applst:
|
while applst:
|
||||||
lst.append((applst[0].id, applst[0].name))
|
lst.append((applst[0].id, applst[0].name))
|
||||||
applst = applst[0].next
|
applst = applst[0].next
|
||||||
|
|
||||||
return lst
|
return lst
|
||||||
|
|
||||||
def poster(self, appId, toFolder):
|
def poster(self, appId, toFolder):
|
||||||
unique_id = ""
|
unique_id = ""
|
||||||
with open(os.path.join(self.key_dir, "uniqueid.dat"), "r") as f:
|
with open(os.path.join(self.key_dir, "uniqueid.dat"), "r") as f:
|
||||||
unique_id = f.read()
|
unique_id = f.read()
|
||||||
|
|
||||||
uid = uuid4()
|
uid = uuid4()
|
||||||
url = "https://%s:47984/appasset?uniqueid=%s&uuid=%s&appid=%d&AssetType=2&AssetIdx=0" % (self.address, unique_id, str(uid), appId)
|
url = "https://%s:47984/appasset?uniqueid=%s&uuid=%s&appid=%d&AssetType=2&AssetIdx=0" % (self.address, unique_id, str(uid), appId)
|
||||||
|
|
||||||
self.gslib.http_create_data.restype = ctypes.POINTER(_HTTP_DATA)
|
self.gslib.http_create_data.restype = ctypes.POINTER(_HTTP_DATA)
|
||||||
data = self.gslib.http_create_data();
|
data = self.gslib.http_create_data();
|
||||||
self.gslib.http_request(ctypes.c_char_p(url), data)
|
self.gslib.http_request(ctypes.c_char_p(url), data)
|
||||||
|
|
||||||
barray = bytearray(data[0].memory[0:data[0].size])
|
barray = bytearray(data[0].memory[0:data[0].size])
|
||||||
|
|
||||||
with open(os.path.join(toFolder, str(appId) + ".png"), "wb") as f:
|
with open(os.path.join(toFolder, str(appId) + ".png"), "wb") as f:
|
||||||
f.write(barray)
|
f.write(barray)
|
||||||
|
|
||||||
self.gslib.http_free_data(data);
|
self.gslib.http_free_data(data);
|
||||||
|
|
||||||
def pair(self, pin):
|
def pair(self, pin):
|
||||||
if not self.connected:
|
if not self.connected:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
ret = self.gslib.gs_pair(self.server, ctypes.c_char_p(pin))
|
ret = self.gslib.gs_pair(self.server, ctypes.c_char_p(pin))
|
||||||
return ret == GS_OK
|
return ret == GS_OK
|
||||||
|
|
Loading…
Reference in a new issue