From 827ab8bc552fe5a2074d6216a11723492a02ee45 Mon Sep 17 00:00:00 2001 From: Ben Sarmiento Date: Fri, 12 Jan 2024 19:41:34 +0100 Subject: [PATCH] Additional files --- nginx/plex.conf | 14 ++++++++++++++ plex_update.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 nginx/plex.conf create mode 100755 plex_update.sh diff --git a/nginx/plex.conf b/nginx/plex.conf new file mode 100644 index 0000000..3236b6c --- /dev/null +++ b/nginx/plex.conf @@ -0,0 +1,14 @@ +server { + listen 80; + listen [::]:80; + + server_name plex.hostname.tld; + + location / { + proxy_pass http://plex:32400; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} diff --git a/plex_update.sh b/plex_update.sh new file mode 100755 index 0000000..cf76f7d --- /dev/null +++ b/plex_update.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# PLEX PARTIAL SCAN script or PLEX UPDATE script +# When zurg detects changes, it can trigger this script IF your config.yml contains +# on_library_update: sh plex_update.sh "$@" + +# this uses python3 +# docker compose exec zurg apk add python3 +# sudo apt install python3 + +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") +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" - | sed 's/key="//g' | tr '"' '\n') + +for arg in "$@" +do + modified_arg="$zurg_mount/$arg" + echo "Detected update on: $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()))") + + if [ -z "$encoded_arg" ]; then + echo "Error: Encoded argument is empty. Check the input or encoding process." + continue + fi + + for section_id in $section_ids + do + 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" + done +done + +echo "All updated sections refreshed" + +# credits to godver3