[PP-Script] NotifyPlex - Library Update and GUI Notification

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.
mannibis
Posts: 60
Joined: 29 Jul 2014, 15:10

[PP-Script] NotifyPlex - Library Update and GUI Notification

Post by mannibis » 17 Aug 2014, 20:37

The PP-Script will call a targeted Plex refresh/update upon successful download and send a GUI Notification to Plex Home Theater.
If snatched via a NewzNab+ indexer, the script can use Direct NZB headers to display the ProperName and EpisodeName in the notification. This is now a new option called "dHeaders". If dHeaders is set to "No" or the indexer does not support DNZB Headers, the full NZB name will be used in the notification.

Library Refresh Mode has now been implemented

Users no longer have to enter in section numbers or copy the script to refresh their TV shows and Movies separately. Library Refresh Mode is a new option that allows the user to choose how they want to script to refresh their library. 'Auto' mode will automatically refresh TV Shows and Movies sections. The script will detect the NZBGet category and also auto-detect the Plex sections by polling the Plex Server's API to figure out what sections are for TV Shows and what sections are for Movies. The plexSections setting has been changed to customPlexSections, if the user would like to scan a section other than TV Shows or Movies. The Custom sections will only be scanned if the Library Refresh Mode is set to Custom or Both.

New settings are movieCat and tvCat. You will have to specify which NZBGet category(s) that you created are intended for movies, and which ones are intended for TV Shows

Sending a GUI Notification to Plex Home Theater client is supported by specifying the IP(s) where PHT is installed. Sending GUI Notifications to multiple clients is now supported.

The script has also been updated to support Plex Home. It will now authenticate with Plex.tv first using HTTP Basic Auth, which is now required for all API commands/methods if Plex Home is enabled. Note that you will need to add your username and password to the NotifyPlex settings (required).

Any feedback or feature requests are welcome.

Requirements: NZBGet v13+ and Python 3.x with requests module

Installation Instructions
  • Download NotifyPlex.zip (or git clone) and extract entire NotifyPlex folder into your NZBGet Scripts Directory
  • If using VideoSort or other Sort/Rename Scripts, run NotifyPlex after those scripts have sorted/renamed your files.
  • Configure Options in WebUI, Save Changes, Reload NZBGet
  • Any duplicate scripts (from previous versions) can be deleted. Only one NotifyPlex.py is needed for Movie/TV show/Custom section(s)
  • If requests module is missing, do "pip install requests" from your command line to install
  • If linux permissions issues arise, do "chmod +x NotifyPlex.py from your command line

Revision 1: Formatting Changes

Revision 2: Added ability to refresh multiple Plex sections at once. Separate multiple sections with a comma (etc. plexSection=1,2)

Revision 3: Added GUI Notification for Plex Home Theater upon successful download. URL requests are now handled by "requests" library which is included in the zip.

Revision 4: Added Authentication with Plex.tv to allow for library refreshing. This was introduced with Plex Media Server version 0.9.11.4 which includes the Plex Home feature. Also added Silent Failure mode, in case you want NZBGet to report SUCCESS if contacting/authenticating with the Plex server fails. There will still be a warning message in the logs.

Revision 5: Added Auto Mode, which will automatically detect the NZBGet category and Plex sections. Added option to Disable Refresh (for users who only want GUI notification). Added ability to send GUI notifications to multiple clients. Changed plexSections to customPlexSections for Custom mode.

Revision 6: Fixed DNZB Header for Movie Year. GUI notification now displays year of movie, i.e. "The Guest (2014)"

Revision 7: Fixed XML Parsing for Plex Sections. Script now properly detects Movie and TV sections by "type" instead of "title"

Revision 8: Did a code overhaul and changed from urllib2 to requests module. Reworked XML parsing to be faster and more efficient and also made some minor code formatting changes. Configuration options/variables have not changed. Simply replace old NotifyPlex.py with new .py and that is all.

Revision 9: The script is now python3 compatible. I also added the ability for the script to save (via pickle) the authorization token to disk inside the NotifyPlex folder. plex.tv sign-in should only be required once. Subsequent library updates will re-use the authorization tokens. There are a few minor cosmetic changes.

Github: https://github.com/mannibis/NotifyPlex
Last edited by mannibis on 20 Aug 2020, 12:22, edited 55 times in total.

hugbug
Developer & Admin
Posts: 7645
Joined: 09 Sep 2008, 11:58
Location: Germany

Re: [PP-Script] NotifyPlex

Post by hugbug » 19 Aug 2014, 13:54

I don't use Plex but since you've asked here is my feedback based purely on the script code and is not related to how well the script works :)
  • I would replace (1, 0) with (yes, no)

    Code: Select all

    # Auto Update Plex Library (yes, no).
    #
    # Activate if you want NotifyPlex to Automatically Update/Refresh your Plex Library
    #PlexUpdate=no
    Then where it is checked:

    Code: Select all

    	if plexUpdate=="yes":
  • Actually it looks like the script doesn't do anything if the option "PlexUpdate" is disabled. If that's true the option is superfluous because the user can just disable the script completely.
  • The description of the options must follow certain (not documented) format:

    Code: Select all

    # Plex Section you would like to Update (1 for Movies, 2 for TV, etc.)
    #plexSection=1
    • The first line of option description must end with dot. This is how NZBGet distinguish the short description from the rest. In this example there is no long description, so it's not a problem;
    • The text in braces in the first line is interpreted in a special way - it lists possible option values to choose from a combobox element. Since this is not what you wanted here, you should move that text to the long option description. The combobox wasn't shown here because you forget the dot at the end, one bug has compensated for another. :)
    • That's how it should be:

      Code: Select all

      # Plex Section you would like to Update.
      #
      #  Section numbers: 1 for Movies, 2 for TV, etc.
      #plexSection=1
  • You recommend to make a copy of the script if more than one section have to be updated. Instead you could allow for multiple sections be entered in the option plexSection (renamed to PlexSections):

    Code: Select all

    # Plex Sections you would like to Update.
    #  1 for Movies, 2 for TV, etc.
    # Multiple sections can be separated with commas.
    #PlexSections=1
    

    Code: Select all

    # This code is not tested:
    plex_sections=os.environ['NZBPO_PLEXSECTIONS'].split(',')
    for plexSection in plex_sections:
    	if plexUpdate=="1":
    		url = 'http://%s/library/sections/%s/refresh' % (plexIP, plexSection)
    
  • Small thing - there is a #-character at the line end in the description. The character is also visible in web-interface and needs to be deleted.

    Code: Select all

    # Post-Process to Update Plex Library Based on Section #
  • Also add missing trailing dots in the script description. The description (About NotifyPlex) will look better in web-interface (it detects paragraphs better).

    Code: Select all

    # Post-Process to Update Plex Library Based on Section.
    #
    # This script sends a Targeted Library Update URL to your Plex Media Server.
    #
    # NOTE: This script requires Python to be installed on your system.

mannibis
Posts: 60
Joined: 29 Jul 2014, 15:10

Re: [PP-Script] NotifyPlex

Post by mannibis » 19 Aug 2014, 14:02

Thanks for your feedback, will revise the script.

As for the copying of the script, this was to be able to set the PP-Script to certain categories. For someone with a Movies category, they would only want the Movies section to be updated, and the same for TV. This is the only way I can think of right now that would be able to do a refresh for different sections based on the category they are using the script with.

EDIT: Updated Attachment in main post to reflect formatting changes

mannibis
Posts: 60
Joined: 29 Jul 2014, 15:10

Re: [PP-Script] NotifyPlex

Post by mannibis » 22 Aug 2014, 00:40

Added ability to scan multiple Plex sections at once by separating section numbers with a comma.
Main post and script has been revised and updated.

mannibis
Posts: 60
Joined: 29 Jul 2014, 15:10

Re: [PP-Script] NotifyPlex - Library Update and GUI Notifica

Post by mannibis » 07 Sep 2014, 04:33

Added GUI Notification for Plex Home Theater

Main Post is updated with new code and URL for download.
The script now uses the requests library.

mannibis
Posts: 60
Joined: 29 Jul 2014, 15:10

Re: [PP-Script] NotifyPlex - Library Update and GUI Notifica

Post by mannibis » 22 Nov 2014, 23:00

The script has been updated to supported Plex Media Server 0.9.11.4, which at the time of writing this post is a Plex-Pass Only release. I noticed that the API call to refresh libraries wasn't working anymore and learned that you need to now authenticate with Plex.tv and get an authentication token before you can perform any API commands/methods. This should not affect users with older versions of Plex, as it only adds an authentication request, but note you will need to add your username and password to the NotifyPlex settings. You will also notice that NotifyPlex is now visible in the Devices section of Plex/Web ;)

I also added (at a user's request) Silent Failure mode, in case you want NZBGet to report SUCCESS if contacting/authenticating with the Plex server fails. There will still be a warning message in the logs. It is an option in the NotifyPlex settings called "silentFailure" and is off by default.

Main post is updated and the same link will bring you to the new updated version.

binreader
Posts: 20
Joined: 07 Oct 2014, 03:00

Re: [PP-Script] NotifyPlex - Library Update and GUI Notifica

Post by binreader » 23 Nov 2014, 02:55

thanks for the updates you workin hard!

mannibis
Posts: 60
Joined: 29 Jul 2014, 15:10

Re: [PP-Script] NotifyPlex - Library Update and GUI Notifica

Post by mannibis » 29 Nov 2014, 23:15

Big changes in this Update...

Library Refresh Mode has now been implemented

Users no longer have to enter in section numbers or copy the script to refresh their TV shows and Movies separately. Library Refresh Mode is a new option that allows the user to choose how they want to script to refresh their library. 'Auto' mode will automatically refresh TV Shows and Movies sections. The script has been completely re-designed to auto-detect the NZBGet category and also auto-detect the Plex sections by polling the Plex Server's API to figure out what sections are for TV Shows and what sections are for Movies. The plexSections setting has been changed to customPlexSections, if the user would like to scan a section other than TV Shows or Movies. The Custom sections will only be scanned if the Library Refresh Mode is set to Custom or Both.

Added option to Disable Refresh (for users who only want GUI notifications).

Added ability to send GUI notifications to multiple clients.

rubylaser
Posts: 34
Joined: 06 Feb 2014, 14:47

Re: [PP-Script] NotifyPlex - Library Update and GUI Notifica

Post by rubylaser » 12 Dec 2014, 01:05

I can't get this to work. Attached is an image showing my settings. Plexmediaserver is running on the same machine as NZBGet. Everytime the postprocessing runs, I get an error of NotifyPlex: Failure. Any ideas to get this working? I'm running plexmediaserver 0.9.11.5 with Plex Home enabled.
Attachments
notify-plex-settings.png

mannibis
Posts: 60
Joined: 29 Jul 2014, 15:10

Re: [PP-Script] NotifyPlex - Library Update and GUI Notifica

Post by mannibis » 12 Dec 2014, 01:16

Are there any logs in the messages tab you can post? I need to see what type of error you are getting. Does it say that Plex.tv authentication is successful? Check the messages tab when you run it again (Actions -> Post Process Again) and paste the output if you can.

Also, double check the names of your movies category. Usually people have one category for movies in their NZBGet settings. Is "Movies > HD" the name of a category in Settings > Categories?

Post Reply

Who is online

Users browsing this forum: No registered users and 31 guests