Update plex_update.sh script for docker setup
This commit is contained in:
@@ -1,45 +1,44 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# PLEX PARTIAL SCAN script or PLEX UPDATE script
|
# PLEX PARTIAL SCAN script or PLEX UPDATE script (Docker)
|
||||||
# When zurg detects changes, it can trigger this script IF your config.yml contains
|
# When zurg detects changes, it can trigger this script IF your config.yml contains
|
||||||
# on_library_update: sh plex_update.sh "$@"
|
# on_library_update: sh plex_update.sh "$@"
|
||||||
|
|
||||||
# this uses python3
|
plexip=$(/sbin/ip route|awk '/default/ { print $3 }')
|
||||||
# docker compose exec zurg apk add python3
|
plex_url="http://$plexip:32400" # If you're using zurg inside a Docker container, by default it is 172.17.0.1:32400
|
||||||
# sudo apt install python3
|
echo "Detected Plex URL inside Docker container: $plex_url"
|
||||||
|
|
||||||
plex_url="http://plex:32400" # If you're using zurg inside a Docker container, by default it is 172.17.0.1:32400
|
|
||||||
token="yourplextoken" # open Plex in a browser, open dev console and copy-paste this: window.localStorage.getItem("myPlexAccessToken")
|
token="yourplextoken" # open Plex in a browser, open dev console and copy-paste this: window.localStorage.getItem("myPlexAccessToken")
|
||||||
zurg_mount="/mnt/zurg" # replace with your zurg mount path, ensure this is what Plex sees
|
zurg_mount="/mnt/zurg" # replace with your zurg mount path, ensure this is what Plex sees
|
||||||
|
|
||||||
# Get the list of section IDs
|
section_ids=$(curl -sLX GET "$plex_url/library/sections" -H "X-Plex-Token: $token" | xmllint --xpath "//Directory/@key" - | grep -o 'key="[^"]*"' | awk -F'"' '{print $2}')
|
||||||
section_ids=$(curl -sLX GET "$plex_url/library/sections" -H "X-Plex-Token: $token" | xmllint --xpath "//Directory/@key" - | sed 's/key="//g' | tr '"' '\n')
|
|
||||||
|
if [ -z "$section_ids" ]; then
|
||||||
|
echo "Error: missing sections; the token seems to be broken"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Plex section IDs: $section_ids"
|
||||||
|
sleep 1
|
||||||
|
|
||||||
for arg in "$@"
|
for arg in "$@"
|
||||||
do
|
do
|
||||||
modified_arg="$zurg_mount/$arg"
|
modified_arg="$zurg_mount/$arg"
|
||||||
echo "Detected update on: $arg"
|
echo "Updating in Plex: $modified_arg"
|
||||||
echo "Absolute path: $modified_arg"
|
|
||||||
|
|
||||||
encoded_arg=$(echo -n "$modified_arg" | python3 -c "import sys, urllib.parse as ul; print (ul.quote_plus(sys.stdin.read()))")
|
encoded_arg=$(echo -n "$modified_arg" | python3 -c "import sys, urllib.parse as ul; print (ul.quote_plus(sys.stdin.read()))")
|
||||||
|
|
||||||
if [ -z "$encoded_arg" ]; then
|
if [ -z "$encoded_arg" ]; then
|
||||||
echo "Error: Encoded argument is empty. Check the input or encoding process."
|
echo "Error: encoded argument is empty, check the input or encoding process"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for section_id in $section_ids
|
for section_id in $section_ids
|
||||||
do
|
do
|
||||||
final_url="${plex_url}/library/sections/${section_id}/refresh?path=${encoded_arg}&X-Plex-Token=${token}"
|
final_url="${plex_url}/library/sections/${section_id}/refresh?path=${encoded_arg}&X-Plex-Token=${token}"
|
||||||
|
|
||||||
echo "Encoded argument: $encoded_arg"
|
|
||||||
echo "Section ID: $section_id"
|
|
||||||
echo "Final URL: $final_url"
|
|
||||||
|
|
||||||
curl -s "$final_url"
|
curl -s "$final_url"
|
||||||
|
echo "Triggered scan with URL: $final_url"
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "All updated sections refreshed"
|
echo "All updated sections refreshed!"
|
||||||
|
|
||||||
# credits to godver3
|
# credits to godver3
|
||||||
|
|||||||
Reference in New Issue
Block a user