From c05ca8d24cad736ec6c20c514f71b05036036ebb Mon Sep 17 00:00:00 2001 From: Denis <146707790+dnzbk@users.noreply.github.com> Date: Fri, 15 Mar 2024 12:47:04 +0300 Subject: [PATCH] Feature: manifest.json (#2) ## Description - migration from a file header config definition to a manifest.json-based configuration; - works with NZBGet v23 and above; - no longer works with NZBGet v22 and below; ## Testing By @dnzbk - NZBGet v23.1/Windows11; - Plex Media Server 1.40.0.7998/Windows 11; --- .github/workflows/release.yml | 3 +- .github/workflows/tests.yml | 5 +- NotifyPlex.py => main.py | 96 ++------------------- manifest.json | 153 ++++++++++++++++++++++++++++++++++ tests.py | 10 ++- 5 files changed, 173 insertions(+), 94 deletions(-) rename NotifyPlex.py => main.py (67%) mode change 100755 => 100644 create mode 100644 manifest.json diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a4a487c..50a01d0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,5 +9,6 @@ jobs: release: uses: nzbgetcom/nzbget-extensions/.github/workflows/extension-release.yml@main with: - release-file-list: NotifyPlex.py + release-file-list: main.py manifest.json release-file-name: notifyplex + release-dir: NotifyPlex diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4669ee0..67e7794 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -4,7 +4,10 @@ on: push: branches: - feature/* - - main + - master + pull_request: + branches: + - master jobs: tests: diff --git a/NotifyPlex.py b/main.py old mode 100755 new mode 100644 similarity index 67% rename from NotifyPlex.py rename to main.py index 8cd3ba2..77dc8c9 --- a/NotifyPlex.py +++ b/main.py @@ -1,83 +1,3 @@ -#!/usr/bin/env python -# -############################################################################## -### NZBGET POST-PROCESSING SCRIPT ### - -# Post-Processing Script to Update Plex Library and Notify PHT. -# -# This script triggers a targeted library update to your Plex Media Server and sends a GUI Notification to Plex Home Theater. -# Auto-Detection of NZBGet category and Plex sections is now supported. This script also works with Plex Home enabled. -# -# Copyright (C) 2019 mannibis -# Version 3.0.0 -# -# -# NOTE: This script is compatible to Python 3.8 and above. -# NOTE: If using VideoSort or other Sort/Rename Scripts, run NotifyPlex after those scripts have sorted/renamed your files. - -############################################################################## -### OPTIONS ### - -## General - -# Use Silent Failure Mode (yes, no). -# -# Activate if you want NZBGet to report a SUCCESS status regardless of errors, in cases where PMS is offline. -#silentFailure=no - -## Plex Media Server - -# Refresh Plex Library (yes, no). -# -# Activate if you want NotifyPlex to refresh your Plex library -#refreshLibrary=no - -# Plex.tv Username [Required to generate Plex Auth-Token] -#PlexUser= - -# Plex.tv Password [Required to generate Plex Auth-Token] -#PlexPassword= - -# Authorize script with Plex server [Required if refreshLibrary is enabled]. -# -# Once authorized, it will be visible in your Plex server settings as "NotifyPlex" -# in the "Authorized Devices" section. -#PlexAuthorize@Generate Plex Auth-Token - -# Auth-Token for this script. -# -# Use the above button to authorize this script with Plex.tv -# NOTE: The Password can be safely removing when setting the Auth-Token. -#PlexAuthToken= - -# Plex Media Server Host. -# -# IP or hostname of your Plex Media Server including port (only 1 server is supported) -#PlexHost=192.168.1.XXX:32400 - -# Library Refresh Mode (Auto, Custom, Both). -# -# Select Refresh Mode: Auto will automatically detect your NZBGet category and refresh the appropriate sections, Custom will only refresh the sections you input into the Custom sections setting below, Both will auto-detect and refresh the Custom Sections -#refreshMode=Auto - -# NZBGet Movies Category/Categories [Required for Auto Mode]. -# -# List the name(s) of your NZBGet categories (CategoryX.Name) that correspond to Movies (comma separated) -#moviesCat=Movies - -# NZBGet TV Category/Categories [Required for Auto Mode]. -# -# List the name(s) of your NZBGet categories (CategoryX.Name) that correspond to TV Shows (comma separated) -#tvCat=TV - -# Custom Plex Section(s) you would like to update [Optional]. -# -# Section Number(s) corresponding to your Plex library (comma separated). These sections will only refreshed if Library Refesh Mode is set to Custom or Both -#customPlexSection= - -### NZBGET POST-PROCESSING SCRIPT ### -############################################################################## - import os import sys import urllib.parse @@ -192,8 +112,8 @@ def refresh_sections(plex_sections, auth_token): print('[WARNING] NOTIFYPLEX: Failed updating section %s. Silent failure mode active' % section_id) sys.exit(POSTPROCESS_SUCCESS) else: - print('[ERROR] NOTIFYPLEX: Failed updating section %s. ' + - 'Check Network Connection, Plex server settings, Auth-Token and section numbers.' % section_id) + print('[ERROR] NOTIFYPLEX: Failed updating section %s. Check Network Connection, Plex server settings, Auth-Token and section numbers.' + % section_id) print('[ERROR] NOTIFYPLEX: %s' % e.reason) sys.exit(POSTPROCESS_ERROR) @@ -205,8 +125,8 @@ def refresh_sections(plex_sections, auth_token): required_options = ('NZBPO_SILENTFAILURE', 'NZBPO_REFRESHLIBRARY') for optname in required_options: if optname not in os.environ: - print('[ERROR] NOTIFYPLEX: Option %s is missing in configuration file. ' + - 'Please check script settings' % optname[6:]) + print('[ERROR] NOTIFYPLEX: Option %s is missing in configuration file. Please check script settings' + % optname[6:]) sys.exit(POSTPROCESS_ERROR) @@ -224,8 +144,8 @@ def refresh_sections(plex_sections, auth_token): required_options = ('NZBPO_PLEXUSER', 'NZBPO_PLEXPASSWORD') for optname in required_options: if optname not in os.environ: - print('[ERROR] NOTIFYPLEX: Option %s is missing in configuration file. ' + - 'Please check script settings' % optname[6:]) + print('[ERROR] NOTIFYPLEX: Option %s is missing in configuration file. Please check script settings' + % optname[6:]) sys.exit(POSTPROCESS_ERROR) plex_username = os.environ['NZBPO_PLEXUSER'] @@ -244,8 +164,8 @@ def refresh_sections(plex_sections, auth_token): required_options = ('NZBPO_MOVIESCAT', 'NZBPO_PLEXAUTHTOKEN', 'NZBPO_PLEXHOST', 'NZBPO_REFRESHMODE', 'NZBPO_TVCAT') for optname in required_options: if os.environ.get(optname) in (None, ''): - print('[ERROR] NOTIFYPLEX: Option "%s" is missing or empty in configuration file. ' + - 'Please check script settings' % optname[6:]) + print('[ERROR] NOTIFYPLEX: Option "%s" is missing or empty in configuration file. Please check script settings' + % optname[6:]) sys.exit(POSTPROCESS_ERROR) raw_custom_section_ids = os.environ['NZBPO_CUSTOMPLEXSECTION'] diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..dde2616 --- /dev/null +++ b/manifest.json @@ -0,0 +1,153 @@ +{ + "main": "main.py", + "name": "NotifyPlex", + "homepage": "https://github.com/nzbgetcom/Extension-NotifyPlex/", + "kind": "POST-PROCESSING", + "displayName": "Notify Plex", + "version": "4.0", + "author": "mannibis", + "license": "GNU", + "about": "Post-Processing extension to Update Plex Library.", + "queueEvents": "", + "description": [ + "This script triggers a targeted library update to your Plex Media Server" + ], + "requirements": [ + "This script is compatible to Python 3.8 and above.", + "If using VideoSort or other Sort/Rename Scripts, run NotifyPlex after those scripts have sorted/renamed your files." + ], + "options": [ + { + "name": "silentFailure", + "displayName": "Silent Failure", + "value": "no", + "description": [ + "Use Silent Failure Mode.", + "", + "Activate if you want NZBGet to report a SUCCESS status regardless of errors, in cases where PMS is offline." + ], + "select": ["yes", "no"] + }, + { + "name": "refreshLibrary", + "displayName": "Refresh Library", + "value": "no", + "description": [ + "Refresh Plex Library.", + "", + "Activate if you want NotifyPlex to refresh your Plex library." + ], + "select": ["yes", "no"] + }, + { + "name": "PlexUser", + "displayName": "Plex User", + "value": "", + "description": [ + "Plex.tv Username.", + "NOTE: Required to generate Plex Auth-Token" + ], + "select": [] + }, + { + "name": "PlexPassword", + "displayName": "Plex Password", + "value": "", + "description": [ + "Plex.tv Password.", + "NOTE: Required to generate Plex Auth-Token" + ], + "select": [] + }, + { + "name": "PlexAuthToken", + "displayName": "Plex AuthToken", + "value": "", + "description": [ + "Auth-Token for this script.", + "", + "Use the above button to authorize this script with Plex.tv", + "NOTE: The Password can be safely removing when setting the Auth-Token." + ], + "select": [] + }, + { + "name": "PlexHost", + "displayName": "Plex Host", + "value": "192.168.1.XXX:32400", + "description": [ + "Plex Media Server Host.", + "", + "IP or hostname of your Plex Media Server including port (only 1 server is supported)." + ], + "select": [] + }, + { + "name": "refreshMode", + "displayName": "Refresh Mode", + "value": "Auto", + "description": [ + "Library Refresh Mode.", + "", + "Select Refresh Mode:", + "Auto will automatically detect your NZBGet category and refresh the appropriate sections;", + "Custom will only refresh the sections you input into the Custom sections setting below;", + "Both will auto-detect and refresh the Custom Sections." + ], + "select": ["Auto", "Custom", "Both"] + }, + { + "name": "moviesCat", + "displayName": "Movies Category", + "value": "Movies", + "description": [ + "NZBGet Movies Category/Categories.", + "", + "List the name(s) of your NZBGet categories (CategoryX.Name) that correspond to Movies (comma separated).", + "NOTE: Required for Auto Mode" + ], + "select": [] + }, + { + "name": "tvCat", + "displayName": "TV Category", + "value": "TV", + "description": [ + "NZBGet TV Category/Categories.", + "", + "List the name(s) of your NZBGet categories (CategoryX.Name) that correspond to TV Shows (comma separated).", + "NOTE: Required for Auto Mode" + ], + "select": [] + }, + { + "name": "customPlexSection", + "displayName": "Custom Plex Section", + "value": "", + "description": [ + "Custom Plex Section(s) you would like to update.", + "", + "Section Number(s) corresponding to your Plex library (comma separated).", + "These sections will only refreshed if Library Refesh Mode is set to Custom or Both.", + "NOTE: Is Optional. Can be easily found in URL, e.g: 192.168.1.XXX:32400...?source=3 - 3 is what we need", + "NOTE: \"Plex video files scanner\" is preferable to use" + ], + "select": [] + } + ], + "commands": [ + { + "name": "PlexAuthorize", + "action": "Generate Plex Auth-Token", + "displayName": "Plex Authorize", + "description": [ + "Authorize script with Plex server.", + "", + "Once authorized, it will be visible in your Plex server settings as \"NotifyPlex\"", + "in the \"Authorized Devices\" section.", + "NOTE: Required if refreshLibrary is enabled." + ] + } + ], + "taskTime": "" +} \ No newline at end of file diff --git a/tests.py b/tests.py index d240da0..8a74833 100644 --- a/tests.py +++ b/tests.py @@ -49,9 +49,8 @@ def do_GET(self): b'composite="/library/sections/2/composite/1709800247" filters="1" refreshing="0" '+ b'thumb="/:/resources/movie.png" key="2" type="movie" title="Movies" agent="tv.plex.agents.movie" ' + b'scanner="Plex Movie" language="en-US" uuid="d495999b-6b8c-4676-9c1c-78e61175f0f5" ' + - b'updatedAt="1709711552" createdAt="1709705968" scannedAt="1709800247" content="1" directory="1" contentChangedAt="1691" hidden="0">' - b'' + - b'' + + b'updatedAt="1709711552" createdAt="1709705968" scannedAt="1709800247" content="1" directory="1" contentChangedAt="1691" hidden="0">' + + b'' + b'