From aee3b151c0f2a7f34c705d91d94af9c720a96e7b Mon Sep 17 00:00:00 2001 From: Clinton Hall Date: Fri, 29 Mar 2019 09:50:43 +1300 Subject: [PATCH] Lazylib 1 (#1587) * add support for LazyLibrarian. Fixes #1223 --- TorrentToMedia.py | 5 +- autoProcessMedia.cfg.spec | 25 +++++++++ core/auto_process/books.py | 75 ++++++++++++++++++++++++++ core/configuration.py | 15 ++++++ nzbToCouchPotato.py | 2 +- nzbToGamez.py | 2 +- nzbToLazyLibrarian.py | 104 +++++++++++++++++++++++++++++++++++++ nzbToMedia.py | 40 +++++++++++++- 8 files changed, 263 insertions(+), 5 deletions(-) create mode 100644 core/auto_process/books.py create mode 100755 nzbToLazyLibrarian.py diff --git a/TorrentToMedia.py b/TorrentToMedia.py index bd1166f4..06d36e1a 100755 --- a/TorrentToMedia.py +++ b/TorrentToMedia.py @@ -13,7 +13,7 @@ import sys import core from core import logger, main_db -from core.auto_process import comics, games, movies, music, tv +from core.auto_process import comics, games, movies, music, tv, books from core.auto_process.common import ProcessResult from core.plugins.plex import plex_update from core.user_scripts import external_script @@ -256,6 +256,9 @@ def process_torrent(input_directory, input_name, input_category, input_hash, inp result = comics.process(section_name, output_destination, input_name, status, client_agent, input_category) elif section_name == 'Gamez': result = games.process(section_name, output_destination, input_name, status, client_agent, input_category) + elif section_name == 'LazyLibrarian': + result = books.process(section_name, output_destination, input_name, status, client_agent, input_category) + plex_update(input_category) diff --git a/autoProcessMedia.cfg.spec b/autoProcessMedia.cfg.spec index 767d937c..b54c640d 100644 --- a/autoProcessMedia.cfg.spec +++ b/autoProcessMedia.cfg.spec @@ -282,6 +282,31 @@ ##### Set to path where download client places completed downloads locally for this category watch_dir = +[LazyLibrarian] + #### autoProcessing for Games + #### games - category that gets called for post-processing with Gamez + [[books]] + enabled = 0 + apikey = + host = localhost + port = 5299 + ###### ADVANCED USE - ONLY EDIT IF YOU KNOW WHAT YOU'RE DOING ###### + ssl = 0 + web_root = + # Enable/Disable linking for Torrents + Torrent_NoLink = 0 + keep_archive = 1 + extract = 1 + # Set this to minimum required size to consider a media file valid (in MB) + minSize = 0 + # Enable/Disable deleting ignored files (samples and invalid media files) + delete_ignored = 0 + ##### Enable if LazyLibrarian is on a remote server for this category + remote_path = 0 + ##### Set to path where download client places completed downloads locally for this category + watch_dir = + + [Network] # Enter Mount points as LocalPath,RemotePath and separate each pair with '|' # e.g. MountPoints = /volume1/Public/,E:\|/volume2/share/,\\NAS\ diff --git a/core/auto_process/books.py b/core/auto_process/books.py new file mode 100644 index 00000000..b05032db --- /dev/null +++ b/core/auto_process/books.py @@ -0,0 +1,75 @@ +# coding=utf-8 + +import os +import shutil + +import requests + +import core +from core import logger +from core.auto_process.common import ProcessResult +from core.utils import convert_to_ascii, server_responding + +requests.packages.urllib3.disable_warnings() + + +def process(section, dir_name, input_name=None, status=0, client_agent='manual', input_category=None): + status = int(status) + + cfg = dict(core.CFG[section][input_category]) + + host = cfg['host'] + port = cfg['port'] + apikey = cfg['apikey'] + ssl = int(cfg.get('ssl', 0)) + web_root = cfg.get('web_root', '') + protocol = 'https://' if ssl else 'http://' + + url = '{0}{1}:{2}{3}/api'.format(protocol, host, port, web_root) + if not server_responding(url): + logger.error('Server did not respond. Exiting', section) + return ProcessResult( + message='{0}: Failed to post-process - {0} did not respond.'.format(section), + status_code=1, + ) + + input_name, dir_name = convert_to_ascii(input_name, dir_name) + + params = { + 'api_key': apikey, + 'cmd': 'forceProcess', + 'dir': dir_name, + } + + logger.debug('Opening URL: {0}'.format(url), section) + + try: + r = requests.get(url, params=params, verify=False, timeout=(30, 300)) + except requests.ConnectionError: + logger.error('Unable to open URL') + return ProcessResult( + message='{0}: Failed to post-process - Unable to connect to {1}'.format(section, section), + status_code=1, + ) + + result = r.json() + logger.postprocess('{0}'.format(result), section) + + if r.status_code not in [requests.codes.ok, requests.codes.created, requests.codes.accepted]: + logger.error('Server returned status {0}'.format(r.status_code), section) + return ProcessResult( + message='{0}: Failed to post-process - Server returned status {1}'.format(section, r.status_code), + status_code=1, + ) + elif result['success']: + logger.postprocess('SUCCESS: ForceProcess for {0} has been started in LazyLibrarian'.format(dir_name), section) + return ProcessResult( + message='{0}: Successfully post-processed {1}'.format(section, input_name), + status_code=0, + ) + else: + logger.error('FAILED: ForceProcess of {0} has Failed in LazyLibrarian'.format(dir_name), section) + return ProcessResult( + message='{0}: Failed to post-process - Returned log from {0} was not as expected.'.format(section), + status_code=1, + ) diff --git a/core/configuration.py b/core/configuration.py index 31ea4852..216a1f05 100644 --- a/core/configuration.py +++ b/core/configuration.py @@ -383,6 +383,21 @@ class ConfigObj(configobj.ConfigObj, Section): cfg_new[section][os.environ[env_cat_key]][option] = value cfg_new[section][os.environ[env_cat_key]]['enabled'] = 1 + section = 'LazyLibrarian' + env_cat_key = 'NZBPO_LLCATEGORY' + env_keys = ['ENABLED', 'APIKEY', 'HOST', 'PORT', 'SSL', 'WEB_ROOT', 'WATCH_DIR', 'REMOTE_PATH'] + cfg_keys = ['enabled', 'apikey', 'host', 'port', 'ssl', 'web_root', 'watch_dir', 'remote_path'] + if env_cat_key in os.environ: + for index in range(len(env_keys)): + key = 'NZBPO_LL{index}'.format(index=env_keys[index]) + if key in os.environ: + option = cfg_keys[index] + value = os.environ[key] + if os.environ[env_cat_key] not in cfg_new[section].sections: + cfg_new[section][os.environ[env_cat_key]] = {} + cfg_new[section][os.environ[env_cat_key]][option] = value + cfg_new[section][os.environ[env_cat_key]]['enabled'] = 1 + section = 'NzbDrone' env_cat_key = 'NZBPO_NDCATEGORY' env_keys = ['ENABLED', 'HOST', 'APIKEY', 'PORT', 'SSL', 'WEB_ROOT', 'WATCH_DIR', 'FORK', 'DELETE_FAILED', diff --git a/nzbToCouchPotato.py b/nzbToCouchPotato.py index 12223106..be7fb4f3 100755 --- a/nzbToCouchPotato.py +++ b/nzbToCouchPotato.py @@ -4,7 +4,7 @@ ############################################################################## ### NZBGET POST-PROCESSING SCRIPT ### -# Post-Process to CouchPotato, SickBeard, NzbDrone, Mylar, Gamez, HeadPhones. +# Post-Process to CouchPotato. # # This script sends the download to your automated media management servers. # diff --git a/nzbToGamez.py b/nzbToGamez.py index d1559e72..42d0a2f5 100755 --- a/nzbToGamez.py +++ b/nzbToGamez.py @@ -4,7 +4,7 @@ ############################################################################## ### NZBGET POST-PROCESSING SCRIPT ### -# Post-Process to CouchPotato, SickBeard, NzbDrone, Mylar, Gamez, HeadPhones. +# Post-Process to Gamez. # # This script sends the download to your automated media management servers. # diff --git a/nzbToLazyLibrarian.py b/nzbToLazyLibrarian.py new file mode 100755 index 00000000..96ab86c8 --- /dev/null +++ b/nzbToLazyLibrarian.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python +# coding=utf-8 +# +############################################################################## +### NZBGET POST-PROCESSING SCRIPT ### + +# Post-Process to LazyLibrarian. +# +# This script sends the download to your automated media management servers. +# +# NOTE: This script requires Python to be installed on your system. + +############################################################################## +# +### OPTIONS ### + +## General + +# Auto Update nzbToMedia (0, 1). +# +# Set to 1 if you want nzbToMedia to automatically check for and update to the latest version +#auto_update=0 + +# Safe Mode protection of DestDir (0, 1). +# +# Enable/Disable a safety check to ensure we don't process all downloads in the default_downloadDirectory by mistake. +#safe_mode=1 + +## LazyLibrarian + +# LazyLibrarian script category. +# +# category that gets called for post-processing with LazyLibrarian. +#llCategory=games + +# LazyLibrarian api key. +#llapikey= + +# LazyLibrarian host. +# +# The ipaddress for your LazyLibrarian server. e.g For the Same system use localhost or 127.0.0.1 +#llhost=localhost + +# LazyLibrarian port. +#llport=5299 + +# LazyLibrarian uses ssl (0, 1). +# +# Set to 1 if using ssl, else set to 0. +#llssl=0 + +# LazyLibrarian web_root +# +# set this if using a reverse proxy. +#llweb_root= + +# LazyLibrarian watch directory. +# +# set this to where your LazyLibrarian completed downloads are. +#llwatch_dir= + +## Posix + +# Niceness for external tasks Extractor and Transcoder. +# +# Set the Niceness value for the nice command. These range from -20 (most favorable to the process) to 19 (least favorable to the process). +#niceness=10 + +# ionice scheduling class (0, 1, 2, 3). +# +# Set the ionice scheduling class. 0 for none, 1 for real time, 2 for best-effort, 3 for idle. +#ionice_class=2 + +# ionice scheduling class data. +# +# Set the ionice scheduling class data. This defines the class data, if the class accepts an argument. For real time and best-effort, 0-7 is valid data. +#ionice_classdata=4 + +## WakeOnLan + +# use WOL (0, 1). +# +# set to 1 to send WOL broadcast to the mac and test the server (e.g. xbmc) on the host and port specified. +#wolwake=0 + +# WOL MAC +# +# enter the mac address of the system to be woken. +#wolmac=00:01:2e:2D:64:e1 + +# Set the Host and Port of a server to verify system has woken. +#wolhost=192.168.1.37 +#wolport=80 + +### NZBGET POST-PROCESSING SCRIPT ### +############################################################################## + +import sys + +import nzbToMedia + +section = 'LazyLibrarian' +result = nzbToMedia.main(sys.argv, section) +sys.exit(result) diff --git a/nzbToMedia.py b/nzbToMedia.py index d91f413f..c663916c 100755 --- a/nzbToMedia.py +++ b/nzbToMedia.py @@ -4,7 +4,8 @@ ############################################################################## ### NZBGET POST-PROCESSING SCRIPT ### -# Post-Process to CouchPotato, SickBeard, NzbDrone, Mylar, Gamez, HeadPhones. +# Post-Process to CouchPotato, SickBeard, Sonarr, Mylar, Gamez, HeadPhones, +# LazyLibrarian, Radarr, Lidarr # # This script sends the download to your automated media management servers. # @@ -410,6 +411,39 @@ # Enable to replace local path with the path as per the mountPoints below. #gzremote_path=0 +## LazyLibrarian + +# LazyLibrarian script category. +# +# category that gets called for post-processing with LazyLibrarian. +#llCategory=games + +# LazyLibrarian api key. +#llapikey= + +# LazyLibrarian host. +# +# The ipaddress for your LazyLibrarian server. e.g For the Same system use localhost or 127.0.0.1 +#llhost=localhost + +# LazyLibrarian port. +#llport=5299 + +# LazyLibrarian uses ssl (0, 1). +# +# Set to 1 if using ssl, else set to 0. +#llssl=0 + +# LazyLibrarian web_root +# +# set this if using a reverse proxy. +#llweb_root= + +# LazyLibrarian watch directory. +# +# set this to where your LazyLibrarian completed downloads are. +#llwatch_dir= + ## Network # Network Mount Points (Needed for remote path above) @@ -635,7 +669,7 @@ import sys import core from core import logger, main_db -from core.auto_process import comics, games, movies, music, tv +from core.auto_process import comics, games, movies, music, tv, books from core.auto_process.common import ProcessResult from core.plugins.downloaders.nzb.utils import get_nzoid from core.plugins.plex import plex_update @@ -763,6 +797,8 @@ def process(input_directory, input_name=None, status=0, client_agent='manual', d result = comics.process(section_name, input_directory, input_name, status, client_agent, input_category) elif section_name == 'Gamez': result = games.process(section_name, input_directory, input_name, status, client_agent, input_category) + elif section_name == 'LazyLibrarian': + result = books.process(section_name, input_directory, input_name, status, client_agent, input_category) elif section_name == 'UserScript': result = external_script(input_directory, input_name, input_category, section[usercat]) else: