diff --git a/.gitignore b/.gitignore index 4ba7350..f851e98 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,8 @@ crashlytics-build.properties fabric.properties *.pyc -.vscode/ \ No newline at end of file +.vscode/ + +# launch script logfiles +**/logfile +**/logfile.old diff --git a/resources/launchscripts/osmc_vero/launch.sh b/resources/launchscripts/osmc_vero/launch.sh new file mode 100644 index 0000000..1d3f4dd --- /dev/null +++ b/resources/launchscripts/osmc_vero/launch.sh @@ -0,0 +1,20 @@ +#!/usr/bin/sh + +resume() { + killall -CONT kodi.bin +} + +trap resume EXIT + +killall -STOP kodi.bin + +# prevent black screen after playing video +echo 1 > /sys/class/graphics/fb0/blank +echo "rm default" > /sys/class/vfm/map +echo add default decoder ppmgr deinterlace amlvideo amvideo > /sys/class/vfm/map + +mv logfile logfile.old +LD_PRELOAD="/usr/local/lib/libmoonlight-aml.so /usr/osmc/lib/libamavutils.so /usr/osmc/lib/libamadec.so /usr/osmc/lib/libamcodec.so" \ + moonlight stream \ + -platform aml \ + -app "$@" >> logfile 2>&1 diff --git a/resources/launchscripts/osmc_vero/postscript.sh b/resources/launchscripts/osmc_vero/postscript.sh new file mode 100644 index 0000000..13d8196 --- /dev/null +++ b/resources/launchscripts/osmc_vero/postscript.sh @@ -0,0 +1 @@ +#!/usr/bin/sh diff --git a/resources/launchscripts/osmc_vero/prescript.sh b/resources/launchscripts/osmc_vero/prescript.sh new file mode 100644 index 0000000..13d8196 --- /dev/null +++ b/resources/launchscripts/osmc_vero/prescript.sh @@ -0,0 +1 @@ +#!/usr/bin/sh diff --git a/resources/lib/util/moonlighthelper.py b/resources/lib/util/moonlighthelper.py index 1e12966..f53d3dd 100644 --- a/resources/lib/util/moonlighthelper.py +++ b/resources/lib/util/moonlighthelper.py @@ -59,20 +59,21 @@ def list_games(self): list_regex = r'\d+\.\s+([^\n]*)' try: - moonlightOut = subprocess.check_output(['moonlight', 'list'], cwd=binary_path, timeout=5, encoding='utf-8', start_new_session=True) + host = self.plugin.getSetting('host_addr') + moonlightOut = subprocess.check_output(['moonlight', 'list', host], cwd=binary_path, timeout=5, encoding='utf-8', start_new_session=True) if 'must pair' in moonlightOut: return True return re.findall(list_regex, moonlightOut) - except: + except Exception: return False def quit_game(self): binary_path = self.config_helper.binary_path try: subprocess.run(['moonlight', 'quit'], cwd=binary_path, timeout=5, start_new_session=True) - except: + except Exception: return False return True @@ -104,14 +105,29 @@ def launch_game(self, game_id): xbmc.audioSuspend() t0 = time.monotonic() + host = self.plugin.getSetting('host_addr') subprocess.run([scripts_path + 'prescript.sh', binary_path, codec], cwd=scripts_path, start_new_session=True) - launch_cmd = subprocess.Popen([scripts_path + 'launch.sh', game_id], cwd=binary_path, start_new_session=True) + launch_cmd = subprocess.Popen( + [scripts_path + 'launch.sh', game_id, host], + cwd=scripts_path, + start_new_session=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + # pipe launch script output to Kodi logger + # moonlight launcher output should be logged to a file to prevent chatty Kodi logs (see any launch.sh) + with launch_cmd.stdout: + for line in iter(launch_cmd.stdout.readline, b''): + self.logger.info(f'{line}') + with launch_cmd.stderr: + for line in iter(launch_cmd.stderr.readline, b''): + self.logger.error(f'{line}') launch_cmd.wait() subprocess.run([scripts_path + 'postscript.sh', binary_path], cwd=scripts_path, start_new_session=True) except Exception as e: - print("Failed to execute moonlight process.") - print(e) + self.logger.error("Failed to execute moonlight process.") + self.logger.error(str(e)) finally: xbmc.audioResume() xbmc.executebuiltin("InhibitScreensaver(false)") diff --git a/resources/settings.xml b/resources/settings.xml index b5a3c5f..ea4d105 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -84,8 +84,8 @@ 20 5 - 1 - 100 + 10 + 250 false @@ -254,4 +254,4 @@ - \ No newline at end of file +