Skip to content

Commit

Permalink
Feature: manifest.json (#2)
Browse files Browse the repository at this point in the history
## 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;
  • Loading branch information
dnzbk authored Mar 15, 2024
1 parent 43e5b79 commit c05ca8d
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 94 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ on:
push:
branches:
- feature/*
- main
- master
pull_request:
branches:
- master

jobs:
tests:
Expand Down
96 changes: 8 additions & 88 deletions NotifyPlex.py → main.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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)


Expand All @@ -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']
Expand All @@ -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']
Expand Down
153 changes: 153 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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": ""
}
10 changes: 6 additions & 4 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'<Location id="10" path="D:\Movies" />' +
b'</Directory>' +
b'updatedAt="1709711552" createdAt="1709705968" scannedAt="1709800247" content="1" directory="1" contentChangedAt="1691" hidden="0">' +
b'<Location id="10" path="D:\Movies" /></Directory>' +
b'<Directory allowSync="1" art="/:/resources/show-fanart.jpg" ' +
b'composite="/library/sections/3/composite/1709799889" filters="1" refreshing="0" ' +
b'thumb="/:/resources/show.png" key="3" type="show" title="Series" agent="tv.plex.agents.series" scanner="Plex TV Series" ' +
Expand All @@ -67,7 +66,7 @@ def get_python():

def run_script():
sys.stdout.flush()
proc = subprocess.Popen([get_python(), root + '/NotifyPlex.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=os.environ.copy())
proc = subprocess.Popen([get_python(), root + '/main.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=os.environ.copy())
out, err = proc.communicate()
proc.pid
ret_code = proc.returncode
Expand Down Expand Up @@ -109,6 +108,7 @@ def test_refresh_auto(self):
thread.start()
[_, code, _] = run_script()
server.shutdown()
server.server_close()
thread.join()
self.assertEqual(code, POSTPROCESS_SUCCESS)

Expand All @@ -122,6 +122,7 @@ def test_refresh_custom(self):
thread.start()
[_, code, _] = run_script()
server.shutdown()
server.server_close()
thread.join()
self.assertEqual(code, POSTPROCESS_SUCCESS)

Expand All @@ -135,6 +136,7 @@ def test_refresh_both(self):
thread.start()
[_, code, _] = run_script()
server.shutdown()
server.server_close()
thread.join()
self.assertEqual(code, POSTPROCESS_SUCCESS)

Expand Down

0 comments on commit c05ca8d

Please sign in to comment.