-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_UpdateMoonlightQtGamesList.sh
202 lines (184 loc) · 7.72 KB
/
_UpdateMoonlightQtGamesList.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/bin/bash
# Global variables, required for script to work
GSTREAMHOSTNO="1" #Number of the game streaming server from the Moonlight.conf that you want to use (default=1)
MOONLIGHT_PATH="/home/pi/RetroPie/roms/moonlight-qt" #Path to RetroPie Moonlight ROMS folder
STREAMINGHOST="$(cat ~/.config/Moonlight\ Game\ Streaming\ Project/Moonlight.conf | grep "^$GSTREAMINGHOSTNO" | grep "\\localaddress=" | cut -d "=" -f2 | sed "s/ *$//g")"
#STREAMINGHOST="192.168.0.10" #Game streaming server's IP adress or hostname, optionally set manually here instead of automatically above
GLOBALSETTINGS="Yes" #"Yes" to use global settings from GUI settings or "No"/empty to use local settings below
# Optional global variables below, only relevant to set if you have set the above GLOBALSETTINGS variable to "No"/empty.
# Leave empty if you don't want to use or want du use default values
RESOLUTION="1080" #720/1080/4K
FPS="60" #30/60/120
BITRATE="" #Bitrate in Kbps
VSYNC="Yes" #"Yes" for VSYNC, "No"/empty otherwise
FRAMEPACING="Yes" #"Yes" for frame pacing, "No"/empty otherwise
VIDEOCODEC="auto" #H.264/HEVC/auto
VIDEODECODER="auto" #auto/hardware/software
REMOTE="Yes" #"Yes" or 1 for remote optimization, empty otherwise
AUDIO="local" #"local" for local audio, empty for audio on remote host
AUDIOCONFIG="stereo" #"5.1-surround" for surround, "stereo"/empty for stereo
MULTICONTROLLER="Yes" #"Yes" for multiple controller support, "No"/empty otherwise
MOUSEACCELERATION="Yes" #"Yes" for mouse acceleration, "No"/empty otherwise
QUITAPPAFTER="Yes" #"Yes" or 1 for quitting app after ending streaming session, empty otherwise
#Check for "list" parameter to list streamable game titles from FIRST game streaming server in file ~/.config/Moonlight\ Game\ Streaming\ Project/Moonlight.conf
#sudo -u pi timeout 2 moonlight list $STREAMINGHOST | grep '^[0-9][0-9.]' | cut -d "." -f2 | sed 's/^ \(.*\)$/\1/' | if ! IFS= read -r
if [ "$1" = "list" ]
then
printf "$(cat ~/.config/Moonlight\ Game\ Streaming\ Project/Moonlight.conf | grep "^$GSTREAMHOSTNO" | grep '\\name=' | cut -d "=" -f2 | sed "s/\\\x/\\\u/g" | sed "s/\"/\ /g" | sed 's/^ \(.*\)$/\1/' | sed "s/ *$//g")\n" /e
exit 1
elif [ "$1" != "" ]
then
echo "Invalid argument\n"
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
_VSYNC=""
if [ "$VSYNC" = "YES" ] || [ "$VSYNC" = 1 ] || [ "$VSYNC" = "Yes" ] || [ "$VSYNC" = "yes" ]
then
_VSYNC=" --vsync"
else
-VSYNC=" --no-vsync"
fi
_FRAMEPACING=""
if [ "$FRAMEPACING" = "YES" ] || [ "$FRAMEPACING" = 1 ] || [ "$FRAMEPACING" = "Yes" ] || [ "$FRAMEPACING" = "yes" ]
then
_FRAMEPACING=" --frame-pacing"
else
_FRAMEPACING=" --no-frame-pacing"
fi
_VIDEOCODEC=""
if [ "$VIDEOCODEC" != "" ]
then
_VIDEOCODEC=" --video-codec $VIDEOCODEC"
fi
_VIDEODECODER=""
if [ "$VIDEODECODER" != "" ]
then
_VIDEODECODER=" --video-decoder $VIDEODECODER"
fi
_REMOTE=""
if [ "$REMOTE" = "YES" ] || [ "$REMOTE" = 1 ] || [ "$REMOTE" = "Yes" ] || [ "$REMOTE" = "yes" ]
then
_REMOTE=" --game-optimization"
else
_REMOTE=" --no-game-optimization"
fi
_AUDIO=""
if [ "$AUDIO" = "local" ]
then
_AUDIO=" --no-audio-on-host"
else
_AUDIO=" --audio-on-host"
fi
_AUDIOCONFIG=""
if [ "$AUDIOCONFIG" != "" ]
then
_AUDIOCONFIG=" --audio-config $AUDIOCONFIG"
fi
_MULTICONTROLLER=""
if [ "$MULTICONTROLLER" = "YES" ] || [ "$MULTICONTROLLER" = 1 ] || [ "$MULTICONTROLLER" = "Yes" ] || [ "$MULTICONTROLLER" = "yes" ]
then
_MULTICONTROLLER=" --multi-controller"
else
_MULTICONTROLLER=" --no-multi-controller"
fi
_MOUSEACCELERATION=""
if [ "$MOUSEACCELERATION" = "YES" ] || [ "$MOUSEACCELERATION" = 1 ] || [ "$MOUSEACCELERATION" = "Yes" ] || [ "$MOUSEACCELERATION" = "yes" ]
then
_MOUSEACCELERATION=" --mouse-acceleration"
else
_MOUSEACCELERATION=" --no-mouse-acceleration"
fi
_QUITAPPAFTER=""
if [ "$QUITAPPAFTER" = "YES" ] || [ "$QUITAPPAFTER" = 1 ] || [ "$QUITAPPAFTER" = "Yes" ] || [ "$QUITAPPAFTER" = "yes" ]
then
_QUITAPPAFTER=" --quit-after"
else
_QUITAPPAFTER=" --no-quit-after"
fi
#Delete old and existing script generated Moonlight game files
OLD_IFS="$IFS"
IFS=
echo "Deleting...:"
grep -l --exclude="_UpdateMoonlightQtGamesList.sh" "#Autocreated by UpdateMoonlightQtGamesList.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 UpdateMoonlightQtGamesList.sh" | sudo tee -a $MOONLIGHT_PATH/$LINE.sh
if [ "$GLOBALSETTINGS" = "YES" ] || [ "$GLOBALSETTINGS" = 1 ] || [ "$GLOBALSETTINGS" = "Yes" ] || [ "$GLOBALSETTINGS" = "yes" ]
then
echo "moonlight-qt stream"$_STREAMINGHOST" \"$LINE\"" | sudo tee -a $MOONLIGHT_PATH/$LINE.sh
else
echo "moonlight-qt"$_RESOLUTION$_FPS$_BITRATE$_VSYNC$_FRAMEPACING$_VIDEOCODEC$_VIDEODECODER$_REMOTE$_AUDIO$_AUDIOCONFIG$_MULTICONTROLLER$_MOUSEACCELERATION$_QUITAPPAFTER" stream"$_STREAMINGHOST" \"$LINE\"" | sudo tee -a $MOONLIGHT_PATH/$LINE.sh
fi
((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 < <(printf "$(cat ~/.config/Moonlight\ Game\ Streaming\ Project/Moonlight.conf | grep "^$GSTREAMHOSTNO" | grep '\\name=' | cut -d "=" -f2 | sed "s/\\\x/\\\u/g" | sed "s/\"/\ /g" | sed 's/^ \(.*\)$/\1/' | sed "s/ *$//g")\n" /e)
#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