diff --git a/README.md b/README.md index bd74bdc..fb58a42 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,7 @@ # plex-tools +Credits: + +ChuckPa: for the database management utility, as well as a function for easily getting host information +jlim0930: for token reading from Preferences.xml and some logic for cleaning up libraries and refreshing metadata +Werner Beroux: For getting token from api diff --git a/plex-do b/plex-do deleted file mode 100644 index 485226c..0000000 --- a/plex-do +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/sh - -# automatic maintenance of PLEX -# will, optimize the database, Update the library, and empty the trash -# all the commands will work via curl over localhost -# please make sure that jq is installed - -# check to see if I'm root -# you can run this script as non root use as long as its ran as the same user that plex runs so that its able to read the Preferences.xml file -#if ! [ $(id -u) = 0 ]; then -# echo "Please run as root user" -# exit 1 -#fi - -# configs -PREF="/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Preferences.xml" - -# get token -TOKEN=`cat "${PREF}" | sed -e 's;^.* PlexOnlineToken=";;' | sed -e 's;".*$;;' | tail -1` - -# print token for troubleshooting -# uncomment to put your token in the logs if you want to know what it is. -logger "[DEBUG PLEX] TOKEN: $TOKEN" -echo "[DEBUG PLEX] TOKEN: $TOKEN" - -# optimize database -logger "[DEBUG PLEX] optimizing library" -echo "[DEBUG PLEX] optimizing library" -## curl -X PUT -H "X-Plex-Token: ${TOKEN}" http://127.0.0.1:32400/library/optimize\?async=1&X-Plex-Token=${TOKEN} -curl -X PUT http://127.0.0.1:32400/library/optimize\?async=1\&X-Plex-Token=${TOKEN} - -# adding 120 sec sleep for things to settle -sleep 120 - -# run a loop against each library -for i in `curl -s -H "Accept: application/json" -H "X-Plex-Token: ${TOKEN}" http://127.0.0.1:32400/library/sections | jq -M -r '.MediaContainer.Directory[] | "\(.key)"'` -do - logger "[DEBUG PLEX] Running Update for key: ${i}" - echo "[DEBUG PLEX] Running Update for key: ${i}" -# OLD way -# curl -X PUT -H "X-Plex-Token: ${TOKEN}" http://127.0.0.1:32400/library/sections/${i}/refresh\?force=1&X-Plex-Token=${TOKEN} -# NEW way - curl -X PUT http://127.0.0.1:32400/library/sections/${i}/refresh\?force=1\&X-Plex-Token=${TOKEN} - # adding 30 sec sleep - sleep 30 -# curl -X PUT -H "X-Plex-Token: ${TOKEN}" http://127.0.0.1:32400/library/sections/${i}/emptyTrash?X-Plex-Token=${TOKEN} - logger "[DEBUG PLEX] Emptying Trash for key: ${i}" - echo "[DEBUG PLEX] Emptying Trash for key: ${i}" - curl -X PUT http://127.0.0.1:32400/library/sections/${i}/emptyTrash\?X-Plex-Token=${TOKEN} -done - -# clean PhotoTranscoder Cache -logger "[DEBUG PLEX] Deleting PhotoTranscoder Cache" -echo "[DEBUG PLEX] Deleting PhotoTranscoder Cache" -CACHEPATH="/opt/plex/Library/Application Support/Plex Media Server/Cache/PhotoTranscoder" -find "${CACHEPATH}" -type f -delete diff --git a/plex-freshen b/plex-freshen new file mode 100644 index 0000000..62386b4 --- /dev/null +++ b/plex-freshen @@ -0,0 +1,29 @@ +#!/bin/sh + +# get plex token +source ./plex-token.sh + +# run a loop against each library +for medialibrary in `curl -s -H "Accept: application/json" -H "X-Plex-Token: ${TOKEN}" http://127.0.0.1:32400/library/sections` +do + + library_number=$(medialibrary | jq -M -r '.MediaContainer.Directory[] | "\(.key)"') + library_name=$(medialibrary | jq -M -r '.MediaContainer.Directory[] | "\(.title)"') + echo "$library_name" + echo "$library_number" + + #echo "[DEBUG PLEX] Running Library Update for key: ${library_number}" + #curl -X PUT http://127.0.0.1:32400/library/sections/${library_number}/refresh\?force=1\&X-Plex-Token=${TOKEN} + + # adding 30 sec sleep + #sleep 30 + + #echo "[DEBUG PLEX] Emptying Trash for key: ${library_number}" + #curl -X PUT http://127.0.0.1:32400/library/sections/${library_number}/emptyTrash\?X-Plex-Token=${TOKEN} + +done + +# clean PhotoTranscoder Cache +#echo "[DEBUG PLEX] Deleting PhotoTranscoder Cache" +#CACHEPATH="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder" +#find "${CACHEPATH}" -type f -delete diff --git a/plex-tools.sh b/plex-tools.sh index e661699..f9c105f 100644 --- a/plex-tools.sh +++ b/plex-tools.sh @@ -4,7 +4,11 @@ echo "Welcome to plex-tools wrapper utility!" case "$1" in token) source ./plex-token.sh;; + freshen) source ./plex-freshen.sh;; dbrepair) source ./DBRepair.sh stop auto start exit;; + start) source ./DBRepair.sh start exit;; + stop) source ./DBRepair.sh stop exit;; + restart) source ./DBRepair.sh stop start exit;; "") echo "No plex-tools command given";; *) echo "'$1' is not a valid plex-tools command";; esac