Add new features

This commit is contained in:
Gustavo 2016-02-16 17:16:57 -02:00
parent ccfacceba7
commit f950c24f8e
7 changed files with 177 additions and 63 deletions

View file

@ -1 +1,15 @@
# moonlight-openelec-rpi2 #script.moonlight
Only for Raspberry Pi 2 and Openelec.
##Installation
- Download a release
- Copy the file to the Openelec
- Go to Settings > Addons > Install from zip file
##Features
- Pair
- List availables games
- Stream
##Bugs
- Feel free to open a issue.

View file

@ -1,5 +1,91 @@
import os import os
import sys
import urllib
import urlparse
import xbmcgui
import xbmcplugin
import xbmcaddon
import re
import subprocess
with open('/storage/.kodi/addons/script.moonlight/start_moonlight.tmp', 'w') as f: my_addon = xbmcaddon.Addon()
f.write("open moonlight") my_env = os.environ.copy()
my_env["LD_LIBRARY_PATH"] = my_addon.getAddonInfo("path")+"/libs:" + my_env["LD_LIBRARY_PATH"]
base_url = sys.argv[0]
addon_handle = int(sys.argv[1])
args = urlparse.parse_qs(sys.argv[2][1:])
xbmcplugin.setContent(addon_handle, 'files')
def build_url(query):
return base_url + '?' + urllib.urlencode(query)
mode = args.get('mode', None)
if mode is None:
xbmcplugin.addDirectoryItem(handle=addon_handle,
url=build_url({'mode': 'pair'}),
listitem=xbmcgui.ListItem('Pair'),
isFolder=False)
xbmcplugin.addDirectoryItem(handle=addon_handle,
url=build_url({'mode': 'list'}),
listitem=xbmcgui.ListItem('List Games'),
isFolder=True)
xbmcplugin.addDirectoryItem(handle=addon_handle,
url=build_url({'mode': 'stream', 'app': ''}),
listitem=xbmcgui.ListItem('Stream Default'),
isFolder=False)
xbmcplugin.endOfDirectory(addon_handle)
elif mode[0] == "pair":
pair_args = ["pair"]
if my_addon.getSetting("MOON_SERVER_IP") != "0.0.0.0":
pair_args += [my_addon.getSetting("MOON_SERVER_IP")]
p = subprocess.Popen([my_addon.getAddonInfo("path") + "/bin/moonlight"] + pair_args, stdout=subprocess.PIPE, env=my_env)
pin = ""
while True:
l = p.stdout.readline()
if "following PIN" in l:
m = re.search(':\s(\d+)', l)
pin = m.group(0)
break
dialog = xbmcgui.Dialog()
dialog.ok("PIN code", "Insert the pin code in server: %s" % pin)
ret = ''.join(p.stdout.readlines())
if "Succesfully paired" in ret:
dialog = xbmcgui.Dialog()
dialog.ok("Paired", "Succesfully paired")
else:
dialog = xbmcgui.Dialog()
dialog.ok("Error", "Failed to pair to server")
elif mode[0] == "list":
list_args = ["list"]
if my_addon.getSetting("MOON_SERVER_IP") != "0.0.0.0":
list_args += [my_addon.getSetting("MOON_SERVER_IP")]
p = subprocess.Popen([my_addon.getAddonInfo("path") + "/bin/moonlight"] + list_args, stdout=subprocess.PIPE, env=my_env)
ret = ''.join(p.stdout.readlines()).strip()
m = re.findall(r"\d.\s(.*?)\n|$", ret)
for game in list(m):
name = game.strip()
if name != "":
xbmcplugin.addDirectoryItem(handle=addon_handle,
url=build_url({'mode': 'stream', 'app': name}),
listitem=xbmcgui.ListItem(name),
isFolder=False)
xbmcplugin.endOfDirectory(addon_handle)
elif mode[0] == "stream":
app = args.get('app', None)
with open(my_addon.getAddonInfo("path") + '/start_moonlight.tmp', 'w') as f:
if app is None:
f.write("")
else:
f.write(app[0])

View file

@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.moonlight" name="Moonlight" version="1.0.0" provider-name="dead"> <addon id="script.moonlight" name="Moonlight" version="1.0.1" provider-name="dead">
<requires> <requires>
<import addon="xbmc.python" version="2.14.0"/> <import addon="xbmc.python" version="2.14.0"/>
</requires> </requires>
<extension point="xbmc.python.script" library="addon.py"> <extension point="xbmc.python.pluginsource" library="addon.py">
<provides>executable</provides> <provides>executable</provides>
</extension> </extension>
<extension point="xbmc.service" library="service.py"> <extension point="xbmc.service" library="service.py">
</extension> </extension>
<extension point="xbmc.addon.metadata"> <extension point="xbmc.addon.metadata">
<platform>all</platform> <platform>linux</platform>
<summary lang="en">Run moonlight</summary> <summary lang="en">Run moonlight</summary>
<description lang="en">Run moonlight</description> <description lang="en">Run moonlight</description>
<license>GNU General Public License, v2</license> <license>GNU General Public License, v2</license>

View file

@ -1,12 +1,23 @@
#!/bin/sh #!/bin/sh
. /etc/profile . /etc/profile
oe_setup_addon script.moonlight oe_setup_addon script.moonlight
export LD_LIBRARY_PATH=$ADDON_DIR/libs:$LD_LIBRARY_PATH export LD_LIBRARY_PATH=$ADDON_DIR/libs:$LD_LIBRARY_PATH
chmod a+x $ADDON_DIR/bin/* chmod a+x $ADDON_DIR/bin/*
while [ 1 ]
do
if [ -f $ADDON_DIR/start_moonlight.tmp ]
then
oe_setup_addon script.moonlight
MOONLIGHT_APP=`cat $ADDON_DIR/start_moonlight.tmp`
rm $ADDON_DIR/start_moonlight.tmp
MOONLIGHT_ARG="" MOONLIGHT_ARG=""
if [ "$MOON_PACKETSIZE" != "0" ]; then if [ "$MOON_PACKETSIZE" != "0" ]; then
@ -50,19 +61,17 @@ if [ "$MOON_REMOTE" = "true" ]; then
fi fi
if [ "$MOON_MAPPING" != "" ]; then if [ "$MOON_MAPPING" != "" ]; then
MOONLIGHT_ARG="$MOONLIGHT_ARG -mapping $ADDON_DIR/bin/mappings/$MOON_MAPPING.conf" MOONLIGHT_ARG="$MOONLIGHT_ARG -mapping \"${ADDON_DIR}/bin/mappings/${MOON_MAPPING}.conf\""
fi
if [ "$MOONLIGHT_APP" != "" ]; then
MOONLIGHT_ARG="$MOONLIGHT_ARG -app \"${MOONLIGHT_APP}\""
fi fi
if [ "$MOON_SERVER_IP" != "0.0.0.0" ]; then if [ "$MOON_SERVER_IP" != "0.0.0.0" ]; then
MOONLIGHT_ARG="$MOONLIGHT_ARG $MOON_SERVER_IP" MOONLIGHT_ARG="$MOONLIGHT_ARG $MOON_SERVER_IP"
fi fi
while [ 1 ]
do
if [ -f $ADDON_DIR/start_moonlight.tmp ]
then
rm $ADDON_DIR/start_moonlight.tmp
if pgrep "kodi.bin" > /dev/null if pgrep "kodi.bin" > /dev/null
then then
systemctl stop kodi systemctl stop kodi
@ -70,7 +79,7 @@ do
modprobe snd_bcm2835 modprobe snd_bcm2835
echo $MOONLIGHT_ARG >> $ADDON_LOG_FILE echo $MOONLIGHT_ARG >> $ADDON_LOG_FILE
$ADDON_DIR/bin/moonlight $MOONLIGHT_ARG stream >> $ADDON_LOG_FILE 2>&1 /bin/sh -c "${ADDON_DIR}/bin/moonlight ${MOONLIGHT_ARG} stream >> ${ADDON_LOG_FILE} 2>&1"
rmmod snd_bcm2835 rmmod snd_bcm2835
systemctl start kodi systemctl start kodi
fi fi

View file

@ -1 +1,5 @@
1.0.0 Initial Release v1.0.1
Add Pair and List Options
v1.0.0
Initial Release

View file

@ -1,14 +1,15 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<settings> <settings>
<setting id="MOON_SERVER_IP" type="text" label="Server IP" default="0.0.0.0"/> <setting id="MOON_SERVER_IP" type="ipaddress" label="Server IP" default="0.0.0.0"/>
<setting id="MOON_RESOLUTION" type="select" values="720p|1080p" label="Resolution" default="720p" /> <setting id="MOON_RESOLUTION" type="select" values="720p|1080p" label="Resolution" default="720p" />
<setting id="MOON_FRAMERATE" type="select" values="30|60" label="FPS" default="30" /> <setting id="MOON_FRAMERATE" type="select" values="30|60" label="FPS" default="30" />
<setting id="MOON_BITRATE" type="text" label="Bitrate" default="10000" /> <setting id="MOON_BITRATE" type="text" label="Bitrate" default="10000" />
<setting id="MOON_PACKETSIZE" type="text" label="Packet Size (lower than MTU)" default="1400" /> <setting id="MOON_PACKETSIZE" type="text" label="Packet Size" default="1024" />
<setting type="sep" /> <setting type="sep" />
<setting id="MOON_REMOTE" type="bool" label="Remote Optimizations" default="false"/> <setting id="MOON_REMOTE" type="bool" label="Remote Optimizations" default="false"/>
<setting id="MOON_NOSOPS" type="bool" label="Don't allow GFE to modify game settings" default="false"/> <setting id="MOON_NOSOPS" type="bool" label="Don't allow GFE to modify game settings" default="false"/>
<setting id="MOON_LOCALAUDIO" type="bool" label="Play audio locally" default="false"/> <setting id="MOON_LOCALAUDIO" type="bool" label="Play audio locally" default="false"/>
<setting id="MOON_SURROUND" type="bool" label="Stream 5.1 surround sound (requires GFE 2.7)" default="false"/> <setting id="MOON_SURROUND" type="bool" label="Stream 5.1 surround sound (requires GFE 2.7)" default="false"/>
<setting id="MOON_FORCEHW" type="bool" label="Force hardware acceleration" default="true"/> <setting id="MOON_FORCEHW" type="bool" label="Force hardware acceleration" default="true"/>
<setting id="MOON_MAPPING" type="text" label="Control Mapping" default="dualshock4" /> <setting id="MOON_MAPPING" type="select" label="Control Mapping" values="default|dualschock3|dualshock4|rumblepad2|xbox360" default="dualshock4" />
</settings> </settings>

View file

@ -5,7 +5,7 @@
<setting id="MOON_LOCALAUDIO" value="false" /> <setting id="MOON_LOCALAUDIO" value="false" />
<setting id="MOON_MAPPING" value="dualshock4" /> <setting id="MOON_MAPPING" value="dualshock4" />
<setting id="MOON_NOSOPS" value="false" /> <setting id="MOON_NOSOPS" value="false" />
<setting id="MOON_PACKETSIZE" value="1400" /> <setting id="MOON_PACKETSIZE" value="1024" />
<setting id="MOON_REMOTE" value="false" /> <setting id="MOON_REMOTE" value="false" />
<setting id="MOON_RESOLUTION" value="720p" /> <setting id="MOON_RESOLUTION" value="720p" />
<setting id="MOON_SERVER_IP" value="0.0.0.0" /> <setting id="MOON_SERVER_IP" value="0.0.0.0" />