From e1aa32aee797af5800e39eb9297f1674b2861dad Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Sun, 3 Feb 2019 12:24:34 -0500 Subject: [PATCH 1/5] Refactor downloader configuration to plugins.downloaders --- core/__init__.py | 153 ++---------------- core/plugins/__init__.py | 0 core/plugins/downloaders/__init__.py | 0 core/plugins/downloaders/configuration.py | 5 + core/plugins/downloaders/nzb/__init__.py | 0 core/plugins/downloaders/nzb/configuration.py | 15 ++ core/plugins/downloaders/torrent/__init__.py | 0 .../downloaders/torrent/configuration.py | 81 ++++++++++ core/plugins/downloaders/torrent/deluge.py | 21 +++ .../downloaders/torrent/qbittorrent.py | 23 +++ .../downloaders/torrent/transmission.py | 20 +++ .../downloaders/torrent/utils.py} | 61 ++----- core/plugins/downloaders/torrent/utorrent.py | 19 +++ core/plugins/downloaders/utils.py | 5 + core/utils/__init__.py | 1 - 15 files changed, 218 insertions(+), 186 deletions(-) create mode 100644 core/plugins/__init__.py create mode 100644 core/plugins/downloaders/__init__.py create mode 100644 core/plugins/downloaders/configuration.py create mode 100644 core/plugins/downloaders/nzb/__init__.py create mode 100644 core/plugins/downloaders/nzb/configuration.py create mode 100644 core/plugins/downloaders/torrent/__init__.py create mode 100644 core/plugins/downloaders/torrent/configuration.py create mode 100644 core/plugins/downloaders/torrent/deluge.py create mode 100644 core/plugins/downloaders/torrent/qbittorrent.py create mode 100644 core/plugins/downloaders/torrent/transmission.py rename core/{utils/torrents.py => plugins/downloaders/torrent/utils.py} (57%) create mode 100644 core/plugins/downloaders/torrent/utorrent.py create mode 100644 core/plugins/downloaders/utils.py diff --git a/core/__init__.py b/core/__init__.py index 15d78bfd..c59daa92 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -46,12 +46,21 @@ from six.moves import reload_module from core import logger, main_db, version_check, databases, transcoder from core.configuration import config +from core.plugins.downloaders.configuration import ( + configure_nzbs, + configure_torrents, + configure_torrent_class, +) +from core.plugins.downloaders.utils import ( + pause_torrent, + remove_torrent, + resume_torrent, +) from core.utils import ( RunningProcess, category_search, clean_dir, copy_link, - create_torrent_class, extract_files, flatten, get_dirs, @@ -59,13 +68,10 @@ from core.utils import ( list_media_files, make_dir, parse_args, - pause_torrent, rchmod, remove_dir, remove_read_only, - remove_torrent, restart, - resume_torrent, sanitize_name, update_download_info_status, wake_up, @@ -403,26 +409,6 @@ def configure_wake_on_lan(): wake_up() -def configure_sabnzbd(): - global SABNZBD_HOST - global SABNZBD_PORT - global SABNZBD_APIKEY - - SABNZBD_HOST = CFG['Nzb']['sabnzbd_host'] - SABNZBD_PORT = int(CFG['Nzb']['sabnzbd_port'] or 8080) # defaults to accommodate NzbGet - SABNZBD_APIKEY = CFG['Nzb']['sabnzbd_apikey'] - - -def configure_nzbs(): - global NZB_CLIENT_AGENT - global NZB_DEFAULT_DIRECTORY - - NZB_CLIENT_AGENT = CFG['Nzb']['clientAgent'] # sabnzbd - NZB_DEFAULT_DIRECTORY = CFG['Nzb']['default_downloadDirectory'] - - configure_sabnzbd() - - def configure_groups(): global GROUPS @@ -435,114 +421,6 @@ def configure_groups(): GROUPS = None -def configure_utorrent(): - global UTORRENT_WEB_UI - global UTORRENT_USER - global UTORRENT_PASSWORD - - UTORRENT_WEB_UI = CFG['Torrent']['uTorrentWEBui'] # http://localhost:8090/gui/ - UTORRENT_USER = CFG['Torrent']['uTorrentUSR'] # mysecretusr - UTORRENT_PASSWORD = CFG['Torrent']['uTorrentPWD'] # mysecretpwr - - -def configure_transmission(): - global TRANSMISSION_HOST - global TRANSMISSION_PORT - global TRANSMISSION_USER - global TRANSMISSION_PASSWORD - - TRANSMISSION_HOST = CFG['Torrent']['TransmissionHost'] # localhost - TRANSMISSION_PORT = int(CFG['Torrent']['TransmissionPort']) - TRANSMISSION_USER = CFG['Torrent']['TransmissionUSR'] # mysecretusr - TRANSMISSION_PASSWORD = CFG['Torrent']['TransmissionPWD'] # mysecretpwr - - -def configure_deluge(): - global DELUGE_HOST - global DELUGE_PORT - global DELUGE_USER - global DELUGE_PASSWORD - - DELUGE_HOST = CFG['Torrent']['DelugeHost'] # localhost - DELUGE_PORT = int(CFG['Torrent']['DelugePort']) # 8084 - DELUGE_USER = CFG['Torrent']['DelugeUSR'] # mysecretusr - DELUGE_PASSWORD = CFG['Torrent']['DelugePWD'] # mysecretpwr - - -def configure_qbittorrent(): - global QBITTORRENT_HOST - global QBITTORRENT_PORT - global QBITTORRENT_USER - global QBITTORRENT_PASSWORD - - QBITTORRENT_HOST = CFG['Torrent']['qBittorrenHost'] # localhost - QBITTORRENT_PORT = int(CFG['Torrent']['qBittorrentPort']) # 8080 - QBITTORRENT_USER = CFG['Torrent']['qBittorrentUSR'] # mysecretusr - QBITTORRENT_PASSWORD = CFG['Torrent']['qBittorrentPWD'] # mysecretpwr - - -def configure_flattening(): - global NOFLATTEN - - NOFLATTEN = (CFG['Torrent']['noFlatten']) - if isinstance(NOFLATTEN, str): - NOFLATTEN = NOFLATTEN.split(',') - - -def configure_torrent_categories(): - global CATEGORIES - - CATEGORIES = (CFG['Torrent']['categories']) # music,music_videos,pictures,software - if isinstance(CATEGORIES, str): - CATEGORIES = CATEGORIES.split(',') - - -def configure_torrent_resuming(): - global TORRENT_RESUME - global TORRENT_RESUME_ON_FAILURE - - TORRENT_RESUME_ON_FAILURE = int(CFG['Torrent']['resumeOnFailure']) - TORRENT_RESUME = int(CFG['Torrent']['resume']) - - -def configure_torrent_permissions(): - global TORRENT_CHMOD_DIRECTORY - - TORRENT_CHMOD_DIRECTORY = int(str(CFG['Torrent']['chmodDirectory']), 8) - - -def configure_torrent_deltetion(): - global DELETE_ORIGINAL - - DELETE_ORIGINAL = int(CFG['Torrent']['deleteOriginal']) - - -def configure_torrent_linking(): - global USE_LINK - - USE_LINK = CFG['Torrent']['useLink'] # no | hard | sym - - -def configure_torrents(): - global TORRENT_CLIENT_AGENT - global OUTPUT_DIRECTORY - global TORRENT_DEFAULT_DIRECTORY - - TORRENT_CLIENT_AGENT = CFG['Torrent']['clientAgent'] # utorrent | deluge | transmission | rtorrent | vuze | qbittorrent |other - OUTPUT_DIRECTORY = CFG['Torrent']['outputDirectory'] # /abs/path/to/complete/ - TORRENT_DEFAULT_DIRECTORY = CFG['Torrent']['default_downloadDirectory'] - configure_torrent_linking() - configure_flattening() - configure_torrent_deltetion() - configure_torrent_categories() - configure_torrent_permissions() - configure_torrent_resuming() - configure_utorrent() - configure_transmission() - configure_deluge() - configure_qbittorrent() - - def configure_remote_paths(): global REMOTE_PATHS @@ -973,13 +851,6 @@ def configure_passwords_file(): PASSWORDS_FILE = CFG['passwords']['PassWordFile'] -def configure_torrent_class(): - global TORRENT_CLASS - - # create torrent class - TORRENT_CLASS = create_torrent_class(TORRENT_CLIENT_AGENT) - - def configure_sections(section): global SECTIONS global CATEGORIES @@ -1138,8 +1009,8 @@ def initialize(section=None): configure_general() configure_updates() configure_wake_on_lan() - configure_nzbs() - configure_torrents() + configure_nzbs(CFG) + configure_torrents(CFG) configure_remote_paths() configure_plex() configure_niceness() diff --git a/core/plugins/__init__.py b/core/plugins/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/core/plugins/downloaders/__init__.py b/core/plugins/downloaders/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/core/plugins/downloaders/configuration.py b/core/plugins/downloaders/configuration.py new file mode 100644 index 00000000..7ea4f881 --- /dev/null +++ b/core/plugins/downloaders/configuration.py @@ -0,0 +1,5 @@ +from core.plugins.downloaders.nzb.configuration import configure_nzbs +from core.plugins.downloaders.torrent.configuration import ( + configure_torrents, + configure_torrent_class, +) diff --git a/core/plugins/downloaders/nzb/__init__.py b/core/plugins/downloaders/nzb/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/core/plugins/downloaders/nzb/configuration.py b/core/plugins/downloaders/nzb/configuration.py new file mode 100644 index 00000000..d0883d01 --- /dev/null +++ b/core/plugins/downloaders/nzb/configuration.py @@ -0,0 +1,15 @@ +import core + + +def configure_nzbs(config): + nzb_config = config['Nzb'] + core.NZB_CLIENT_AGENT = nzb_config['clientAgent'] # sabnzbd + core.NZB_DEFAULT_DIRECTORY = nzb_config['default_downloadDirectory'] + + configure_sabnzbd(nzb_config) + + +def configure_sabnzbd(config): + core.SABNZBD_HOST = config['sabnzbd_host'] + core.SABNZBD_PORT = int(config['sabnzbd_port'] or 8080) # defaults to accommodate NzbGet + core.SABNZBD_APIKEY = config['sabnzbd_apikey'] diff --git a/core/plugins/downloaders/torrent/__init__.py b/core/plugins/downloaders/torrent/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/core/plugins/downloaders/torrent/configuration.py b/core/plugins/downloaders/torrent/configuration.py new file mode 100644 index 00000000..92001636 --- /dev/null +++ b/core/plugins/downloaders/torrent/configuration.py @@ -0,0 +1,81 @@ +import core +from core.plugins.downloaders.torrent.utils import create_torrent_class + + +def configure_torrents(config): + torrent_config = config['Torrent'] + core.TORRENT_CLIENT_AGENT = torrent_config['clientAgent'] # utorrent | deluge | transmission | rtorrent | vuze | qbittorrent |other + core.OUTPUT_DIRECTORY = torrent_config['outputDirectory'] # /abs/path/to/complete/ + core.TORRENT_DEFAULT_DIRECTORY = torrent_config['default_downloadDirectory'] + + configure_torrent_linking(torrent_config) + configure_flattening(torrent_config) + configure_torrent_deletion(torrent_config) + configure_torrent_categories(torrent_config) + configure_torrent_permissions(torrent_config) + configure_torrent_resuming(torrent_config) + configure_utorrent(torrent_config) + configure_transmission(torrent_config) + configure_deluge(torrent_config) + configure_qbittorrent(torrent_config) + + +def configure_torrent_linking(config): + core.USE_LINK = config['useLink'] # no | hard | sym + + +def configure_flattening(config): + core.NOFLATTEN = (config['noFlatten']) + if isinstance(core.NOFLATTEN, str): + core.NOFLATTEN = core.NOFLATTEN.split(',') + + +def configure_torrent_categories(config): + core.CATEGORIES = (config['categories']) # music,music_videos,pictures,software + if isinstance(core.CATEGORIES, str): + core.CATEGORIES = core.CATEGORIES.split(',') + + +def configure_torrent_resuming(config): + core.TORRENT_RESUME_ON_FAILURE = int(config['resumeOnFailure']) + core.TORRENT_RESUME = int(config['resume']) + + +def configure_torrent_permissions(config): + core.TORRENT_CHMOD_DIRECTORY = int(str(config['chmodDirectory']), 8) + + +def configure_torrent_deletion(config): + core.DELETE_ORIGINAL = int(config['deleteOriginal']) + + +def configure_utorrent(config): + core.UTORRENT_WEB_UI = config['uTorrentWEBui'] # http://localhost:8090/gui/ + core.UTORRENT_USER = config['uTorrentUSR'] # mysecretusr + core.UTORRENT_PASSWORD = config['uTorrentPWD'] # mysecretpwr + + +def configure_transmission(config): + core.TRANSMISSION_HOST = config['TransmissionHost'] # localhost + core.TRANSMISSION_PORT = int(config['TransmissionPort']) + core.TRANSMISSION_USER = config['TransmissionUSR'] # mysecretusr + core.TRANSMISSION_PASSWORD = config['TransmissionPWD'] # mysecretpwr + + +def configure_deluge(config): + core.DELUGE_HOST = config['DelugeHost'] # localhost + core.DELUGE_PORT = int(config['DelugePort']) # 8084 + core.DELUGE_USER = config['DelugeUSR'] # mysecretusr + core.DELUGE_PASSWORD = config['DelugePWD'] # mysecretpwr + + +def configure_qbittorrent(config): + core.QBITTORRENT_HOST = config['qBittorrenHost'] # localhost + core.QBITTORRENT_PORT = int(config['qBittorrentPort']) # 8080 + core.QBITTORRENT_USER = config['qBittorrentUSR'] # mysecretusr + core.QBITTORRENT_PASSWORD = config['qBittorrentPWD'] # mysecretpwr + + +def configure_torrent_class(): + # create torrent class + core.TORRENT_CLASS = create_torrent_class(core.TORRENT_CLIENT_AGENT) diff --git a/core/plugins/downloaders/torrent/deluge.py b/core/plugins/downloaders/torrent/deluge.py new file mode 100644 index 00000000..69ae2000 --- /dev/null +++ b/core/plugins/downloaders/torrent/deluge.py @@ -0,0 +1,21 @@ +from synchronousdeluge.client import DelugeClient + +import core +from core import logger + + +def configure_client(): + agent = 'deluge' + host = core.DELUGE_HOST + port = core.DELUGE_PORT + user = core.DELUGE_USER + password = core.DELUGE_PASSWORD + + logger.debug('Connecting to {0}: http://{1}:{2}'.format(agent, host, port)) + client = DelugeClient() + try: + client.connect(host, port, user, password) + except Exception: + logger.error('Failed to connect to Deluge') + else: + return client diff --git a/core/plugins/downloaders/torrent/qbittorrent.py b/core/plugins/downloaders/torrent/qbittorrent.py new file mode 100644 index 00000000..37671fea --- /dev/null +++ b/core/plugins/downloaders/torrent/qbittorrent.py @@ -0,0 +1,23 @@ +from qbittorrent import Client as qBittorrentClient + +import core +from core import logger + + +def configure_client(): + agent = 'qbittorrent' + host = core.QBITTORRENT_HOST + port = core.QBITTORRENT_PORT + user = core.QBITTORRENT_USER + password = core.QBITTORRENT_PASSWORD + + logger.debug( + 'Connecting to {0}: http://{1}:{2}'.format(agent, host, port) + ) + client = qBittorrentClient('http://{0}:{1}/'.format(host, port)) + try: + client.login(user, password) + except Exception: + logger.error('Failed to connect to qBittorrent') + else: + return client diff --git a/core/plugins/downloaders/torrent/transmission.py b/core/plugins/downloaders/torrent/transmission.py new file mode 100644 index 00000000..d122aaf0 --- /dev/null +++ b/core/plugins/downloaders/torrent/transmission.py @@ -0,0 +1,20 @@ +from transmissionrpc.client import Client as TransmissionClient + +import core +from core import logger + + +def configure_client(): + agent = 'transmission' + host = core.TRANSMISSION_HOST + port = core.TRANSMISSION_PORT + user = core.TRANSMISSION_USER + password = core.TRANSMISSION_PASSWORD + + logger.debug('Connecting to {0}: http://{1}:{2}'.format(agent, host, port)) + try: + client = TransmissionClient(host, port, user, password) + except Exception: + logger.error('Failed to connect to Transmission') + else: + return client diff --git a/core/utils/torrents.py b/core/plugins/downloaders/torrent/utils.py similarity index 57% rename from core/utils/torrents.py rename to core/plugins/downloaders/torrent/utils.py index 4c152e47..be2db4e8 100644 --- a/core/utils/torrents.py +++ b/core/plugins/downloaders/torrent/utils.py @@ -1,55 +1,28 @@ import time -from qbittorrent import Client as qBittorrentClient -from synchronousdeluge.client import DelugeClient -from transmissionrpc.client import Client as TransmissionClient -from utorrent.client import UTorrentClient - import core from core import logger +from .deluge import configure_client as deluge_client +from .qbittorrent import configure_client as qbittorrent_client +from .transmission import configure_client as transmission_client +from .utorrent import configure_client as utorrent_client + +torrent_clients = { + 'deluge': deluge_client, + 'qbittorrent': qbittorrent_client, + 'transmission': transmission_client, + 'utorrent': utorrent_client, +} + def create_torrent_class(client_agent): - # Hardlink solution for Torrents - tc = None - if not core.APP_NAME == 'TorrentToMedia.py': #Skip loading Torrent for NZBs. - return tc + if not core.APP_NAME == 'TorrentToMedia.py': + return # Skip loading Torrent for NZBs. - if client_agent == 'utorrent': - try: - logger.debug('Connecting to {0}: {1}'.format(client_agent, core.UTORRENT_WEB_UI)) - tc = UTorrentClient(core.UTORRENT_WEB_UI, core.UTORRENT_USER, core.UTORRENT_PASSWORD) - except Exception: - logger.error('Failed to connect to uTorrent') - - if client_agent == 'transmission': - try: - logger.debug('Connecting to {0}: http://{1}:{2}'.format( - client_agent, core.TRANSMISSION_HOST, core.TRANSMISSION_PORT)) - tc = TransmissionClient(core.TRANSMISSION_HOST, core.TRANSMISSION_PORT, - core.TRANSMISSION_USER, - core.TRANSMISSION_PASSWORD) - except Exception: - logger.error('Failed to connect to Transmission') - - if client_agent == 'deluge': - try: - logger.debug('Connecting to {0}: http://{1}:{2}'.format(client_agent, core.DELUGE_HOST, core.DELUGE_PORT)) - tc = DelugeClient() - tc.connect(host=core.DELUGE_HOST, port=core.DELUGE_PORT, username=core.DELUGE_USER, - password=core.DELUGE_PASSWORD) - except Exception: - logger.error('Failed to connect to Deluge') - - if client_agent == 'qbittorrent': - try: - logger.debug('Connecting to {0}: http://{1}:{2}'.format(client_agent, core.QBITTORRENT_HOST, core.QBITTORRENT_PORT)) - tc = qBittorrentClient('http://{0}:{1}/'.format(core.QBITTORRENT_HOST, core.QBITTORRENT_PORT)) - tc.login(core.QBITTORRENT_USER, core.QBITTORRENT_PASSWORD) - except Exception: - logger.error('Failed to connect to qBittorrent') - - return tc + client = torrent_clients.get(client_agent) + if client: + return client() def pause_torrent(client_agent, input_hash, input_id, input_name): diff --git a/core/plugins/downloaders/torrent/utorrent.py b/core/plugins/downloaders/torrent/utorrent.py new file mode 100644 index 00000000..95422bfe --- /dev/null +++ b/core/plugins/downloaders/torrent/utorrent.py @@ -0,0 +1,19 @@ +from utorrent.client import UTorrentClient + +import core +from core import logger + + +def configure_client(): + agent = 'utorrent' + web_ui = core.UTORRENT_WEB_UI + user = core.UTORRENT_USER + password = core.UTORRENT_PASSWORD + + logger.debug('Connecting to {0}: {1}'.format(agent, web_ui)) + try: + client = UTorrentClient(web_ui, user, password) + except Exception: + logger.error('Failed to connect to uTorrent') + else: + return client diff --git a/core/plugins/downloaders/utils.py b/core/plugins/downloaders/utils.py new file mode 100644 index 00000000..a84d270b --- /dev/null +++ b/core/plugins/downloaders/utils.py @@ -0,0 +1,5 @@ +from core.plugins.downloaders.torrent.utils import ( + pause_torrent, + remove_torrent, + resume_torrent, +) diff --git a/core/utils/__init__.py b/core/utils/__init__.py index 0083fbbd..b662e9ae 100644 --- a/core/utils/__init__.py +++ b/core/utils/__init__.py @@ -45,7 +45,6 @@ from core.utils.paths import ( ) from core.utils.processes import RunningProcess, restart from core.utils.subtitles import import_subs -from core.utils.torrents import create_torrent_class, pause_torrent, remove_torrent, resume_torrent requests.packages.urllib3.disable_warnings() shutil_custom.monkey_patch() From 1d75439441dece2be2f315240e1797cfd2409a4f Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Sun, 10 Mar 2019 11:09:26 -0400 Subject: [PATCH 2/5] Refactor utils.nzb to plugins.downloaders.nzb.utils --- core/auto_process/movies.py | 18 ++++++++++++++++-- core/auto_process/tv.py | 17 +++++++++++++++-- .../downloaders/nzb/utils.py} | 0 core/utils/__init__.py | 1 - 4 files changed, 31 insertions(+), 5 deletions(-) rename core/{utils/nzbs.py => plugins/downloaders/nzb/utils.py} (100%) diff --git a/core/auto_process/movies.py b/core/auto_process/movies.py index c0f1ace4..98ce62ad 100644 --- a/core/auto_process/movies.py +++ b/core/auto_process/movies.py @@ -8,9 +8,23 @@ import requests import core from core import logger, transcoder -from core.auto_process.common import command_complete, completed_download_handling, ProcessResult +from core.auto_process.common import ( + ProcessResult, + command_complete, + completed_download_handling, +) +from core.plugins.downloaders.nzb.utils import report_nzb from core.scene_exceptions import process_all_exceptions -from core.utils import convert_to_ascii, find_download, find_imdbid, import_subs, list_media_files, remote_dir, remove_dir, report_nzb, server_responding +from core.utils import ( + convert_to_ascii, + find_download, + find_imdbid, + import_subs, + list_media_files, + remote_dir, + remove_dir, + server_responding, +) requests.packages.urllib3.disable_warnings() diff --git a/core/auto_process/tv.py b/core/auto_process/tv.py index bfc1a8d9..3b9b46d3 100644 --- a/core/auto_process/tv.py +++ b/core/auto_process/tv.py @@ -10,10 +10,23 @@ import requests import core from core import logger, transcoder -from core.auto_process.common import command_complete, completed_download_handling, ProcessResult +from core.auto_process.common import ( + ProcessResult, + command_complete, + completed_download_handling, +) from core.forks import auto_fork +from core.plugins.downloaders.nzb.utils import report_nzb from core.scene_exceptions import process_all_exceptions -from core.utils import convert_to_ascii, flatten, import_subs, list_media_files, remote_dir, remove_dir, report_nzb, server_responding +from core.utils import ( + convert_to_ascii, + flatten, + import_subs, + list_media_files, + remote_dir, + remove_dir, + server_responding, +) requests.packages.urllib3.disable_warnings() diff --git a/core/utils/nzbs.py b/core/plugins/downloaders/nzb/utils.py similarity index 100% rename from core/utils/nzbs.py rename to core/plugins/downloaders/nzb/utils.py diff --git a/core/utils/__init__.py b/core/utils/__init__.py index b662e9ae..6817860a 100644 --- a/core/utils/__init__.py +++ b/core/utils/__init__.py @@ -20,7 +20,6 @@ from core.utils.links import copy_link, replace_links from core.utils.naming import clean_file_name, is_sample, sanitize_name from core.utils.network import find_download, server_responding, test_connection, wake_on_lan, wake_up from core.utils.notifications import plex_update -from core.utils.nzbs import get_nzoid, report_nzb from core.utils.parsers import ( parse_args, parse_deluge, From e12f2724e62b6abd74769f8d1390446350889754 Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Sun, 10 Mar 2019 10:58:17 -0400 Subject: [PATCH 3/5] Refactor plex configuration to plugins.plex --- core/__init__.py | 27 +++------------------------ core/plugins/plex.py | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 24 deletions(-) create mode 100644 core/plugins/plex.py diff --git a/core/__init__.py b/core/__init__.py index c59daa92..9468f5a1 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -11,9 +11,9 @@ import subprocess import sys import time +import eol import libs.autoload import libs.util -import eol if not libs.autoload.completed: sys.exit('Could not load vendored libraries.') @@ -56,6 +56,7 @@ from core.plugins.downloaders.utils import ( remove_torrent, resume_torrent, ) +from core.plugins.plex import configure_plex from core.utils import ( RunningProcess, category_search, @@ -443,28 +444,6 @@ def configure_remote_paths(): ] -def configure_plex(): - global PLEX_SSL - global PLEX_HOST - global PLEX_PORT - global PLEX_TOKEN - global PLEX_SECTION - - PLEX_SSL = int(CFG['Plex']['plex_ssl']) - PLEX_HOST = CFG['Plex']['plex_host'] - PLEX_PORT = CFG['Plex']['plex_port'] - PLEX_TOKEN = CFG['Plex']['plex_token'] - PLEX_SECTION = CFG['Plex']['plex_sections'] or [] - - if PLEX_SECTION: - if isinstance(PLEX_SECTION, list): - PLEX_SECTION = ','.join(PLEX_SECTION) # fix in case this imported as list. - PLEX_SECTION = [ - tuple(item.split(',')) - for item in PLEX_SECTION.split('|') - ] - - def configure_niceness(): global NICENESS @@ -1012,7 +991,7 @@ def initialize(section=None): configure_nzbs(CFG) configure_torrents(CFG) configure_remote_paths() - configure_plex() + configure_plex(CFG) configure_niceness() configure_containers() configure_transcoder() diff --git a/core/plugins/plex.py b/core/plugins/plex.py new file mode 100644 index 00000000..180cca66 --- /dev/null +++ b/core/plugins/plex.py @@ -0,0 +1,19 @@ +import core + + +def configure_plex(config): + core.PLEX_SSL = int(config['Plex']['plex_ssl']) + core.PLEX_HOST = config['Plex']['plex_host'] + core.PLEX_PORT = config['Plex']['plex_port'] + core.PLEX_TOKEN = config['Plex']['plex_token'] + plex_section = config['Plex']['plex_sections'] or [] + + if plex_section: + if isinstance(plex_section, list): + plex_section = ','.join(plex_section) # fix in case this imported as list. + plex_section = [ + tuple(item.split(',')) + for item in plex_section.split('|') + ] + + core.PLEX_SECTION = plex_section From 76b5c06a33964d9cd7909413bcdb16398f60a4a8 Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Sun, 10 Mar 2019 11:15:31 -0400 Subject: [PATCH 4/5] Refactor utils.notifications.plex_update to plugins.plex.plex_update --- core/plugins/plex.py | 27 +++++++++++++++++++++++++++ core/utils/__init__.py | 1 - core/utils/notifications.py | 30 ------------------------------ 3 files changed, 27 insertions(+), 31 deletions(-) delete mode 100644 core/utils/notifications.py diff --git a/core/plugins/plex.py b/core/plugins/plex.py index 180cca66..6d851e85 100644 --- a/core/plugins/plex.py +++ b/core/plugins/plex.py @@ -1,4 +1,7 @@ +import requests + import core +from core import logger def configure_plex(config): @@ -17,3 +20,27 @@ def configure_plex(config): ] core.PLEX_SECTION = plex_section + + +def plex_update(category): + if core.FAILED: + return + url = '{scheme}://{host}:{port}/library/sections/'.format( + scheme='https' if core.PLEX_SSL else 'http', + host=core.PLEX_HOST, + port=core.PLEX_PORT, + ) + section = None + if not core.PLEX_SECTION: + return + logger.debug('Attempting to update Plex Library for category {0}.'.format(category), 'PLEX') + for item in core.PLEX_SECTION: + if item[0] == category: + section = item[1] + + if section: + url = '{url}{section}/refresh?X-Plex-Token={token}'.format(url=url, section=section, token=core.PLEX_TOKEN) + requests.get(url, timeout=(60, 120), verify=False) + logger.debug('Plex Library has been refreshed.', 'PLEX') + else: + logger.debug('Could not identify section for plex update', 'PLEX') diff --git a/core/utils/__init__.py b/core/utils/__init__.py index 6817860a..88b9692f 100644 --- a/core/utils/__init__.py +++ b/core/utils/__init__.py @@ -19,7 +19,6 @@ from core.utils.identification import category_search, find_imdbid from core.utils.links import copy_link, replace_links from core.utils.naming import clean_file_name, is_sample, sanitize_name from core.utils.network import find_download, server_responding, test_connection, wake_on_lan, wake_up -from core.utils.notifications import plex_update from core.utils.parsers import ( parse_args, parse_deluge, diff --git a/core/utils/notifications.py b/core/utils/notifications.py deleted file mode 100644 index ddad0c1b..00000000 --- a/core/utils/notifications.py +++ /dev/null @@ -1,30 +0,0 @@ -import requests - -import core -from core import logger - - -def plex_update(category): - if core.FAILED: - return - url = '{scheme}://{host}:{port}/library/sections/'.format( - scheme='https' if core.PLEX_SSL else 'http', - host=core.PLEX_HOST, - port=core.PLEX_PORT, - ) - section = None - if not core.PLEX_SECTION: - return - logger.debug('Attempting to update Plex Library for category {0}.'.format(category), 'PLEX') - for item in core.PLEX_SECTION: - if item[0] == category: - section = item[1] - - if section: - url = '{url}{section}/refresh?X-Plex-Token={token}'.format(url=url, section=section, token=core.PLEX_TOKEN) - requests.get(url, timeout=(60, 120), verify=False) - logger.debug('Plex Library has been refreshed.', 'PLEX') - else: - logger.debug('Could not identify section for plex update', 'PLEX') - - From b6db785c9221638c152a10a5c0555ba24f19b8e3 Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Sun, 10 Mar 2019 11:28:54 -0400 Subject: [PATCH 5/5] Refactor utils.subtitles to plugins.subtitles --- core/auto_process/movies.py | 2 +- core/auto_process/tv.py | 2 +- core/{utils => plugins}/subtitles.py | 0 core/user_scripts.py | 3 ++- core/utils/__init__.py | 1 - 5 files changed, 4 insertions(+), 4 deletions(-) rename core/{utils => plugins}/subtitles.py (100%) diff --git a/core/auto_process/movies.py b/core/auto_process/movies.py index 98ce62ad..b7fe3a66 100644 --- a/core/auto_process/movies.py +++ b/core/auto_process/movies.py @@ -14,12 +14,12 @@ from core.auto_process.common import ( completed_download_handling, ) from core.plugins.downloaders.nzb.utils import report_nzb +from core.plugins.subtitles import import_subs from core.scene_exceptions import process_all_exceptions from core.utils import ( convert_to_ascii, find_download, find_imdbid, - import_subs, list_media_files, remote_dir, remove_dir, diff --git a/core/auto_process/tv.py b/core/auto_process/tv.py index 3b9b46d3..c4a68f59 100644 --- a/core/auto_process/tv.py +++ b/core/auto_process/tv.py @@ -17,11 +17,11 @@ from core.auto_process.common import ( ) from core.forks import auto_fork from core.plugins.downloaders.nzb.utils import report_nzb +from core.plugins.subtitles import import_subs from core.scene_exceptions import process_all_exceptions from core.utils import ( convert_to_ascii, flatten, - import_subs, list_media_files, remote_dir, remove_dir, diff --git a/core/utils/subtitles.py b/core/plugins/subtitles.py similarity index 100% rename from core/utils/subtitles.py rename to core/plugins/subtitles.py diff --git a/core/user_scripts.py b/core/user_scripts.py index 83f17d60..5d447670 100644 --- a/core/user_scripts.py +++ b/core/user_scripts.py @@ -5,7 +5,8 @@ from subprocess import Popen import core from core import logger, transcoder -from core.utils import import_subs, list_media_files, remove_dir +from core.plugins.subtitles import import_subs +from core.utils import list_media_files, remove_dir def external_script(output_destination, torrent_name, torrent_label, settings): diff --git a/core/utils/__init__.py b/core/utils/__init__.py index 88b9692f..470fe4fd 100644 --- a/core/utils/__init__.py +++ b/core/utils/__init__.py @@ -42,7 +42,6 @@ from core.utils.paths import ( remove_read_only, ) from core.utils.processes import RunningProcess, restart -from core.utils.subtitles import import_subs requests.packages.urllib3.disable_warnings() shutil_custom.monkey_patch()