Skip to content

Instantly share code, notes, and snippets.

@jamiew
Created December 7, 2019 16:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamiew/bfb239673c4e62a437f40b5831f59e30 to your computer and use it in GitHub Desktop.
Save jamiew/bfb239673c4e62a437f40b5831f59e30 to your computer and use it in GitHub Desktop.
WIP script to intelligently upate my Plex library after sabnzbd downloads are done
#!/bin/bash
# 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"
done
# 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"
done
echo "Done."
@ivan-leschinsky
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