-
Notifications
You must be signed in to change notification settings - Fork 0
/
_UpdateMoonlightGamesList.sh
139 lines (120 loc) · 4.81 KB
/
_UpdateMoonlightGamesList.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
# Global variables, leave empty if you don't want to use them
MOONLIGHT_PATH="/home/pi/RetroPie/roms/moonlight" #Full path to the location of the Moonlight roms folder
STREAMINGHOST="192.168.1.5" #Streaming host's IP adress or hostname
RESOLUTION="1080" #720/1080/4K
FPS="60" #30/60 etc.
BITRATE= #Bitrate in Kbps
REMOTE="Yes" #"Yes" or 1 for remote optimization, empty otherwise
AUDIO= #"local" for local audio, empty otherwise
PLATFORM="pi" #pi/imx/aml/rk/x11/x11_vdpau/sdl/fake/auto, empty otherwise
QUITAPPAFTER="Yes" #"Yes" or 1 for quitting app after ending streaming session, empty otherwise
#Check if game server is online AND Moonlight returns a game list from the game server, terminate script otherwise
sudo -u pi timeout 2 moonlight list $STREAMINGHOST | grep '^[0-9][0-9.]' | cut -d "." -f2 | sed 's/^ \(.*\)$/\1/' | if ! IFS= read -r
then
echo "Game server unreachable or no games listed by Moonlight on the game server..."
sleep 3
exit 1
else
# Set script variables
_STREAMINGHOST=""
if [ "$STREAMINGHOST" != "" ]
then
_STREAMINGHOST=" $STREAMINGHOST"
fi
_RESOLUTION=""
if [ "$RESOLUTION" != "" ]
then
_RESOLUTION=" -$RESOLUTION"
fi
_FPS=""
if [ "$FPS" != "" ]
then
_FPS=" -fps $FPS"
fi
_BITRATE=""
if [ "$BITRATE" != "" ]
then
_BITRATE=" -bitrate $BITRATE"
fi
_REMOTE=""
if [ "$REMOTE" = "YES" ] || [ "$REMOTE" = 1 ] || [ "$REMOTE" = "Yes" ] || [ "$REMOTE" = "yes" ]
then
_REMOTE=" -remote"
fi
_AUDIO=""
if [ "$AUDIO" = "local" ]
then
_AUDIO=" -audio local"
fi
_PLATFORM=""
if [ "$PLATFORM" = "pi" ] || [ "$PLATFORM" = "imx" ] || [ "$PLATFORM" = "aml" ] || [ "$PLATFORM" = "rk" ] || [ "$PLATFORM" = "x11" ] || [ "$PLATFORM" = "x11_vdpau" ] || [ "$PLATFORM" = "sdl" ] || [ "$PLATFORM" = "fake" ] || [ "$PLATFORM" = "auto" ]
then
_PLATFORM=" -platform $PLATFORM"
fi
_QUITAPPAFTER=""
if [ "$QUITAPPAFTER" = "YES" ] || [ "$QUITAPPAFTER" = 1 ] || [ "$QUITAPPAFTER" = "Yes" ] || [ "$QUITAPPAFTER" = "yes" ]
then
_QUITAPPAFTER=" -quitappafter"
fi
#Delete old and existing script generated Moonlight game files
OLD_IFS="$IFS"
IFS=
echo "Deleting...:"
grep -l --exclude="_UpdateMoonlightGamesList.sh" "#Autocreated by UpdateMoonlightGamesList.sh" $MOONLIGHT_PATH/*.sh | while read -r LINE; do
sudo rm $LINE
echo $LINE
done
IFS="$OLD_IFS"
echo ""
#Make list of moonlight games borrowed from https://github.com/rpf16rj/moonlight_script_retropie
# sudo -u pi moonlight list | grep '^[0-9][0-9.]' | cut -d "." -f2 | sed 's/^ \(.*\)$/\1/' >> gamesreal.txt
# sudo -u pi moonlight list | grep '^[0-9][0-9.]' | cut -d "." -f2 | sed 's/[^a-z A-Z 0-9 -]//g' >> games.txt
#Generate new script files from Moonlight listed games on game server
OLD_IFS="$IFS"
IFS= #Make read command reade entire lines and not divide into words
CNTR=0
CNTR2=0
CNTR3=0
ARR1[0]=""
ARR2[0]=""
while read -r LINE ;do
echo $LINE".sh:"
#Check if file already exists and exclude
if IFS= read -r ;then
ARR1[$CNTR]=$LINE
((CNTR++))
echo $LINE" already exists and was created from another source, will not overwrite."
#If file doesn't exist, create new file
else
ARR2[$CNTR2]=$LINE
echo "#!/bin/bash" | sudo tee -a $MOONLIGHT_PATH/$LINE.sh
echo "#Autocreated by UpdateMoonlightGamesList.sh" | sudo tee -a $MOONLIGHT_PATH/$LINE.sh
echo "moonlight stream"$_RESOLUTION$_FPS$_BITRATE$_REMOTE$_AUDIO$_PLATFORM$_QUITAPPAFTER" -app \"$LINE\""$_STREAMINGHOST | sudo tee -a $MOONLIGHT_PATH/$LINE.sh
((CNTR2++))
fi< <(find $MOONLIGHT_PATH -name $LINE".sh")
((CNTR3++))
#ProcessSubstitution to prevent subshell and thereby being able to use variables from while loop outside the loop
done < <(sudo -u pi timeout 2 moonlight list $STREAMINGHOST | grep '^[0-9][0-9.]' | cut -d "." -f2 | sed 's/^ \(.*\)$/\1/')
#Sum up and print operations
echo ""
echo $CNTR"/"$CNTR3" game files were not created from Moonlight, because the files already existed or were created from another source:"
for ITEM in ${ARR1[*]}
do
printf " %s\n" $ITEM".sh"
done
echo ""
echo $CNTR2"/"$CNTR3" game files were created from Moonlight:"
for ITEM in ${ARR2[*]}
do
printf " %s\n" $ITEM".sh"
done
IFS="$OLD_IFS"
#Exit script and restart Emulationstation to update Moonlight games list
echo""
echo "Now restarting EmulationStation..."
sudo -u pi touch /tmp/es-restart
sudo -u pi kill $(pgrep -l -n emulationstatio | awk '!/grep/ {printf "%s ",$1}')
sleep 3
#sudo -u pi rm /tmp/es-restart
fi