Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ crashlytics-build.properties
fabric.properties

*.pyc
.vscode/
.vscode/

# launch script logfiles
**/logfile
**/logfile.old
20 changes: 20 additions & 0 deletions resources/launchscripts/osmc_vero/launch.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions resources/launchscripts/osmc_vero/postscript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/usr/bin/sh
1 change: 1 addition & 0 deletions resources/launchscripts/osmc_vero/prescript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/usr/bin/sh
28 changes: 22 additions & 6 deletions resources/lib/util/moonlighthelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines +62 to +63

@agboom agboom Aug 19, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds the configured host address as argument to moonlight. Without it, Luna would err on my system.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is because I don't have any mDNS configured on my network. Is this something we need to take into account?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking more closely, I think this is because the written config file is not read. Luna writes moonlight.conf to one of these paths:

  • /etc/moonlight.conf
  • The binary path that MLE is installed in (e.g. /usr/local/bin/moonlight.conf)
  • If above aren't writable, it falls back to the addon path (e.g. ~/.kodi/addons/script.luna/moonlight.conf).

According to the docs, MLE only tries to read from the first one by default or from $XDG_CONFIG_HOME/moonlight/moonlight.conf.

So I think I need to change this to either pass the config path explicitly, or write the config file to $XDG_CONFIG_HOME/moonlight/moonlight.conf always. What do you think?


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
Expand Down Expand Up @@ -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}')
Comment on lines +117 to +124

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helps me to debug things if the launch script fails.

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)")
Expand Down
6 changes: 3 additions & 3 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
<default>20</default>
<constraints>
<minimum>5</minimum>
<step>1</step>
<maximum>100</maximum>
<step>10</step>
<maximum>250</maximum>
</constraints>
<control type="slider" format="integer">
<popup>false</popup>
Expand Down Expand Up @@ -254,4 +254,4 @@
</group>
</category>
</section>
</settings>
</settings>