wackerl91 / luna

Moonlight Launcher for Kodi
GNU General Public License v3.0
100 stars 22 forks source link

Can't run listed games #61

Open TTherouanne opened 8 years ago

TTherouanne commented 8 years ago

Hello, I know that Luna is designed for OSMC but i'm trying to use it with Kodi (i guess he is compatible)

When i try to start games or steam from Luna, nothing is happening, (features like scrapper, pairing, remote game list works) Moonlight is working fine when i run it from the terminal.

My setup:

I have put kodi in debug mode, this is an extract during the game start :

11:51:12 T:1549792160 NOTICE: [script.luna] [CoreService] - initialized 11:51:12 T:1549792160 DEBUG: [xbmcswift2] Reading pickle storage from disk at "/var/lib/kodi/.kodi/userdata/addon_data/script.luna/.storage/game_storage" 11:51:12 T:1549792160 DEBUG: [xbmcswift2] Loaded storage "game_storage" from disk 11:51:12 T:1549792160 DEBUG: LocalizeStrings: no translation available in currently set gui language, at path /var/lib/kodi/.kodi/addons/script.luna/resources/language/French 11:51:12 T:1549792160 DEBUG: LocalizeStrings: no strings.po file exist at /var/lib/kodi/.kodi/addons/script.luna/resources/language/English, fallback to strings.xml 11:51:12 T:1828680608 DEBUG: WaitOnScriptResult- plugin returned successfully 11:51:12 T:1549792160 DEBUG: [xbmcswift2] Saving a pickle storage to disk at "/var/lib/kodi/.kodi/userdata/addon_data/script.luna/.storage/game_version" 11:51:12 T:1949356032 DEBUG: Saving fileitems [plugin://script.luna/games] 11:51:12 T:1949356032 DEBUG: -- items: 19, sort method: 0, ascending: false 11:51:12 T:1549792160 DEBUG: [xbmcswift2] Saving a pickle storage to disk at "/var/lib/kodi/.kodi/userdata/addon_data/script.luna/.storage/game_storage" 11:51:12 T:1549792160 DEBUG: [xbmcswift2] Saving a pickle storage to disk at "/var/lib/kodi/.kodi/userdata/addon_data/script.luna/.storage/update" 11:51:12 T:1605559200 DEBUG: Thread BackgroundLoader start, auto delete: false 11:51:12 T:1549792160 INFO: CPythonInvoker(26, /var/lib/kodi/.kodi/addons/script.luna/addon.py): script successfully run 11:51:12 T:1605559200 WARNING: CreateLoader - unsupported protocol(plugin) in plugin://script.luna/games/launch/DIA+GeForce+GTX+950%2C+GFE+2.11.2.55+%28protocol+version+7%29/folder.jpg 11:51:13 T:1605559200 WARNING: CreateLoader - unsupported protocol(plugin) in plugin://script.luna/games/launch/Launcher/folder.jpg 11:51:13 T:1605559200 WARNING: CreateLoader - unsupported protocol(plugin) in plugin://script.luna/games/launch/Serious+Sam+3%3A+BFE/folder.jpg 11:51:13 T:1949356032 DEBUG: ------ Window Deinit (DialogBusy.xml) ------ 11:51:13 T:1605559200 WARNING: CreateLoader - unsupported protocol(plugin) in plugin://script.luna/games/launch/Shank2/folder.jpg 11:51:13 T:1605559200 WARNING: CreateLoader - unsupported protocol(plugin) in plugin://script.luna/games/launch/Steam/folder.jpg 11:51:13 T:1549792160 WARNING: CPythonInvoker(26, /var/lib/kodi/.kodi/addons/script.luna/addon.py): the python script "/var/lib/kodi/.kodi/addons/script.luna/addon.py" has left several classes in memory that we couldn't clean up. The classes include: N9XBMCAddon7xbmcgui8ListItemE,N9XBMCAddon7xbmcgui8ListItemE,N9XBMCAddon7xbmcgui8ListItemE,N9XBMCAddon9xbmcaddon5AddonE,N9XBMCAddon7xbmcgui8ListItemE,N9XBMCAddon7xbmcgui8ListItemE,N9XBMCAddon7xbmcgui8ListItemE,N9XBMCAddon7xbmcgui8ListItemE,N9XBMCAddon7xbmcgui8ListItemE,N9XBMCAddon7xbmcgui8ListItemE,N9XBMCAddon7xbmcgui8ListItemE,N9XBMCAddon7xbmcgui8ListItemE,N9XBMCAddon7xbmcgui8ListItemE,N9XBMCAddon7xbmcgui8ListItemE,N9XBMCAddon7xbmcgui8ListItemE,N9XBMCAddon7xbmcgui8ListItemE,N9XBMCAddon7xbmcgui8ListItemE,N9XBMCAddon7xbmcgui8ListItemE,N9XBMCAddon7xbmcgui8ListItemE,N9XBMCAddon7xbmcgui8ListItemE 11:51:13 T:1549792160 INFO: Python script stopped 11:51:13 T:1549792160 DEBUG: Thread LanguageInvoker 1549792160 terminating 11:51:13 T:1605559200 WARNING: CreateLoader - unsupported protocol(plugin) in plugin://script.luna/games/launch/trine2_32bit/folder.jpg 11:51:13 T:1605559200 DEBUG: Thread BackgroundLoader 1605559200 terminating 11:51:17 T:1566569376 DEBUG: CPullupCorrection: detected pattern of length 1: 40000.00, frameduration: 40000.000000 11:51:23 T:1949356032 INFO: Python, unloading python shared library because no scripts are running anymore 11:51:23 T:1949356032 DEBUG: UnloadExtensionLibs, clearing python extension libraries 11:51:27 T:1949356032 DEBUG: Keyboard: scancode: 0x6c, sym: 0x0112, unicode: 0x0000, modifier: 0x0 11:51:27 T:1949356032 DEBUG: OnKey: down (0xf081) pressed, action is Down 11:51:27 T:1828680608 DEBUG: COMXCoreComponent::Initialize OMX.broadcom.image_decode input port 320 output port 321 m_handle 0x60c6b598 11:51:27 T:1828680608 DEBUG: COMXCoreComponent::AllocInputBuffers component(OMX.broadcom.image_decode) - port(320), nBufferCountMin(2), nBufferCountActual(2), nBufferSize(81920), nBufferAlignmen(16) 11:51:27 T:1828680608 DEBUG: COMXCoreComponent::Initialize OMX.broadcom.egl_render input port 220 output port 221 m_handle 0x7243f830 11:51:27 T:1828680608 DEBUG: COMXCoreComponent::UseEGLImage component(OMX.broadcom.egl_render) - port(221), nBufferCountMin(1), nBufferCountActual(1), nBufferSize(15360) nBufferAlignmen(16) 11:51:27 T:1828680608 DEBUG: COMXCoreComponent::Deinitialize : OMX.broadcom.image_decode handle 0x60c6b598 11:51:27 T:1828680608 DEBUG: COMXCoreComponent::Deinitialize : OMX.broadcom.egl_render handle 0x7243f830 11:51:27 T:1828680608 DEBUG: DoWork - took 194 ms to load special://masterprofile/Thumbnails/0/061e29cf.jpg 11:51:32 T:1949356032 DEBUG: Keyboard: scancode: 0x67, sym: 0x0111, unicode: 0x0000, modifier: 0x0 11:51:32 T:1949356032 DEBUG: OnKey: up (0xf080) pressed, action is Up 11:51:35 T:1949356032 DEBUG: Keyboard: scancode: 0x1c, sym: 0x000d, unicode: 0x0000, modifier: 0x0 11:51:35 T:1949356032 DEBUG: OnKey: return (0xf00d) pressed, action is Select 11:51:35 T:1949356032 DEBUG: CGUIMediaWindow::GetDirectory (plugin://script.luna/games/launch/DiRT+Rally) 11:51:35 T:1949356032 DEBUG: ParentPath = [plugin://script.luna/games] 11:51:35 T:1828680608 DEBUG: StartScript - calling plugin Luna('plugin://script.luna/games/launch/DiRT+Rally','19','') 11:51:35 T:1828680608 DEBUG: WaitOnScriptResult - waiting on the Luna (id=27) plugin... 11:51:35 T:1605559200 DEBUG: Thread LanguageInvoker start, auto delete: false 11:51:35 T:1605559200 INFO: initializing python engine. 11:51:35 T:1605559200 DEBUG: CPythonInvoker(27, /var/lib/kodi/.kodi/addons/script.luna/addon.py): start processing 11:51:35 T:1605559200 DEBUG: -->Python Interpreter Initialized<-- 11:51:35 T:1605559200 DEBUG: CPythonInvoker(27, /var/lib/kodi/.kodi/addons/script.luna/addon.py): the source file to load is "/var/lib/kodi/.kodi/addons/script.luna/addon.py" 11:51:35 T:1605559200 DEBUG: CPythonInvoker(27, /var/lib/kodi/.kodi/addons/script.luna/addon.py): setting the Python path to /var/lib/kodi/.kodi/addons/script.luna:/var/lib/kodi/.kodi/addons/script.module.dateutil/lib:/var/lib/kodi/.kodi/addons/script.module.pyxbmct/lib:/var/lib/kodi/.kodi/addons/script.module.six/lib:/var/lib/kodi/.kodi/addons/script.module.xbmcswift2/lib:/usr/lib/python27.zip:/usr/lib/python2.7:/usr/lib/python2.7/plat-linux2:/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/lib-old:/usr/lib/python2.7/lib-dynload:/usr/lib/python2.7/site-packages 11:51:35 T:1605559200 DEBUG: CPythonInvoker(27, /var/lib/kodi/.kodi/addons/script.luna/addon.py): entering source directory /var/lib/kodi/.kodi/addons/script.luna 11:51:35 T:1605559200 DEBUG: CPythonInvoker(27, /var/lib/kodi/.kodi/addons/script.luna/addon.py): instantiating addon using automatically obtained id of "script.luna" dependent on version 2.1.0 of the xbmc.python api 11:51:35 T:1949356032 DEBUG: ------ Window Init (DialogBusy.xml) ------ 11:51:36 T:1566569376 WARNING: CRenderManager::WaitForBuffer - timeout waiting for buffer 11:51:36 T:1605559200 NOTICE: [script.luna] [CoreService] - initialized 11:51:36 T:1605559200 DEBUG: [xbmcswift2] Adding url rule "/" named "index" pointing to function "index" 11:51:36 T:1605559200 DEBUG: [xbmcswift2] Adding url rule "/settings" named "open_settings" pointing to function "open_settings" 11:51:36 T:1605559200 DEBUG: [xbmcswift2] Adding url rule "/update" named "check_update" pointing to function "check_update" 11:51:36 T:1605559200 DEBUG: [xbmcswift2] Adding url rule "/actions/create-mapping" named "create_mapping" pointing to function "create_mapping" 11:51:36 T:1605559200 DEBUG: [xbmcswift2] Adding url rule "/actions/pair-host" named "pair_host" pointing to function "pair_host" 11:51:36 T:1605559200 DEBUG: [xbmcswift2] Adding url rule "/actions/reset-cache" named "reset_cache" pointing to function "reset_cache" 11:51:36 T:1605559200 DEBUG: [xbmcswift2] Adding url rule "/actions/patch-osmc" named "patch_osmc_skin" pointing to function "patch_osmc_skin" 11:51:36 T:1605559200 DEBUG: [xbmcswift2] Adding url rule "/actions/rollback-osmc" named "rollback_osmc_skin" pointing to function "rollback_osmc_skin" 11:51:36 T:1605559200 DEBUG: [xbmcswift2] Adding url rule "/games" named "show_games" pointing to function "show_games" 11:51:36 T:1605559200 DEBUG: [xbmcswift2] Adding url rule "/games/refresh" named "do_full_refresh" pointing to function "do_full_refresh" 11:51:36 T:1605559200 DEBUG: [xbmcswift2] Adding url rule "/games/info/" named "show_game_info" pointing to function "show_game_info" 11:51:36 T:1605559200 DEBUG: [xbmcswift2] Adding url rule "/games/launch/" named "launch_game" pointing to function "launch_game" 11:51:36 T:1605559200 DEBUG: [xbmcswift2] Adding url rule "/games/launch-from-widget/" named "launch_game_from_widget" pointing to function "launch_game_from_widget" 11:51:36 T:1605559200 NOTICE: [script.luna] [CoreService] - initialized 11:51:36 T:1605559200 NOTICE: [script.luna] [UpdateService] - initialized 11:51:36 T:1605559200 DEBUG: [xbmcswift2] Reading pickle storage from disk at "/var/lib/kodi/.kodi/userdata/addon_data/script.luna/.storage/update" 11:51:36 T:1605559200 DEBUG: [xbmcswift2] Loaded storage "update" from disk 11:51:37 T:1605559200 NOTICE: [script.luna] [ConfigHelper] - Dumped config to disk. 11:51:37 T:1605559200 DEBUG: [xbmcswift2] Reading pickle storage from disk at "/var/lib/kodi/.kodi/userdata/addon_data/script.luna/.storage/game_version" 11:51:37 T:1605559200 DEBUG: [xbmcswift2] Loaded storage "game_version" from disk 11:51:37 T:1605559200 DEBUG: [xbmcswift2] Handling incoming request for /games/launch/DiRT+Rally 11:51:37 T:1605559200 NOTICE: [xbmcswift2] Request for "/games/launch/DiRT+Rally" matches rule for function "launch_game" 11:51:37 T:1605559200 NOTICE: [script.luna] [CoreService] - initialized 11:51:37 T:1605559200 NOTICE: [script.luna] Launching game DiRT Rally 11:51:37 T:1605559200 NOTICE: [script.luna] [ConfigHelper] - Dumped config to disk. 11:51:39 T:1828680608 DEBUG: WaitOnScriptResult- plugin returned failure 11:51:39 T:1605559200 DEBUG: [xbmcswift2] Saving a pickle storage to disk at "/var/lib/kodi/.kodi/userdata/addon_data/script.luna/.storage/game_version" 11:51:39 T:1949356032 ERROR: GetDirectory - Error getting plugin://script.luna/games/launch/DiRT+Rally 11:51:39 T:1949356032 ERROR: CGUIMediaWindow::GetDirectory(plugin://script.luna/games/launch/DiRT+Rally) failed 11:51:39 T:1949356032 DEBUG: CGUIMediaWindow::GetDirectory (plugin://script.luna/games) 11:51:39 T:1949356032 DEBUG: ParentPath = [plugin://script.luna/] 11:51:39 T:1949356032 DEBUG: Loading items: 19, directory: plugin://script.luna/games sort method: 0, ascending: false 11:51:39 T:1549792160 DEBUG: Thread BackgroundLoader start, auto delete: false 11:51:39 T:1605559200 DEBUG: [xbmcswift2] Saving a pickle storage to disk at "/var/lib/kodi/.kodi/userdata/addon_data/script.luna/.storage/update" 11:51:39 T:1549792160 WARNING: CreateLoader - unsupported protocol(plugin) in plugin://script.luna/games/launch/DIA+GeForce+GTX+950%2C+GFE+2.11.2.55+%28protocol+version+7%29/folder.jpg 11:51:39 T:1549792160 WARNING: CreateLoader - unsupported protocol(plugin) in plugin://script.luna/games/launch/Launcher/folder.jpg 11:51:39 T:1605559200 INFO: CPythonInvoker(27, /var/lib/kodi/.kodi/addons/script.luna/addon.py): script successfully run 11:51:39 T:1949356032 DEBUG: ------ Window Deinit (DialogBusy.xml) ------ 11:51:39 T:1549792160 WARNING: CreateLoader - unsupported protocol(plugin) in plugin://script.luna/games/launch/Serious+Sam+3%3A+BFE/folder.jpg 11:51:39 T:1549792160 WARNING: CreateLoader - unsupported protocol(plugin) in plugin://script.luna/games/launch/Shank2/folder.jpg 11:51:39 T:1549792160 WARNING: CreateLoader - unsupported protocol(plugin) in plugin://script.luna/games/launch/Steam/folder.jpg 11:51:39 T:1549792160 WARNING: CreateLoader - unsupported protocol(plugin) in plugin://script.luna/games/launch/trine2_32bit/folder.jpg 11:51:39 T:1549792160 DEBUG: Thread BackgroundLoader 1549792160 terminating 11:51:39 T:1605559200 WARNING: CPythonInvoker(27, /var/lib/kodi/.kodi/addons/script.luna/addon.py): the python script "/var/lib/kodi/.kodi/addons/script.luna/addon.py" has left several classes in memory that we couldn't clean up. The classes include: N9XBMCAddon9xbmcaddon5AddonE 11:51:39 T:1605559200 INFO: Python script stopped 11:51:39 T:1605559200 DEBUG: Thread LanguageInvoker 1605559200 terminating 11:51:41 T:1566569376 DEBUG: CPullupCorrection: detected pattern of length 1: 40000.00, frameduration: 40000.000000 11:51:50 T:1949356032 INFO: Python, unloading python shared library because no scripts are running anymore 11:51:50 T:1949356032 DEBUG: UnloadExtensionLibs, clearing python extension libraries 11:51:57 T:1566569376 DEBUG: CPullupCorrection: detected pattern of length 1: 40000.00, frameduration: 40000.000000 11:52:09 T:1828680608 DEBUG: Previous line repeats 1 times. 11:52:09 T:1828680608 DEBUG: Thread JobWorker 1828680608 terminating (autodelete) 11:52:51 T:1566569376 DEBUG: CPullupCorrection: detected pattern of length 1: 40000.00, frameduration: 40000.000000

Have you got an idea that what is causing this problem? Thanks for your help!

wackerl91 commented 8 years ago

Heya @TTherouanne! I'm actually not surprised that launching a game doesn't work from Luna ;) The only available launch scripts are tied to OSMC right now - plus they're leveraging the fact that elevated commands can be issued without further authentication by default. Since I guess that you're pretty proficient with Linux (given that you installed ALARM instead of a preconfigured mediacenter solution) I'll try to point you into the right direction, but you will have to do some dirty work yourself. 1) the launch scripts are called from moonlighthelper in resources/lib/util 2) the script being called is actually just a helper which takes four arguments: the path to the actual launcher script, the path to the heartbeat script, the game to be launched and the path to the config file generated by Luna. It then launches the heartbeat script, switches to another VT using openvt and starts the actual launch script and attempts to stop the Kodi systemd service after a two second wait period. It's using elevated rights (those are all sudo commands) to do this. 3) the heartbeat script checks for a moonlight PID and restarts the Kodi service once moonlight has been quit

To get this working in your environment (and this is probably just the easiest way) you need to make sure that:

All of the files can be found in Kodi's add-on directory, which varies slightly. Check Kodi's documentation to find the path for your system.

If you had to change the launch scripts then this will break as soon as the next update is released as they're overwritten - we should worry about that later though, once everything works on your end.

Should you need any further assistance please let me know. If you get it to work I'd really appreciate it if you could document the steps needed to get it fully running and shoot me an email (can be found on my GitHub profile page) so I can include these steps on the Wiki šŸ˜ƒ

Good luck!

TTherouanne commented 8 years ago

Hi, Thanks for your answer :) Great, adapt these bash scripts to kodi should be easy! I come back to you soon

I plan also to work on a 'wake on lan' feature with shutdown support (with pywinrm), and to create a PKGBUILD for Archlinux...

wackerl91 commented 8 years ago

WOL is something I wanted to look into once I got multi-host and mDNS support straight. There shouldn't be much dark magic involved in sending a magic packet via python (yeah, I'll show myself out for that stupid joke ...). So it will find its way to Luna sooner or later. Anyway, if you want to have that functionality now you're indeed better off writing this yourself - not to mention the fact that stuff like this is extremely fun! You should be able to just hook your own command into the launch script and / or call it before launching a game from within python and just stall script execution until your host machine woke up.

wackerl91 commented 8 years ago

@TTherouanne Did you get this to work on Arch?

TTherouanne commented 8 years ago

Hi,

Sorry this last days i'm a little busy :/ I have redeployed my raspberrypi (with Ansible) and now Luna won't start, i don't know why yet, i will post debug log after few investigations...

For the moment, i have found an easy way to start moonlight from kodi with systemd user services.

I start a script from Kodi with the Advanced Launcher addon who call 'systemctl --user start kodi-moonlight'

-> kodi is started by a user session systemd service -> user lingering is enable for the kodi user with loginctl (headless raspi)

Stop and start of kodi are managed by the unit kodi-moonlight.service with the options 'ExecStartPre' and 'ExecStopPost'. See below

[root@RPI2 user]# cat /etc/systemd/user/kodi.service [Unit] Description = Starts an instance of Kodi After = remote-fs.target [Service] Type = simple ExecStart = /usr/bin/kodi-standalone -l /run/lirc/lircd Restart = on-failure [Install] WantedBy = multi-user.target

[root@RPI2 user]# cat /etc/systemd/user/kodi-moonlight.service [Unit] Description = Start moonlight [Service] Type = simple ExecStartPre = /usr/bin/systemctl --user stop kodi ExecStart = /usr/bin/moonlight stream -mapping /etc/moonlight/xpad-360.map ExecStopPost = /usr/bin/systemctl --user start kodi

TTherouanne commented 8 years ago

Hi wackerl91,

As promised, here are the logs, sorry for the wait! :) When i start Luna (with pairing not done), the app starts ( just an SSL error/warning in logs from requests module ) The pairing is not working from the app and if i do it manually, Luna no longer starts. (kodi 16.1, Luna 0.6.1) Do you have an idea?

I also looking for a way to install the dependencies of the addon from a script (to make an AUR package). I should parse the addon.xml file and download/unpack each of the modules in the addon folder but this is ugly. I'm surprised not to find methods to manage addons in the Kodi API And if i just unpack luna in the addon folder, Kodi don't search for missing dƩpendencies at his startup :/

Thanks ;)

When i start a pairing 19:09:36 T:1724642208 NOTICE: [script.luna] [CoreService] - initialized 19:09:37 T:1724642208 ERROR: /var/lib/kodi/.kodi/addons/script.module.requests/lib/requests/packages/urllib3/connectionpool.py:791: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html InsecureRequestWarning) 19:09:37 T:1724642208 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--

when i start Luna (with certificates in ~/.cache/moonlight): 19:06:56 T:1749808032 ERROR: /var/lib/kodi/.kodi/addons/script.module.requests/lib/requests/packages/urllib3/connectionpool.py:791: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html InsecureRequestWarning) 19:06:56 T:1749808032 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--

wackerl91 commented 8 years ago

Heya @TTherouanne,

no worries, I was obviously busy as well. That's a (admittedly pretty common) string encoding issue - I'm not sure why you're seeing this though, probably got to debug this a bit. I guess you're using the most recent version of ALARM? And what's your GFE version? Edit: before I'm going ahead and start to install ALARM on my second card, could you try to log the output where Luna is failing? Simply edit /var/lib/kodi/.kodi/addons/script.luna/resources/lib/nvhttp/nvhttp.py at line 143 and place self.logger.info(response.content) before the get_app_list_from_string() call. That might help me out a lot!

Kodi Addons probably shouldn't be installable via an open API to prevent abuse (not that this would matter much on systems like OSMC ...) - so while Kodi parses the addon.xml file and installs every dependency stated in there via a private API, you would indeed need to do pretty much the same on your own. On the other hand - why an AUR package? For easy installation? You could probably just as easily supply only the systemd service definition in the AUR package and point to it from within Luna if the discovered OS is ALARM. Then again, that's probably not even worth the trouble for just a single file, as it might be way easier to just tell people what to copy inside the service definition and how it should be named ;) Anyway, waiting for you answer here before I'm starting to speculate even more :P

Sian-Lee-SA commented 8 years ago

I too am getting this same error and though I would chime in here, the output from inserting the code you mentioned displays xml of my games [http://pastebin.com/34MLkGZW]. The error shows the same as TTherouanne.

`17:19:42 1956.891846 T:1478136816 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--

Sian-Lee-SA commented 8 years ago

I believe the problem is with the ā„¢ symbol

wackerl91 commented 8 years ago

Heya @CQoute, thanks for letting me know and providing a full XML - this was extremely helpful! The problem is indeed related to the ā„¢ symbol, though the error occurs because I'm trying to decode the string as UTF-16 instead of UTF-8 (as noted in the 'encoding' attribute in the XML). Question is if this attribute has changed in newer GFE versions (I'm currently still at 2.11.3.x, which uses UTF-16) or if GFE just decides to use UTF-8 encoding for certain special characters. Maybe you can shed some light onto that by also telling me your GFE version. Depending on whether they generally decided to switch encodings or if it's just used occasionally the fix will be slightly different - I can detect GFE versions and act accordingly and I'd only decide to using a regex on the string if I can't properly predict its contents otherwise.

TTherouanne commented 8 years ago

Hi, "DARK SOULSā„¢ III" was the guilty ! After renamed it with the GFE interface, Luna is starting :)

In my case, the XML is generated with UTF-16 encoding as expected : http://pastebin.com/tFwxWbH1 I use the last version : NVIDIA GeForce GTX 950, GFE 2.11.3.5 (protocol version 7)

wackerl91 commented 8 years ago

Heya! Thanks for confirming and providing another example. Both in conjunction should point me into the right direction to get a fix ready and just hit it with both examples until it passes ;) Still curious what CQuote's version is ... BTW, as of today GFE 2.11.4.0 is the most recent version though I haven't installed it yet.

Now that Luna's starting again for you and you got a systemd definition, you should be able to just tell launch-helper-osmc and moonlight-heartbeat what your service is called (as long as the scripts can be executed as root). I'll look into using a service for starting moonlight in the future (similar to yours actually, just need to pass some args) since this has been proposed quite some times already, though that's quite another beast unfortunately.

It might also please you to hear that basic WoL support is (finally) coming with Luna's next version (i.e. 0.7.0). Will only work properly if you have your computer set to auto-login after sleep. No remote sleep/shutdown though. Just saying, because you mentioned both earlier :)

Sian-Lee-SA commented 8 years ago

My version is 2.11.3.5, I also didn't realise you could rename from the GFE interface so I will do that as a temporary fix for now.

wackerl91 commented 8 years ago

@TTherouanne / @CQoute: Luna 0.6.3 should resolve the encoding issues. Both your datasets (dumped as XML to disc, so it's not strictly the same) as well as a local test (used Star Wars KotoR I, amazing game!) went fine. That being said, the XML states that it's encoded as UTF-16 so my more 'hands-on' test matches @TTherouanne scenario.

Either way, here's what I'm doing to (hopefully!) capture all cases: 1) trying to find a specified encoding in the XML 2) if I can find one, I'm trying to decode the XML string as the specified encoding and re-encode it using the same encoding (ElementTree needs to have matching encodings, i.e. if the XML says it's UTF-8 it has to be encoded as UTF-8, that's why we're doing the last step) 3) if decoding the XML as specified fails, I'm trying to decode it as UTF-8 (educated guess: the response body is always UTF-8?) and encode it again as specified (i.e. UTF-16).

I did what I could to test this locally (and it took way longer than expected; after I fixed the XML encoding, the TM symbol caused the entire scraper chain to crash as well), so I'm pretty confident you shouldn't run into this kind of issue anymore. Still, let me know how it goes and I really appreciate your help in this matter!

If you guys should run into any additional problems, please open separate issues to keep this one clear for @TTherouanne's discussion about getting Luna to run properly on Arch. Thanks!

Sian-Lee-SA commented 8 years ago

All working good now, thanks for rectifying the problem quickly. On a side note, I only came across this on a google search to only scroll down and see @TTherouanne has the same error that mine was showing so I thought it was suitable to give my input on the situation. I will be sure to open a new issue in future if I come across any. All in all I really appreciate your work on this, so thanks!

wackerl91 commented 8 years ago

@CQoute No worries, that's fine in this case - and it wasn't meant offensive in any way. Just usually like my tracker somewhat organised because it's way easier for people to find related (and maybe already resolved) issues if the title matches the content ;)

As I've said, your input was very much appreciated and valuable - before you showed up, I thought that ALARM had Python set up differently, so you saved some people a lot of headaches.

Anyway, glad it's working for you again and you're welcome. Game on!

TTherouanne commented 8 years ago

Hi Wacker, Thank you for your quick fix!

I can now start a game by modifying the launch_game method in 'resources/lib/util/moonlighthelper.py' to call a systemd service. The arguments are passed to systemd by putting variables in a file

    def launch_game(self, game_id):
        self.config_helper.configure()
        # Environment file used by systemd to start moonlight
        with open('/tmp/luna_env.tmp', 'w') as file:
            file.write(''.join(['LUNA_CONFIG = ', self.config_helper.get_config_path(), '\n', 'LUNA_DEBUG = ', self.plugin.get_setting('enable_moonlight_debug'), '\n', 'LUNA_APP = ', game_id, '\n']))

        # Start systemd service
        subprocess.call(['/usr/bin/systemctl', '--user', 'start', 'kodi-moonlight'])

So to resume:

[Unit]
Description = Starts an instance of Kodi
[Service]
Type = simple
ExecStart = /usr/bin/kodi-standalone -l /run/lirc/lircd
Restart = on-failure
[Install]
WantedBy = default.target
[Unit]
Description = Start Moonlight from Kodi, with Luna
[Service]
Type = simple
EnvironmentFile = /tmp/luna_env.tmp
ExecStartPre = /usr/bin/systemctl --user stop kodi
ExecStart = /usr/bin/moonlight stream -app ${LUNA_APP} -config ${LUNA_CONFIG} -audio hdmi
ExecStopPost = /usr/bin/systemctl --user start kodi

If i don't set the audio option to 'hdmi', moonlight try to find a sound device but the alsa module snd_bcm2835 is not (always) loaded by defaults on the raspberrypi.

Currently, i can't set the '-audio hdmi' option from Luna and Inputs listing seems to not work with the xpad module (empty window).

I'm happy to learn that the WOL feature is available soon! :) Meanwhile as you suggesting, i use a bash script for this.

wackerl91 commented 8 years ago

@TTherouanne

Hi Wacker, Thank you for your quick fix!

That's my last name, but still: you're welcome :) And that's really great news on your end!

I'd like to ask for your opinion on transitioning away from the currently used launch scripts to systemd in general, as you seem to have a lot more experience with this than I do and I don't want to break your solution with any upcoming updates.

My current plan would be to provide a kind of "skeleton" for the moonlight service with Luna, which would have to be copied to the corresponding systemd folder by the user. While I could do this programmatically on OSMC, I won't be able to do so on most other systems and I think it's better to keep installation instructions the same. I would require the service to use a certain name so I don't have to present the user with a list of all known services and have them pick one. Now this leaves us with the issue of different configurations:

So what I'd do would be to check if the OS is OSMC / OpenELEC (since we already know how they're set up) and for all other cases I'd give the user an option to select if the service is started as a user or as a non-password root command.

I guess with this implementation I wouldn't break your setup (as you can still put into your service definition whatever you want or need; only pitfall would be the name but that's changed quickly) while extending support to pretty much all systems where moonlight runs properly (and systemd is used) at once. Looking forward to your input regarding this!

If i don't set the audio option to 'hdmi', moonlight try to find a sound device but the alsa module snd_bcm2835 is not (always) loaded by defaults on the raspberrypi.

Anything I can do to fix this for you from inside Luna? For example checking if the kernel module is loaded and set to audio=hdmi by default? The parameter is already part of the config file passed to moonlight, so I'd just have to provide a fallback. Simply need to know if this would solve your issue in an elegant way :)

Inputs listing seems to not work with the xpad module (empty window).

Hm, that's strange. The list of available input devices is pulled from /proc/bus/input/devices, so as long as the host recognises them, Luna should list them. As a side note, I can't handle newly plugged in controllers right now - if you open up the input selection and plug in / power up your controller afterwards, you will need to exit Luna completely and restart it, as the service builds its list once it's initialised and the service is cached by the DI container (more or less properly on 0.6.x; completely on 0.7.x and above). That being said, at least xboxdrv always lists all available controllers, even if they're turned off. I got no idea how xpad itself is behaving, but it should be easy enough to test (just need to kill xboxdrv, reload xpad and do some testing). Do you get any error in the log when trying to access the input selection or does it just act like everything's fine?

EDIT: Using xpad works fine on OSMC (at least for controller selection, haven't tried actually using it in moonlight as I don't have a windows host up right now. Oh and apart from weird naming of course, might need to fix that): screen shot 2016-06-23 at 14 55 53 screen shot 2016-06-23 at 14 56 11

Just to make sure there's no misunderstanding about how this works:

[Input 0]
mapping = /home/osmc/xbox-1.map
input = /dev/input/event2

[Input 1]
mapping = /home/osmc/xbox-1.map
input = /dev/input/event3

I'm happy to learn that the WOL feature is available soon! :) Meanwhile as you suggesting, i use a bash script for this.

Always trying my best :P Since you mentioned remote shutdown before, I'd like to pick up that topic again. Since I'm not looking to support this directly (as it requires account information about the host and - quite frankly - I don't want to handle user password input in Luna), would it help you out if I gave you the option to append an item to the host context menu and the action of that menu item would be a script execution? You'd have to provide a name and the script location obviously, plus making sure it's executable (that way I can support both Python and Bash scripts since I don't need to know what they really are, as long as they got their shebang set properly). Arguments would be the hosts local IP, its name and its MAC. So you could basically set up scripts for shutdown / sleep / whatever on your own with whatever tools you need and just have Luna execute them for you, while making sure it affects the currently selected host (pssst, spoiler: multi-host support is coming, too!). You could still make some example scripts available on the wiki, so setting them up will be up to the user but still as simple as possible.

wackerl91 commented 8 years ago

@TTherouanne, just as a quick follow-up regarding the PKGBUILD for ALARM: would it help with the dependencies if we provided an additional requirements file that can be used with pip to install everything that's needed?

Roboron3042 commented 7 years ago

I don't know if this is going to be helpful, but I followed the suggestions in @wackerl91 's first comment:

  • you got passwordless sudo enabled (please keep in mind that this is a potential security issue and you should have other security measures in place, i.e. that you're Pi can't be accessed from outside your local network)
  • probably the user 'osmc' doesn't exist on your system, so you will have to run those scripts as root or as your current user account (launch helper script needs to be changed accordingly on lines 11 and 12)
  • openvt is installed
  • Kodi has a systemd service attached
  • if your service is called 'mediacenter' (that's the default for OSMC) then everything should work already. If it's called something else then you'd need to edit the launch helper and heartbeat scripts to stop/start your service. For example if your Kodi service is simply called 'kodi', the launch helper should call sudo su -c "systemctl stop kodi &" &
  • make sure all launch scripts are marked as executable

And when I try to launch a game from Luna i get a black screen with a error message:

unknown: i need something more specific

Maybe later I will try the solution of @TTherouanne last comment.

wackerl91 commented 7 years ago

@Roboron3042 Following @TTherouanne's guide is indeed your best bet, as my first comment was a complete shot in the dark, simply stating what the current implementation expects.

When following his steps please keep in mind that the implementation has changed a lot since then (this is especially true for the 0.7.0 release candidates). You might want to have a look at the current state of the moonlight helper and the current launch scripts.

The error you're getting might(!) be caused by all three scripts having a different shebang (which I just now realised, never opened them all at the same time), but that's difficult to say without more information. When changing them it might be worth it to try each one individually to see which of them is failing (this also holds true if you decide to use @TTherouanne's way).

Let me know if you need any more help. And while you're at it, I'd appreciate any thoughts regarding a possible more general implementation I mentioned at the beginning of my last comment.

BlackVodka commented 7 years ago

@TTherouanne Thanks a lot for sharing your way of starting moonlight via systemd - services! I'd like to post my modifications here which I needed on my Retropie/Raspbian system, perhaps this helps some other people.

@wackerl91 : Great work, awesome addon, thanks a lot for your time and work!

./resources/lib/util/pymoonlighthelper.py: (Note here also the changed class name of 'plugin' to 'core' in line self.core.get_setting('enable_moonlight_debug')

def launch_game(self, game_id):
        self.config_helper.configure()
        host = self.host_context_service.get_current_context()

        (pre_script, post_script) = self.core.prepare_init_scripts()

        self.logger.info("Got script paths: %s and %s" % (pre_script, post_script))

        with open('/tmp/luna_env.tmp', 'w') as file:
            file.write(''.join(['LUNA_CONFIG = ', self.config_helper.get_config_path(), '\n', 'LUNA_DEBUG = ', self.core.get_setting('enable_moonlight_debug'), '\n', 'LUNA_APP = ', game_id, '\n']))

        # Start systemd service
        subprocess.Popen(['/bin/sh /home/pi/start_moonlight.sh'])

with the shell scripts

/home/pi/start_moonlight.sh:

#!/bin/sh
rm /tmp/start_moonlight.log -f
echo "starting kodi-moonlight.service" > /tmp/start_moonlight.log
systemctl --user start kodi-moonlight.service
echo "done" >> /tmp/start_moonlight.log
exit

and /home/pi/stop_kodi_soft.sh:

#!/bin/sh
rm /tmp/stop_kodi_soft.log -f
# check if kodi is running
kodi_pid=$(ps aux | grep -i pi | grep -v grep | grep -i kodi_v7.bin | awk '{print $2}')
if [ -z "$kodi_pid" ]
then
        echo "No kodi instances running, finished" > /tmp/stop_kodi_soft.log
        exit
fi

old_kodi_pid=kodi_pid
echo "Found kodi instance with PID $kodi_pid, send quit command" >> /tmp/stop_kodi_soft.log
/home/pi/kodi-send.py --action=quit
# wait for kodi to exit
sleep 10
# refresh kodi pid
kodi_pid=$(ps aux | grep -i pi | grep -v grep | grep -i kodi_v7.bin | awk '{print $2}')
if [ -z "$kodi_pid" ]
then
        echo "No kodi instances anymore running, finished" >> /tmp/stop_kodi_soft.log
        exit
else
        if [ $old_kodi_pid = $kodi_pid  ]
        then
                echo "kodi is still running, will kill it now the hard way" >> /tmp/stop_kodi_soft.log
                kill -9 $kodi_pid
        else
                echo "Seems kodi has been restarted with another PID $kodi_pid, kill this" >> /tmp/stop_kodi_soft.log
                kill -9 $kodi_pid
        fi
exit
fi

Along with the systemd services /home/pi/.config/systemd/user/kodi.service:

[Unit]
Description = Starts an instance of Kodi
[Service]
Type = simple
ExecStart = /usr/bin/kodi
Restart = on-failure
[Install]
WantedBy = default.target

and /home/pi/.config/systemd/user/kodi-moonlight.service:

[Unit]
Description = Start Moonlight from Kodi, with Luna
[Service]
Type = simple
EnvironmentFile = /tmp/luna_env.tmp
ExecStartPre = /home/pi/stop_kodi_soft.sh
ExecStart = /usr/local/bin/moonlight stream -app ${LUNA_APP} -config ${LUNA_CONFIG} -1080
ExecStopPost = /bin/systemctl --user start kodi
FailureAction = /bin/systemctl --user start kodi
danielfmo commented 7 years ago

Hello all,

I seek some guidance, I have and ODROID C2 with Ubuntu 16.04 and I'm trying to setup kodi 17 with moonlight and luna.

Unfortunately I'm not able to make luna launch moonlight, I've followed this in order to make kodi start at boot: http://kodi.wiki/view/Archive:HOW-TO:Autostart_Kodi_for_Linux

With that service definition running 'systemctl --user start/stop kodi' does nothing.

/etc/systemd/user/kodi.service

[Unit]
Description = Kodi Media Center
After = systemd-user-sessions.service network.target sound.target

[Service]
User = odroid
Group = odroid
Type = simple
PAMName = login
ExecStart = /usr/bin/xinit /usr/bin/dbus-launch --exit-with-session /usr/bin/kodi-standalone -- :0 -nolisten tcp vt7
Restart = on-failure
RestartSec = 5

[Install]
WantedBy = default.target

/etc/systemd/user/kodi.service

[Unit]
Description = Start Moonlight from Kodi, with Luna

[Service]
Type = simple
ExecStartPre = /bin/systemctl --user stop kodi
ExecStart = /usr/local/bin/moonlight stream -app ${LUNA_APP} -config ${LUNA_CONFIG} -audio hdmi
ExecStopPost = /bin/systemctl --user start kodi
FailureAction = /bin/systemctl --user start kodi
EnvironmentFile = /tmp/luna_env.tmp

/var/log/syslog Jul 16 16:30:38 odroid64 systemd[822]: [/home/odroid/kodi-moonlight.service:9] Failed to parse failure action specifier, ignoring: /bin/systemctl --user start kodi

Thank you

hubertokf commented 5 years ago

trying to reproduce it with kodi 18 and latest versions, I got this error trying go start a game `19:48:26.688 T:1226830576 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--

Well, I made start_moonlight.sh executable but no success

wackerl91 commented 5 years ago

@hubertokf No idea what you're trying to run there, but the launch script obviously doesn't exist at the mentioned location. Please contact the person where you got this version of Luna from - the file mentioned in the logs has never been a part of any of my versions, so I won't be able to help you out here.

Pawe98 commented 5 years ago

Look at issue: https://github.com/wackerl91/luna/issues/171

But I don't understand your provided logs