· 5 years ago · Feb 14, 2021, 03:26 PM
1#! /bin/bash
2
3filelocation="/home/cas/scripts" # full path to advancedplexapi.sh without / at the end
4plexapitoken="[[plexapitoken]]" # the api token of your plex server
5ipplexserver="192.168.2.15" # the ip adress of your plex server
6logfolder="/home/cas/scripts/logs" # full path to folder where log file needs to be stored without / at the end
7sonarrapitoken="[[sonarrapitoken]]" # the api token of your sonarr server
8ipsonarrserver="192.168.2.15" # the ip adress of your sonarr server
9sonarrport="8989" # the port sonarr is available on
10
11echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user started script" >> $logfolder/advancedplexapi.log 2>&1
12
13a=0
14
15while [ $a = 0 ]
16do
17clear
18echo "--------------------------------"
19echo -e "plex\nsonarr"
20echo "--------------------------------"
21read -rp "exit | Choose one of these options: " selection
22
23echo "$(date '+%d/%m/%Y %H:%M:%S') | option | $selection" >> $logfolder/advancedplexapi.log 2>&1
24
25if [[ ${selection,,} = plex ]]
26then
27
28#------------------------------------------------------------Plex Api--------------------------------------------------
29n=0
30re='^[0-9]+$'
31while [ $n = 0 ]
32do
33#commenting the clear command below will have the following effect:
34#commented/inactive=after choosing an option, leading to a new page, the previous page won't be cleared. You can scroll back up to see your history
35#un-commented/working as a command=after choosing an option, leading to a new page, the previous page will be cleared. You cant sroll back, but it will make it cleaner and easier to navigate or view the the output of the page you're on.
36clear
37
38 path=$(head -n 1 < $filelocation/advancedplexapivar.txt)
39 location="http://$ipplexserver:32400$path?X-Plex-Token=$plexapitoken"
40 echo "$(date '+%d/%m/%Y %H:%M:%S') | path | $path" >> $logfolder/advancedplexapi.log 2>&1
41
42 if ! [[ "$path" = "root" ]]
43 then
44 GET http://$ipplexserver:32400$path?X-Plex-Token=$plexapitoken
45 fi
46
47 if [[ $path = "root" ]]
48 then
49 echo "Home page Plex API"
50 echo "--------------------------------"
51 echo -e "/\npagesearcher\nsessions\nlibrary\nhistory\nsearch\nservers\nrefresh\nonDeck\nprefs\naccount\nsystem\nagents"
52 echo "--------------------------------"
53 read -rp "back | exit | Choose one of these options: " option
54
55 elif [[ $path = /library/sections/$(curl -sSL http://$ipplexserver:32400/library/sections?X-Plex-Token=$plexapitoken | grep -Eo "key\=\"[0-9]{1,4}\"\ type\=\"show\"" | grep -Eo "[0-9]{1,4}")/all ]]
56 then
57 read -rp "Choose back | exit | series: " option
58 if ! [[ $option = "back" || $option = "exit" || $option = "series" ]]
59 then
60 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | that option is not possible here" >> $logfolder/advancedplexapi.log
61 fi
62
63 elif [[ $path = /library/onDeck ]]
64 then
65 if [[ $(GET http://$ipplexserver:32400/library/onDeck?X-Plex-Token=$plexapitoken | grep -o Part | head -n1) ]]
66 then
67 t=0
68 while [ $t = 0 ]
69 do
70 read -rp "Choose back | exit | mediainfo: " ondeckoption
71 if [[ ${ondeckoption,,} = back ]]
72 then
73 t=1
74 newlocation="root"
75 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
76
77 elif [[ ${ondeckoption,,} = exit ]]
78 then
79 t=1
80 n=1
81
82 elif [[ ${ondeckoption,,} = mediainfo ]]
83 then
84 u=0
85 while [ $u = 0 ]
86 do
87 read -rp "cancel | Choose one media file (1/$(echo "$(GET http://$ipplexserver:32400/library/onDeck?X-Plex-Token=$plexapitoken | grep -o Part | wc -w)/2" | bc)): " mediainfooption
88 if [[ ${mediainfooption,,} = cancel ]]
89 then
90 u=1
91
92 elif [[ "$mediainfooption" =~ [0-9]{1,5} ]]
93 then
94 t=1
95 u=1
96 newlocation=$(GET http://$ipplexserver:32400/library/onDeck?X-Plex-Token=$plexapitoken | grep -o "key\=\".*\" parentRatingKey" | grep -o "/.*[0-9]" | head -n "$mediainfooption" | tail -n 1)
97 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
98 fi
99 done
100 fi
101 done
102 else
103 read -rp "Choose back | exit: " option
104 fi
105
106 elif [[ $(curl -sSL $location | grep -o "streamType\=\"3\"" | head -n1) ]]
107 then
108 if [[ $(curl -sSL $location | grep "streamType\=\"3\"" | grep -o key | head -n1) ]]
109 then
110 read -rp "Choose back | exit | subtitle: " option
111 else
112 read -rp "Choose back | exit: " option
113 fi
114
115 elif [[ $path = /system || \
116 $path = /system/agents || \
117 $path = /myplex/account || \
118 $path = "/:/prefs" || \
119 $path = / || \
120 $path = /status/sessions || \
121 $path = /servers || \
122 $(curl -sSL $location | grep -o "streamType" | head -n1) || \
123 $(curl -sSL $location | grep -o '\-->' | head -n1) ]]
124 then
125 r=0
126 while [ $r = 0 ]
127 do
128 read -rp "Choose back | exit: " suboption
129 if [[ $suboption = "back" ]] || [[ $suboption = "exit" ]]
130 then
131 option=$suboption
132 r=1
133 else
134 r=0
135 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | that option is not possible here" >> $logfolder/advancedplexapi.log
136 fi
137 done
138
139 elif [[ $path = /status/sessions/history/all ]]
140 then
141 read -rp "Choose back | exit | list: " option
142
143 elif [[ $path = /library/sections ]]
144 then
145 read -rp "Choose exit | back | $(curl -sSL $location | grep -o "title\=\".*\"\ agent" | grep -o "\".*\"" | grep -o "[a-zA-Z0-9].*[a-zA-Z0-9]" | paste -sd/): " option
146
147 elif [[ $(curl -sSL $location | grep -o "type\=\"season\"" | head -n1) ]]
148 then
149 read -rp "Choose back | exit | [season number]: " option
150
151 elif [[ $(curl -sSL $location | grep -o "type\=\"episode\"" | head -n1) ]]
152 then
153 read -rp "Choose back | exit | [episode number]: " option
154
155 elif [[ $(curl -sSL $location | grep -o "type\=\"movie\"" | head -n1) ]]
156 then
157 read -rp "Choose back | exit | movies: " option
158
159 fi
160
161 echo "$(date '+%d/%m/%Y %H:%M:%S') | option | $option" >> $logfolder/advancedplexapi.log 2>&1
162
163 if [[ -z $option ]]
164 then
165 continue
166
167 elif [[ $option =~ $re ]]
168 then
169 if [[ $(curl -sSL "$location" | grep -o "type\=\"episode\"" | head -n1) ]] || [[ $(curl -sSL "$location" | grep -o "type\=\"season\"" | head -n1) ]]
170 then
171 if curl -sSL "$location" | grep -q "index\=\"$option\""
172 then
173 if [[ $(curl -sSL "$location" | grep -o "type\=\"episode\"" | head -n1) ]]
174 then
175 newlocation=$(curl -sSL "$location" | grep "index\=\"$option\"" | grep -Eo "key\=\"/library/metadata/[0-9]{1,5}\"" | grep -Eo "/.*[0-9]")
176 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
177 else
178 newlocation=$(curl -sSL "$location" | grep "index\=\"$option\"" | grep -o "key\=\".*/children" | grep -o "/.*/children")
179 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
180 fi
181 else
182 if [[ $(curl -sSL "$location" | grep -o "type\=\"episode\"" | head -n1) ]]
183 then
184 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | that episode number doesn't exist" >> $logfolder/advancedplexapi.log 2>&1
185 else
186 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | that season number doesn't exist" >> $logfolder/advancedplexapi.log 2>&1
187 fi
188 fi
189 else
190 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | inputing a number here is not an option" >> $logfolder/advancedplexapi.log 2>&1
191 fi
192
193 elif [[ ${option,,} = library ]]
194 then
195 newlocation=/library/sections
196 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
197
198 elif [[ ${option,,} = / ]]
199 then
200 newlocation=/
201 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
202
203 elif [[ ${option,,} = history ]]
204 then
205 newlocation=/status/sessions/history/all
206 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
207
208 elif [[ ${option,,} = agents ]]
209 then
210 newlocation=/system/agents
211 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
212
213 elif [[ ${option,,} = system ]]
214 then
215 newlocation=/system
216 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
217
218 elif [[ ${option,,} = account ]]
219 then
220 newlocation=/myplex/account
221 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
222
223 elif [[ ${option,,} = prefs ]]
224 then
225 newlocation=/:/prefs
226 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
227
228 elif [[ $option = onDeck ]]
229 then
230 newlocation=/library/onDeck
231 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
232
233 elif [[ ${option,,} = pagesearcher ]]
234 then
235 p=0
236 while [ $p = 0 ]
237 do
238 read -rp "cancel | Give key: " pagesearcherkey
239 if [[ ${pagesearcherkey,,} = cancel ]]
240 then
241 p=1
242 newlocation="root"
243 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
244
245 else
246 if curl -sL http://$ipplexserver:32400$pagesearcherkey?X-Plex-Token=$plexapitoken | grep -q -o MediaContainer
247 then
248 p=1
249 newlocation=$pagesearcherkey
250 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
251 else
252 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | not a valid path" >> $logfolder/advancedplexapi.log 2>&1
253 fi
254 fi
255 done
256
257 elif [[ ${option,,} = servers ]]
258 then
259 newlocation=/servers
260 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
261
262 elif [[ ${option,,} = refresh ]]
263 then
264 read -rp "Choose $(curl -sSL "http://$ipplexserver:32400/library/sections?X-Plex-Token=$plexapitoken" | grep -o "title\=\".*\"\ agent" | grep -o "\".*\"" | grep -o "[a-zA-Z0-9].*[a-zA-Z0-9]" | paste -sd/): " refreshoption
265 if [[ $refreshoption == $(curl -sSL "http://$ipplexserver:32400/library/sections?X-Plex-Token=$plexapitoken" | grep -o "title\=\".*\"\ agent" | grep -o "\".*\"" | grep -o "$refreshoption") ]]
266 then
267 curl -sSL "http://$ipplexserver:32400/library/sections/$(curl -sSL "http://$ipplexserver:32400/library/sections?X-Plex-Token=$plexapitoken" | grep "$refreshoption" | grep -Eo "key\=\"[0-9]{1,4}\"" | grep -Eo "[0-9]{1,4}")/refresh?X-Plex-Token=$plexapitoken"
268 newlocation="root"
269 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
270 fi
271
272 elif [[ ${option,,} = search ]]
273 then
274 read -rp "cancel | String to search for: " searchstring
275 if [[ ${searchstring,,} = cancel ]]
276 then
277 newlocation="root"
278 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
279 else
280 GET "http://$ipplexserver:32400/search?query=$searchstring&X-Plex-Token=$plexapitoken"
281 e=0
282 while [ $e = 0 ]
283 do
284 read -rp "Choose back | exit: " searchoption
285 if [[ ${searchoption,,} = "exit" ]]
286 then
287 e=1
288 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user quitted the script" >> $logfolder/advancedplexapi.log
289 n=1
290
291 elif [[ ${searchoption,,} = back ]]
292 then
293 e=1
294 newlocation="root"
295 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
296 else
297 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | that option is not possible here" >> $logfolder/advancedplexapi.log
298 fi
299 done
300 fi
301
302 elif [[ ${option,,} = list ]]
303 then
304 l=2
305 while [ $l -le 50 ]
306 do
307 echo "$(GET "http://$ipplexserver:32400/status/sessions/history/all?X-Plex-Token=$plexapitoken" | tail -n$l | head -n1 | grep -o grandparentTitle\=\".*\"\ type | grep -o \".*\" | grep -o [a-zA-Z0-9].*[a-zA-Z0-9]) | $(GET "http://$ipplexserver:32400/status/sessions/history/all?X-Plex-Token=$plexapitoken" | tail -n$l | head -n1 | grep -o title\=\".*\"\ grandparentTitle | grep -o \".*\") | $(GET "http://$ipplexserver:32400/status/sessions/history/all?X-Plex-Token=$plexapitoken" | tail -n$l | head -n1 | grep -Eo "key\=\"/library/metadata/[0-9]{1,6}\"" | grep -Eo "/library/metadata/[0-9]{1,6}")"
308 l=$(( l+1 ))
309 done
310 l2=0
311 while [ $l2 = 0 ]
312 do
313 read -rp "Choose back | exit: " listoption
314 if [[ ${listoption,,} = "exit" ]]
315 then
316 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user quitted the script" >> $logfolder/advancedplexapi.log
317 l2=1
318 n=1
319 elif [[ ${listoption,,} = back ]]
320 then
321 l2=1
322 newlocation="root"
323 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
324 else
325 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | that option is not possible here" >> $logfolder/advancedplexapi.log
326 fi
327 done
328
329 elif [[ ${option,,} = sessions ]]
330 then
331 s=0
332 while [ $s = 0 ]
333 do
334 clear
335 GET http://$ipplexserver:32400/status/sessions?X-Plex-Token=$plexapitoken
336 if GET "http://$ipplexserver:32400/status/sessions?X-Plex-Token=$plexapitoken" | grep -q -Eo "key\=\"/library/metadata/[0-9]{1,6}\""
337 then
338 read -rp "Choose back | exit | mediainfo: " sesoption
339 else
340 read -rp "Choose back | exit: " sesoption
341 fi
342
343 if [[ ${sesoption,,} = "exit" ]]
344 then
345 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user quitted the script" >> $logfolder/advancedplexapi.log
346 s=1
347 n=1
348
349 elif [[ ${sesoption,,} = back ]]
350 then
351 s=1
352 newlocation="root"
353 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
354
355 elif [[ ${sesoption,,} = mediainfo ]]
356 then
357 s=1
358 newlocation=$(curl -sSL "http://$ipplexserver:32400/status/sessions?X-Plex-Token=$plexapitoken" | grep -Eo "key\=\"/library/metadata/[0-9]{1,6}\"" | grep -o /.*[0-9])
359 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
360 else
361 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | that option is not possible here" >> $logfolder/advancedplexapi.log
362 fi
363 done
364
365 elif [[ ${option,,} = series ]]
366 then
367 echo "--------------------------------"
368 curl -sSL "$location" | grep -o "title\=\".*\"\ contentRating" | grep -o "\".*\"" | grep -o "[a-zA-Z0-9].*[a-zA-Z0-9]" | sort | sed 's|amp;||g' | sed "s|\'|\'|g" | sed "s|\&\#233\;|é|"
369 echo "--------------------------------"
370 z=0
371 while [ $z = 0 ]
372 do
373 read -rp "cancel | Choose one of these series: " Series
374 echo "$(date '+%d/%m/%Y %H:%M:%S') | series | $Series" >> $logfolder/advancedplexapi.log 2>&1
375 if [[ ${Series,,} = cancel ]]
376 then
377 z=1
378 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user canceled series selection" >> $logfolder/advancedplexapi.log 2>&1
379
380 elif [[ $Series =~ $re ]]
381 then
382 if [[ -z $(curl -sSL $location | grep -Eo "title\=\"$(echo $Series | sed 's|&|&|g' | sed "s|'|\'|g" | sed "s|é|\&\#233\;|")\"" | head -n1) ]]
383 then
384 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | invalid series title [numbers]" >> $logfolder/advancedplexapi.log 2>&1
385 else
386 z=1
387 Series=$(echo $Series | sed 's|&|&|g' | sed "s|'|\'|g" | sed "s|é|\&\#233\;|")
388 newlocation=$(curl -sSL $location | grep "title\=\"$Series\"" | grep -o "key\=\"/library/metadata/.*/children\"" | grep -Eo "/library.*/children")
389 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
390 fi
391
392 else
393 if [[ -z $(curl -sSL $location | grep -Eo "title\=\"$(echo $Series | sed 's|&|&|g' | sed "s|'|\'|g" | sed "s|é|\&\#233\;|")\"" | head -n1) ]]
394 then
395 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | invalid series title [letters]" >> $logfolder/advancedplexapi.log 2>&1
396 else
397 z=1
398 Series=$(echo $Series | sed 's|&|&|g' | sed "s|'|\'|g" | sed "s|é|\&\#233\;|")
399 newlocation=$(curl -sSL $location | grep "title\=\"$Series\"" | grep -o "key\=\"/library/metadata/.*/children\"" | grep -o "/library.*/children")
400 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
401 fi
402 fi
403 done
404
405 elif [[ $option == $(curl -sSL $location | grep -o "title\=\".*\"\ agent" | grep -o "\".*\"" | grep -o "$option") ]]
406 then
407 newlocation=/library/sections/$(curl -sSL $location | grep "$option" | grep -Eo key\=\""[0-9]{1,4}"\" | grep -Eo "[0-9]{1,4}")/all
408 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
409
410 elif [[ ${option,,} = movies ]]
411 then
412 echo "--------------------------------"
413 printf "$(curl -sSL $location | grep -o "title\=\".*\"\ contentRating" | grep -o "\".*\"" | grep -v titleSort && curl -sSL $location | grep -o "title\=\".*\"\ contentRating" | grep -o "\".*\"" | grep titleSort | grep -o "\".*\"\ titleSort" | grep -o "\".*\"")" | grep -o "[a-zA-Z0-9].*[a-zA-Z0-9]" | sort | sed 's|amp;||g' | sed "s|\'|\'|g" | sed "s|\&\#233\;|é|"
414 echo "--------------------------------"
415 y=0
416 while [ $y = 0 ]
417 do
418 read -rp "cancel | choose on of these movies: " Movies
419 echo "$(date '+%d/%m/%Y %H:%M:%S') | movie | $Movies" >> $logfolder/advancedplexapi.log 2>&1
420 if [[ ${Movies,,} = cancel ]]
421 then
422 y=1
423 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user canceled movie selection" >> $logfolder/advancedplexapi.log 2>&1
424
425 elif [[ $Movies =~ $re ]]
426 then
427 if [[ -z $(curl -sSL $location | grep -Eo "title\=\"$(echo $Movies | sed 's|&|&|g' | sed "s|'|\'|g" | sed "s|é|\&\#233\;|")\"" | head -n1) ]]
428 then
429 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | invalid movie title [numbers]" >> $logfolder/advancedplexapi.log 2>&1
430 else
431 y=1
432 Movies=$(echo $Movies | sed 's|&|&|g' | sed "s|'|\'|g" | sed "s|é|\&\#233\;|")
433 newlocation=$(curl -sSL $location | grep "title\=\"$Movies\"" | grep -Eo "key\=\"/library/metadata/[0-9]{1,5}\"" | grep -Eo "/library/metadata/[0-9]{1,5}")
434 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
435 fi
436
437 else
438 if [[ -z $(curl -sSL $location | grep -Eo "title\=\"$(echo $Movies | sed 's|&|&|g' | sed "s|'|\'|g" | sed "s|é|\&\#233\;|")\"" | head -n1) ]]
439 then
440 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | invalid movie title [letters]" >> $logfolder/advancedplexapi.log 2>&1
441 else
442 y=1
443 Movies=$(echo $Movies | sed 's|&|&|g' | sed "s|'|\'|g" | sed "s|é|\&\#233\;|")
444 newlocation=$(curl -sSL $location | grep "title\=\"$Movies\"" | grep -Eo "key\=\"/library/metadata/[0-9]{1,5}\"" | grep -Eo "/library/metadata/[0-9]{1,5}")
445 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
446 fi
447 fi
448 done
449
450 elif [[ ${option,,} = subtitle ]]
451 then
452 suboldlocation=$path
453 newlocation=$(curl -sSL "$location" | grep -Eo "key\=\"/library/streams/[0-9]{1,9}\"" | grep -Eo "/library/streams/[0-9]{1,9}")
454 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
455
456 elif [[ ${option,,} = back ]]
457 then
458 if [[ "$path" = /library/sections || \
459 "$path" = "/:/prefs" || \
460 "$path" = /system/agents || \
461 "$path" = /system || \
462 "$path" = /myplex/account || \
463 "$path" = /library/onDeck || \
464 "$path" = / || \
465 "$path" = /status/sessions || \
466 "$path" = /status/sessions/history/all || \
467 "$path" = /servers ]]
468 then
469 newlocation="root"
470 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
471
472 elif [[ "$path" = root ]]
473 then
474 n=2
475 else
476 case $(curl -sSL $location | grep -o "type\=\".*\"\ title\=" | grep -o "\".*\"" | grep -o "[a-zA-Z].*[a-zA-Z]" | head -n1) in
477 "show" )
478 #from all shows folder to all media folder
479 newlocation=/library/sections
480 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
481 ;;
482 "season" )
483 #from series (list of seasons) folder to all shows folder
484 newlocation=/library/sections/$(curl -sSL $location | grep -Eo librarySectionID\=\""[0-9]{1,6}"\" | grep -Eo "[0-9]{1,6}" | head -n1)/all
485 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
486 ;;
487 "episode" )
488 #from season (list of episodes in season) folder to series (list of seasons) folder
489 newlocation=/library/metadata/$(curl -sSL $location | grep -Eo parentRatingKey\=\""[0-9]{1,6}"\" | grep -Eo "[0-9]{1,6}" | head -n1)/children
490 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
491 ;;
492 "movie" )
493 if ! curl -sSL $location | grep -q streamType
494 then
495 #from all movies folder to all media folder
496 newlocation=/library/sections
497 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
498 else
499 #from movie information to all movies folder
500 newlocation=/library/sections/$(curl -sSL $location | grep -Eo librarySectionID\=\""[0-9]{1,6}"\" | grep -Eo "[0-9]{1,6}" | head -n1)/all
501 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
502 fi
503 ;;
504 * )
505 if [[ $(curl -sSL $location | grep -o '\-->' | head -n1) = "-->" ]]
506 then
507 newlocation=$suboldlocation
508 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
509 else
510 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | you can't go back here" >> $logfolder/advancedplexapi.log
511 fi
512 ;;
513 esac
514 fi
515
516 elif [[ ${option,,} = exit ]]
517 then
518 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user quitted the script" >> $logfolder/advancedplexapi.log 2>&1
519 n=1
520 else
521 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user chose invalid option" >> $logfolder/advancedplexapi.log 2>&1
522 fi
523done
524
525#Commenting the sed command below will have the following effect:
526#Commented/inactive= When you exit the plex api and access it again later, you begin where you left off the previous time.
527#Un-commented/working as a command= Everytime you use the plex api, you will begin at the start.
528#You can change root to something else.
529#What you replace it with will be the place you start at when accessing the plex api (a valid plex api location e.g. /library/sections). The starting point doesn't effect your options/actions in any way.
530#To start at the home menu of the plex api (Home page Plex API), replace it with "root"
531#DEFAULT=un-commented, root
532sed -i "s|^$path$|root|g" $filelocation/advancedplexapivar.txt 2>/dev/null
533
534if [ $n = 1 ]
535then
536a=1
537fi
538
539#------------------------------------------------------------End of Plex Api-------------------------------------------
540
541elif [[ ${selection,,} = sonarr ]]
542then
543
544#--------------------------------------------------------------Sonarr Api----------------------------------------------
545
546b=0
547re='^[0-9]+$'
548while [ $b = 0 ]
549do
550#commenting the clear command below will have the following effect:
551#commented/inactive=after choosing an option inside the sonarr api, leading to a new page, the previous page won't be cleared. You can scroll back up to see your history
552#un-commented/working as a command=after choosing an option inside the sonarr api, leading to a new page, the previous page will be cleared. You cant scroll back, but it will make it cleaner and easier to navigate or view the the output of the page you're on.
553#DEFAULT=un-commented
554clear
555
556 path=$(tail -n 1 < $filelocation/advancedplexapivar.txt | head -n 2)
557 location="http://$ipsonarrserver:$sonarrport$path?apikey=$sonarrapitoken"
558 echo "$(date '+%d/%m/%Y %H:%M:%S') | path | $path" >> $logfolder/advancedplexapi.log 2>&1
559
560 if ! [[ "$path" = "sonarrroot" ]]
561 then
562 GET "http://$ipsonarrserver:$sonarrport/api$path?apikey=$sonarrapitoken" | python3 -m json.tool
563 fi
564
565 if [[ $path = sonarrroot ]]
566 then
567 echo "Home page Sonarr API"
568 echo "--------------------------------"
569 echo -e "calendar\ndiskspace\nseries\nhistory\nmissing\nqueue\nsearch\nprofile\nrelease\nrootfolder\nseries lookup\nstatus\nbackups\ntag\ncommand\nrefresh series\nrescan series\nrsssync\nmake backup"
570 echo "--------------------------------"
571 bb=0
572 while [ $bb = 0 ]
573 do
574 read -rp "exit | back | Choose one of these options: " option
575 if [[ -z $option ]]
576 then
577 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | that option is not possible here" >> $logfolder/advancedplexapi.log
578 continue
579 else
580 bb=1
581 fi
582 done
583 fi
584
585 v=0
586 while [ $v = 0 ]
587 do
588 if [[ $path = /calendar ]]
589 then
590 read -rp "exit | back | date: " option
591
592 elif [[ $path = /command ]]
593 then
594 read -rp "exit | back | refresh: " option
595
596 elif [[ $path = /system/backup ]]
597 then
598 read -rp "exit | back | download backup: " option
599
600 elif [[ $path = /diskspace || \
601 $path = /history || \
602 $path = /wanted/missing || \
603 $path = /queue || \
604 $path = /profile || \
605 $path = /rootfolder || \
606 $path = /system/status || \
607 $path = /tag ]]
608 then
609 read -rp "exit | back: " option
610 fi
611
612 if [[ -z $option ]]
613 then
614 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user chose invalid option" >> $logfolder/advancedplexapi.log 2>&1
615 continue
616 else
617 v=1
618 fi
619 done
620
621 echo "$(date '+%d/%m/%Y %H:%M:%S') | option | $option" >> $logfolder/advancedplexapi.log 2>&1
622
623 if [[ ${option,,} = calendar ]]
624 then
625 newlocation=/calendar
626 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
627
628 elif [[ ${option,,} = diskspace ]]
629 then
630 newlocation=/diskspace
631 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
632
633 elif [[ ${option,,} = queue ]]
634 then
635 newlocation=/queue
636 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
637
638 elif [[ ${option,,} = rootfolder ]]
639 then
640 newlocation=/rootfolder
641 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
642
643 elif [[ ${option,,} = status ]]
644 then
645 newlocation=/system/status
646 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
647
648 elif [[ ${option,,} = command ]]
649 then
650 newlocation=/command
651 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
652
653 elif [[ ${option,,} = tag ]]
654 then
655 newlocation=/tag
656 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
657
658 elif [[ ${option,,} = missing ]]
659 then
660 newlocation=/wanted/missing
661 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
662
663 elif [[ ${option,,} = profile ]]
664 then
665 newlocation=/profile
666 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
667
668 elif [[ ${option,,} = backups ]]
669 then
670 newlocation=/system/backup
671 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
672
673 elif [[ ${option,,} = history ]]
674 then
675 newlocation=/history
676 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
677
678 elif [[ ${option,,} = refresh ]]
679 then
680 newlocation=$path
681 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
682
683 elif [[ ${option,,} = "refresh series" ]]
684 then
685 clear
686 curl -sSL -d '{"name": "RefreshSeries"}' -X POST http://$ipsonarrserver:$sonarrport/api/command?apikey=$sonarrapitoken | python3 -m json.tool
687 l=0
688 while [ $l = 0 ]
689 do
690 read -rp "exit | back: " refreshoption
691 if [[ ${refreshoption,,} = exit ]]
692 then
693 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user quitted the script" >> $logfolder/advancedplexapi.log 2>&1
694 l=1
695 b=1
696 elif [[ ${refreshoption,,} = back ]]
697 then
698 l=1
699 newlocation=sonarrroot
700 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
701 else
702 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user chose invalid option" >> $logfolder/advancedplexapi.log 2>&1
703 fi
704 done
705
706 elif [[ ${option,,} = "rescan series" ]]
707 then
708 clear
709 curl -sSL -d '{"name": "RescanSeries"}' -X POST http://$ipsonarrserver:$sonarrport/api/command?apikey=$sonarrapitoken | python3 -m json.tool
710 m=0
711 while [ $m = 0 ]
712 do
713 read -rp "exit | back: " rescanoption
714 if [[ ${rescanoption,,} = exit ]]
715 then
716 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user quitted the script" >> $logfolder/advancedplexapi.log 2>&1
717 m=1
718 b=1
719 elif [[ ${rescanoption,,} = back ]]
720 then
721 m=1
722 newlocation=sonarrroot
723 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
724 else
725 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user chose invalid option" >> $logfolder/advancedplexapi.log 2>&1
726 fi
727 done
728
729 elif [[ ${option,,} = "rsssync" ]]
730 then
731 clear
732 curl -sSL -d '{"name": "RssSync"}' -X POST http://$ipsonarrserver:$sonarrport/api/command?apikey=$sonarrapitoken | python3 -m json.tool
733 o=0
734 while [ $o = 0 ]
735 do
736 read -rp "exit | back: " rsssyncoption
737 if [[ ${rsssyncoption,,} = exit ]]
738 then
739 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user quitted the script" >> $logfolder/advancedplexapi.log 2>&1
740 o=1
741 b=1
742 elif [[ ${rsssyncoption,,} = back ]]
743 then
744 o=1
745 newlocation=sonarrroot
746 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
747 else
748 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user chose invalid option" >> $logfolder/advancedplexapi.log 2>&1
749 fi
750 done
751
752 elif [[ ${option,,} = "make backup" ]]
753 then
754 clear
755 curl -sSL -d '{"name": "Backup"}' -X POST http://$ipsonarrserver:$sonarrport/api/command?apikey=$sonarrapitoken | python3 -m json.tool
756 q=0
757 while [ $q = 0 ]
758 do
759 read -rp "exit | back: " makebackupoption
760 if [[ ${makebackupoption,,} = exit ]]
761 then
762 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user quitted the script" >> $logfolder/advancedplexapi.log 2>&1
763 q=1
764 b=1
765 elif [[ ${makebackupoption,,} = back ]]
766 then
767 q=1
768 newlocation=sonarrroot
769 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
770 else
771 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user chose invalid option" >> $logfolder/advancedplexapi.log 2>&1
772 fi
773 done
774
775 elif [[ ${option,,} = "download backup" ]]
776 then
777 read -rp "cancel | Give path to backup file (listed in output): " backuppath
778 if [[ ${backuppath,,} = cancel ]]
779 then
780 newlocation=/system/backup
781 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
782 else
783 wget -q "http://$ipsonarrserver:$sonarrport$backuppath"
784 ls
785 k=0
786 while [ $k = 0 ]
787 do
788 read -rp "exit | back: " downloadoption
789 if [[ ${downloadoption,,} = exit ]]
790 then
791 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user quitted the script" >> $logfolder/advancedplexapi.log 2>&1
792 k=1
793 b=1
794
795 elif [[ ${downloadoption,,} = back ]]
796 then
797 k=1
798 newlocation=sonarrroot
799 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
800 else
801 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user chose invalid option" >> $logfolder/advancedplexapi.log 2>&1
802 fi
803 done
804 fi
805
806 elif [[ ${option,,} = release ]]
807 then
808 x=0
809 while [ $x = 0 ]
810 do
811 read -rp "cancel | Give episode id: " releaseoption
812 if [[ -z $releaseoption ]]
813 then
814 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | that option is not possible here" >> $logfolder/advancedplexapi.log
815 continue
816
817 elif [[ ${releaseoption,,} = cancel ]]
818 then
819 x=1
820 newlocation=sonarrroot
821 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
822
823 else
824 x=1
825 clear
826 GET "http://$ipsonarrserver:$sonarrport/api/release?apikey=$sonarrapitoken&episodeId=$releaseoption" | python3 -m json.tool
827 read -rp "exit | back: " releasebaroption
828 if [[ ${releasebaroption,,} = exit ]]
829 then
830 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user quitted the script" >> $logfolder/advancedplexapi.log 2>&1
831 b=1
832
833 elif [[ ${releasebaroption,,} = back ]]
834 then
835 newlocation=sonarrroot
836 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
837 else
838 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user chose invalid option" >> $logfolder/advancedplexapi.log 2>&1
839 fi
840 fi
841 done
842
843 elif [[ ${option,,} = "series lookup" ]]
844 then
845 read -rp "cancel | Give name or tvdbId \(tvdb:12345\): " lookupoption
846 if [[ ${lookupoption,,} = cancel ]]
847 then
848 continue
849
850 else
851 lookupoption=$(echo $lookupoption | sed "s| |%20|g")
852 clear
853 GET "http://$ipsonarrserver:$sonarrport/api/series/lookup?term=$lookupoption&apikey=$sonarrapitoken" | python3 -m json.tool
854 j=0
855 while [ $j = 0 ]
856 do
857 read -rp "exit | back: " resultoption
858 if [[ ${resultoption,,} = exit ]]
859 then
860 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user quitted the script" >> $logfolder/advancedplexapi.log 2>&1
861 j=1
862 b=1
863
864 elif [[ ${resultoption,,} = back ]]
865 then
866 j=1
867 newlocation=sonarrroot
868 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
869 else
870 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user chose invalid option" >> $logfolder/advancedplexapi.log 2>&1
871 fi
872 done
873 fi
874
875 elif [[ ${option,,} = search ]]
876 then
877 d=0
878 while [ $d = 0 ]
879 do
880 read -rp "cancel | Choose filename or path: " searchoption
881 if [[ ${searchoption,,} = cancel ]]
882 then
883 d=1
884
885 elif [[ ${searchoption,,} = filename ]]
886 then
887 h=0
888 while [ $h = 0 ]
889 do
890 read -rp "cancel | Give filename \(without extension\): " searchoptionfile
891 if [[ ${searchoptionfile,,} = cancel ]]
892 then
893 h=1
894 d=1
895 else
896 if [[ -n $(GET "http://$ipsonarrserver:$sonarrport/api/parse?apikey=$sonarrapitoken&title=$searchoptionfile" | python3 -m json.tool) ]] 2>/dev/null
897 then
898 GET "http://$ipsonarrserver:$sonarrport/api/parse?apikey=$sonarrapitoken&title=$searchoptionfile" | python3 -m json.tool
899 i=0
900 while [ $i = 0 ]
901 do
902 read -rp "exit | back: " searchoptionfileoption
903 if [[ ${searchoptionfileoption,,} = exit ]]
904 then
905 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user quitted the script" >> $logfolder/advancedplexapi.log 2>&1
906 i=1
907 h=1
908 d=1
909 b=1
910
911 elif [[ ${searchoptionfileoption,,} = back ]]
912 then
913 h=1
914 i=1
915 d=1
916 newlocation=sonarrroot
917 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
918 else
919 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user chose invalid option" >> $logfolder/advancedplexapi.log 2>&1
920 fi
921 done
922 fi
923 fi
924 done
925
926 elif [[ ${searchoption,,} = path ]]
927 then
928 f=0
929 while [ $f = 0 ]
930 do
931 read -rp "cancel | Give path to file: " searchoptionpath
932 if [[ ${searchoptionpath,,} = cancel ]]
933 then
934 f=1
935 d=1
936 else
937 if [[ -n $(GET "http://$ipsonarrserver:$sonarrport/api/parse?apikey=$sonarrapitoken&path=$searchoptionpath" | python3 -m json.tool) ]] 2>/dev/null
938 then
939 GET "http://$ipsonarrserver:$sonarrport/api/parse?apikey=$sonarrapitoken&path=$searchoptionpath" | python3 -m json.tool
940 g=0
941 while [ $g = 0 ]
942 do
943 read -rp "exit | back: " searchoptionpathoption
944 if [[ ${searchoptionpathoption,,} = exit ]]
945 then
946 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user quitted the script" >> $logfolder/advancedplexapi.log 2>&1
947 g=1
948 f=1
949 d=1
950 b=1
951
952 elif [[ ${searchoptionpathoption,,} = back ]]
953 then
954 g=1
955 f=1
956 d=1
957 newlocation=sonarrroot
958 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
959 else
960 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user chose invalid option" >> $logfolder/advancedplexapi.log 2>&1
961 fi
962 done
963 fi
964 fi
965 done
966 else
967 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user chose invalid option" >> $logfolder/advancedplexapi.log 2>&1
968 fi
969 done
970
971 elif [[ ${option,,} = series ]]
972 then
973 GET "http://$ipsonarrserver:$sonarrport/api/series?apikey=$sonarrapitoken" | python3 -m json.tool
974 c=0
975 while [ $c = 0 ]
976 do
977 read -rp "exit | back | list: " seriesoption
978 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | $seriesoption" >> $logfolder/advancedplexapi.log 2>&1
979 if [[ ${seriesoption,,} = exit ]]
980 then
981 c=1
982 b=1
983
984 elif [[ ${seriesoption,,} = back ]]
985 then
986 c=1
987 newlocation=sonarrroot
988 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
989
990 elif [[ ${seriesoption,,} = list ]]
991 then
992 echo "--------------------------------"
993 GET "http://$ipsonarrserver:$sonarrport/api/series?apikey=$sonarrapitoken" | grep -Pzo "\"title\": \".*\",.*\n.*\"alternateTitles\"" | grep -ao "title.*$" | grep -o ": .*" | grep -o \".*\" | sed "s|\"||g" | sort
994 echo "--------------------------------"
995 aa=0
996 while [ $aa = 0 ]
997 do
998 read -rp "cancel | Choose one of these series: " listselection
999 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | $listselection" >> $logfolder/advancedplexapi.log 2>&1
1000 if [[ ${listselection,,} = cancel ]]
1001 then
1002 aa=1
1003
1004 elif [[ -z $(GET "http://$ipsonarrserver:$sonarrport/api/series?apikey=$sonarrapitoken" | python3 -m json.tool | grep -o "$listselection") ]] 2>/dev/null
1005 then
1006 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | that option is not possible here" >> $logfolder/advancedplexapi.log
1007 continue
1008
1009 else
1010 seriesid=$(GET "http://$ipsonarrserver:$sonarrport/api/series?apikey=$sonarrapitoken" | python3 -m json.tool | grep -zPo -- "(?s)$listselection.*?\"id\": \K[0-9]{1,4}" | tr '\0' '\n')
1011 GET "http://$ipsonarrserver:$sonarrport/api/episodefile?apikey=$sonarrapitoken&seriesId=$seriesid" | python3 -m json.tool
1012 read -rp "exit | back: " listoption
1013 if [[ ${listoption,,} = exit ]]
1014 then
1015 aa=1
1016 c=1
1017 b=1
1018
1019 elif [[ ${listoption,,} = back ]]
1020 then
1021 aa=1
1022 c=1
1023 newlocation=/series
1024 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
1025 else
1026 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user chose invalid option" >> $logfolder/advancedplexapi.log 2>&1
1027 fi
1028 fi
1029 done
1030 else
1031 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user chose invalid option" >> $logfolder/advancedplexapi.log 2>&1
1032 fi
1033 done
1034
1035 elif [[ ${option,,} = date ]]
1036 then
1037 read -rp "cancel | Give beginning date (yyyy-mm-dd): " begindate
1038 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | $begindate" >> $logfolder/advancedplexapi.log 2>&1
1039 if [[ ${begindate,,} = cancel ]]
1040 then
1041 continue
1042 fi
1043 read -rp "cancel | Give end date (yyyy-mm-dd): " enddate
1044 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | $enddate" >> $logfolder/advancedplexapi.log 2>&1
1045 if [[ ${enddate,,} = cancel ]]
1046 then
1047 continue
1048 fi
1049
1050 clear
1051
1052 if [[ -z $begindate ]] && [[ -n $enddate ]]
1053 then
1054 GET "http://$ipsonarrserver:$sonarrport/api/calendar?apikey=$sonarrapitoken&end=$enddate" | python3 -m json.tool
1055 elif [[ -z $enddate ]] && [[ -n $begindate ]]
1056 then
1057 GET "http://$ipsonarrserver:$sonarrport/api/calendar?apikey=$sonarrapitoken&start=$begindate" | python3 -m json.tool
1058 elif [[ -n $enddate ]] && [[ -n $begindate ]]
1059 then
1060 GET "http://$ipsonarrserver:$sonarrport/api/calendar?apikey=$sonarrapitoken&start=$begindate&end=$enddate" | python3 -m json.tool
1061 elif [[ -z $enddate ]] && [[ -z $begindate ]]
1062 then
1063 GET "http://$ipsonarrserver:$sonarrport/api/calendar?apikey=$sonarrapitoken" | python3 -m json.tool
1064 fi
1065 read -rp "exit | back: " option
1066 fi
1067
1068 if [[ ${option,,} = back ]]
1069 then
1070 if [[ $path = /calendar || \
1071 $path = /diskspace || \
1072 $path = /history || \
1073 $path = /wanted/missing || \
1074 $path = /queue || \
1075 $path = /profile || \
1076 $path = /rootfolder || \
1077 $path = /system/status || \
1078 $path = /system/backup || \
1079 $path = /tag || \
1080 $path = /command ]]
1081 then
1082 newlocation=sonarrroot
1083 sed -i "s|^$path$|$newlocation|g" $filelocation/advancedplexapivar.txt
1084
1085 elif [[ $path = sonarrroot ]]
1086 then
1087 b=2
1088
1089 else
1090 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | you can't go back here" >> $logfolder/advancedplexapi.log
1091 fi
1092 fi
1093
1094 if [[ ${option,,} = exit ]]
1095 then
1096 b=1
1097 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user quitted the script" >> $logfolder/advancedplexapi.log 2>&1
1098 fi
1099done
1100
1101#Commenting the sed command below will have the following effect:
1102#Commented/inactive= When you exit the sonarr api and access it again later, you begin where you left off the previous time.
1103#Un-commented/working as a command= Everytime you use the sonarr api, you will begin at the start.
1104#You can change sonarrroot to something else.
1105#What you replace it with will be the place you start at when using the sonarr api (a valid sonarr api location e.g. /calendar). The starting point doesn't effect your options/actions in any way.
1106#To start at the home menu of the sonarr api (Home page Sonarr API), replace it with "sonarrroot"
1107#DEFAULT=un-commented, sonarrroot
1108sed -i "s|^$path$|sonarrroot|g" $filelocation/advancedplexapivar.txt 2>/dev/null
1109
1110if [ $b = 1 ]
1111then
1112a=1
1113fi
1114
1115#------------------------------------------------------------End of Sonarr Api-----------------------------------------
1116
1117elif [[ ${selection,,} = exit ]]
1118then
1119 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user quitted the script" >> $logfolder/advancedplexapi.log 2>&1
1120 a=1
1121else
1122 echo "$(date '+%d/%m/%Y %H:%M:%S') | info | user chose invalid option" >> $logfolder/advancedplexapi.log 2>&1
1123fi
1124done
1125
1126#commenting the clear command below will have the following effect:
1127#commented/inactive= after you exit the script, you can scroll back up to see the last output of the script before you left.
1128#un-commented/working as a command= when you exit the script, it clear's the terminal so you start with a empty screen.
1129#DEFAULT=un-commented
1130clear