From 76b5c06a33964d9cd7909413bcdb16398f60a4a8 Mon Sep 17 00:00:00 2001 From: Labrys of Knossos Date: Sun, 10 Mar 2019 11:15:31 -0400 Subject: [PATCH] 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') - -