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