Best script to use to update Plex library?

Share your scripts or request scripts with specific features.
Forum rules
Please keep the forum clean - one topic per script. Questions not related to a specific script should be posted in Support forum.
Post Reply
davidmac27
Posts: 24
Joined: 14 Nov 2015, 23:27

Best script to use to update Plex library?

Post by davidmac27 » 25 Feb 2017, 18:21

Hi everyone,

Would appreciate some guidance on the best script to use for updating a Plex library after NZBGet downloads a TV Show or Movie. I have been playing with NotifyPlex but it doesn't seem to work with PMS 1.4.2

The 15 minute Plex library update interval drives me insane! ;)

Thanks!

johnnykorn
Posts: 2
Joined: 04 Jun 2017, 15:55

Re: Best script to use to update Plex library?

Post by johnnykorn » 04 Jun 2017, 16:12

Of course you'll need to acquire your token from plex for each section (movies, TV shows, etc). And you'll need curl installed. change the section number below (3) with the section number for you section. I looked at notifyplex and was more than I needed. So I use this and works.

To find your token:
Sign into your Plex Account in Plex Web App
Browse to a library item and view the XML for it
Look in the URL and find the token as the X-Plex-Token value

To find your section, just hover over it in Plex and you'll see it in the link. For me, Movies shows as =library/sections/3

In Nzbget just make sure its listed in the extensions for that category.

updateplexmovies.sh

Code: Select all

#!/bin/sh 


curl http://localhost:32400/library/sections/3/refresh?X-Plex-Token=X-Plex-Token

POSTPROCESS_SUCCESS=93
POSTPROCESS_ERROR=94
exit $POSTPROCESS_SUCCESS

johnnykorn
Posts: 2
Joined: 04 Jun 2017, 15:55

Re: Best script to use to update Plex library?

Post by johnnykorn » 05 Jun 2017, 18:26

I've modified svenglars' kodi script to fit my needs. All credits to him for the work. Place it in your scripts directory then modify your values in Nzbget. Super simple script that updates Plex. Create duplicates for additional sections. I have no idea how to writes scripts but it works.

PlexMovies.sh

Code: Select all

#!/bin/bash
##############################################################################
### NZBGET POST-PROCESSING SCRIPT                                          ###

# PP-Script Version: 1.0.0.
#
# NOTE: This script only runs on *nix based hosts with BASH.
#       It also requires that curl is installed and is in the $PATH.

##############################################################################
### OPTIONS                                                                ###

# The hostname or IP address of the host running Plex.
#
# This can be a remote host or a local host. e.g. 192.168.1.50 or localhost
#host=localhost

# To find your token:
#
# Sign into your Plex Account in Plex Web App,
# Browse to a library item and view the XML for it,
# Look in the URL and find the token as the X-Plex-Token value
#XPlexToken=X-Plex-Token

# The section that Plex needs to update.
#
# To find your section, just hover over it in Plex and you'll see it in the link. For example "=library/sections/3"
#Section=Section


### NZBGET POST-PROCESSING SCRIPT                                          ###
##############################################################################

SUCCESS=93
ERROR=94
SKIP=95

# Check that the required options have been set before continuing
[[ -n $NZBPO_HOST ]] || { echo "[ERROR] Host not set"; exit $ERROR; }
[[ -n $NZBPO_XPLEXTOKEN ]] || { echo "[ERROR] X-Plex-Token not set"; exit $ERROR; }
[[ -n $NZBPO_SECTION ]] || { echo "[ERROR] Section not set"; exit $ERROR; }

plex_is_local () {
  if [[ $NZBPO_HOST == 'localhost'  || $NZBPO_HOST == '127.0.0.1' ]]; then
    return 0
  else
    return 1
  fi
}

plex_is_running_locally () {
  if pgrep Plex* 1>/dev/null 2>&1; then
    return 0
  elif ps ax | grep [p]lex* 1>/dev/null 2>&1; then
    return 0
  else
    return 1
  fi
}

if ! which curl 1>/dev/null 2>&1; then
  echo '[ERROR] Can not find curl. update_plex requires curl to be installed and in $PATH.'
  exit $ERROR
fi

curl  --connect-timeout 5 \
  http://${NZBPO_HOST}:32400/library/sections/${NZBPO_SECTION}/refresh?X-Plex-Token=${NZBPO_XPLEXTOKEN} 1>/dev/null 2>&1

curl_return_value="$?"

case $curl_return_value in
  0)
    exit $SUCCESS ;;
  6)
    echo "[ERROR] Couldn't resolve host: ${NZBPO_HOST}"
    exit $ERROR ;;
  6)
    echo "[ERROR] Couldn't resolve X-Plex-Token: ${NZBPO_XPLEXTOKEN}"
    exit $ERROR ;;
  7)
    echo "[ERROR] Could not connect to the Plex API endpoint at ${NZBPO_XPLEXTOKEN}:${NZBPO_SECTION}."
    echo "[ERROR] Is Plex running and is 'Allow remote control via HTTP' enabled?"
    exit $ERROR ;;
  *)
    echo "[ERROR] Unknown error occured. Curl returned: ${curl_return_value}"
    exit $ERROR ;;
esac

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest