Add new features
This commit is contained in:
parent
ccfacceba7
commit
f950c24f8e
7 changed files with 177 additions and 63 deletions
16
README.md
16
README.md
|
@ -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.
|
||||
|
|
|
@ -1,5 +1,91 @@
|
|||
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:
|
||||
f.write("open moonlight")
|
||||
my_addon = xbmcaddon.Addon()
|
||||
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])
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
<?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>
|
||||
<import addon="xbmc.python" version="2.14.0"/>
|
||||
</requires>
|
||||
<extension point="xbmc.python.script" library="addon.py">
|
||||
<extension point="xbmc.python.pluginsource" library="addon.py">
|
||||
<provides>executable</provides>
|
||||
</extension>
|
||||
<extension point="xbmc.service" library="service.py">
|
||||
</extension>
|
||||
<extension point="xbmc.addon.metadata">
|
||||
<platform>all</platform>
|
||||
<platform>linux</platform>
|
||||
<summary lang="en">Run moonlight</summary>
|
||||
<description lang="en">Run moonlight</description>
|
||||
<license>GNU General Public License, v2</license>
|
||||
|
|
|
@ -1,68 +1,77 @@
|
|||
#!/bin/sh
|
||||
|
||||
. /etc/profile
|
||||
|
||||
oe_setup_addon script.moonlight
|
||||
|
||||
export LD_LIBRARY_PATH=$ADDON_DIR/libs:$LD_LIBRARY_PATH
|
||||
|
||||
chmod a+x $ADDON_DIR/bin/*
|
||||
|
||||
MOONLIGHT_ARG=""
|
||||
|
||||
if [ "$MOON_PACKETSIZE" != "0" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -packetsize $MOON_PACKETSIZE"
|
||||
fi
|
||||
|
||||
if [ "$MOON_BITRATE" != "0" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -bitrate $MOON_BITRATE"
|
||||
fi
|
||||
|
||||
if [ "$MOON_RESOLUTION" = "720p" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -720"
|
||||
else
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -1080"
|
||||
fi
|
||||
|
||||
if [ "$MOON_FRAMERATE" = "60" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -60fps"
|
||||
else
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -30fps"
|
||||
fi
|
||||
|
||||
if [ "$MOON_FORCEHW" = "true" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -forcehw"
|
||||
fi
|
||||
|
||||
if [ "$MOON_SURROUND" = "true" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -surround"
|
||||
fi
|
||||
|
||||
if [ "$MOON_LOCALAUDIO" = "true" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -localaudio"
|
||||
fi
|
||||
|
||||
if [ "$MOON_NOSOPS" = "true" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -nosops"
|
||||
fi
|
||||
|
||||
if [ "$MOON_REMOTE" = "true" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -remote"
|
||||
fi
|
||||
|
||||
if [ "$MOON_MAPPING" != "" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -mapping $ADDON_DIR/bin/mappings/$MOON_MAPPING.conf"
|
||||
fi
|
||||
|
||||
if [ "$MOON_SERVER_IP" != "0.0.0.0" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG $MOON_SERVER_IP"
|
||||
fi
|
||||
|
||||
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=""
|
||||
|
||||
if [ "$MOON_PACKETSIZE" != "0" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -packetsize $MOON_PACKETSIZE"
|
||||
fi
|
||||
|
||||
if [ "$MOON_BITRATE" != "0" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -bitrate $MOON_BITRATE"
|
||||
fi
|
||||
|
||||
if [ "$MOON_RESOLUTION" = "720p" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -720"
|
||||
else
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -1080"
|
||||
fi
|
||||
|
||||
if [ "$MOON_FRAMERATE" = "60" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -60fps"
|
||||
else
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -30fps"
|
||||
fi
|
||||
|
||||
if [ "$MOON_FORCEHW" = "true" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -forcehw"
|
||||
fi
|
||||
|
||||
if [ "$MOON_SURROUND" = "true" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -surround"
|
||||
fi
|
||||
|
||||
if [ "$MOON_LOCALAUDIO" = "true" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -localaudio"
|
||||
fi
|
||||
|
||||
if [ "$MOON_NOSOPS" = "true" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -nosops"
|
||||
fi
|
||||
|
||||
if [ "$MOON_REMOTE" = "true" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG -remote"
|
||||
fi
|
||||
|
||||
if [ "$MOON_MAPPING" != "" ]; then
|
||||
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
|
||||
|
||||
if [ "$MOON_SERVER_IP" != "0.0.0.0" ]; then
|
||||
MOONLIGHT_ARG="$MOONLIGHT_ARG $MOON_SERVER_IP"
|
||||
fi
|
||||
|
||||
if pgrep "kodi.bin" > /dev/null
|
||||
then
|
||||
systemctl stop kodi
|
||||
|
@ -70,7 +79,7 @@ do
|
|||
|
||||
modprobe snd_bcm2835
|
||||
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
|
||||
systemctl start kodi
|
||||
fi
|
||||
|
|
|
@ -1 +1,5 @@
|
|||
1.0.0 Initial Release
|
||||
v1.0.1
|
||||
Add Pair and List Options
|
||||
|
||||
v1.0.0
|
||||
Initial Release
|
|
@ -1,14 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<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_FRAMERATE" type="select" values="30|60" label="FPS" default="30" />
|
||||
<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 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_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_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>
|
|
@ -5,7 +5,7 @@
|
|||
<setting id="MOON_LOCALAUDIO" value="false" />
|
||||
<setting id="MOON_MAPPING" value="dualshock4" />
|
||||
<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_RESOLUTION" value="720p" />
|
||||
<setting id="MOON_SERVER_IP" value="0.0.0.0" />
|
||||
|
|
Loading…
Reference in a new issue