Skip to content

Instantly share code, notes, and snippets.

Created December 7, 2019 16:01
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
WIP script to intelligently upate my Plex library after sabnzbd downloads are done
# sabnzbd post-download notification script for Plex
# Define $PLEX_TOKEN in your environment
# Debug arguments to sab
echo "Args:"
for word in "$@"; do
echo "$word"
# Debug our library mapping... this is also available via Plex API at
# curl -s http://localhost:32400/library/sections/?X-Plex-Token=$PLEX_TOKEN
echo "Listing all libraries:"
export LD_LIBRARY_PATH=/usr/lib/plexmediaserver
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR='/var/lib/plexmediaserver/Library/Application Support'
/usr/lib/plexmediaserver/Plex\ Media\ Scanner --list
# echo "Updating using directory... 1=$1"
# This just totally hangs the process
# /usr/lib/plexmediaserver/Plex\ Media\ Scanner --scan --directory "$1"
# This returns, but doesn't seem to actually work
# /usr/lib/plexmediaserver/Plex\ Media\ Scanner --scan --directory "$1" --section 1
# Scanning whole library works :(
# /usr/lib/plexmediaserver/Plex\ Media\ Scanner --scan --section 1
# Using Plex API directly seems to behave better
echo "Mass-updating libraries..."
for id in 8 12 1 2; do
echo -n $id...
curl -s "http://localhost:32400/library/sections/$id/refresh?X-Plex-Token=$PLEX_TOKEN"
echo "Done."
Copy link

Thanks, API version works great

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment