From 599bfbe7f5985dbc5d65bb76cdcb0a3cb9abc142 Mon Sep 17 00:00:00 2001 From: ReenigneArcher <42013603+ReenigneArcher@users.noreply.github.com> Date: Sat, 15 Oct 2022 11:32:38 -0400 Subject: [PATCH] improve plexapi timeout changing timeout will no longer require a Plex Media Server restart --- CHANGELOG.md | 4 ++++ Contents/Code/__init__.py | 31 ++++++------------------------- Contents/Code/plex_api_helper.py | 5 +++-- Contents/DefaultPrefs.json | 2 +- docs/source/about/usage.rst | 3 +++ 5 files changed, 17 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 86f2a4a1..ddeb7b8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [0.0.5] - 2022-10-15 +### Fixed +- changing timeout no longer requires a Plex Media Server restart + ## [0.0.4] - 2022-10-14 ### Fixed - issue with timeout not being respected diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index 5dcb79df..409d50ac 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- # standard imports -import os import re import sys @@ -31,8 +30,10 @@ # local imports if sys.version_info.major < 3: from default_prefs import default_prefs + from plex_api_helper import add_themes else: from .default_prefs import default_prefs + from .plex_api_helper import add_themes def process_youtube(url): @@ -89,26 +90,6 @@ def process_youtube(url): return audio_url # return None or url found -def set_environment(key, value): - # type: (str, str) -> None - """ - Set an environment variable key to a specified value. - - Parameters - ---------- - key : str - The variable name. - value : str - The variable value. - - Examples - -------- - >>> set_environment(key='plexapi_plexapi_timeout', value='180') - ... - """ - os.environ[key.upper()] = value - - def ValidatePrefs(): # type: () -> MessageContainer """ @@ -153,9 +134,10 @@ def ValidatePrefs(): Log.Error("Setting '%s' must be True or False; Value '%s'" % (key, Prefs[key])) error_message += "Setting '%s' must be True or False; Value '%s'
" % (key, Prefs[key]) - plexapi_key = key.split('_', 1)[-1] - if plexapi_key.startswith('plexapi_'): - set_environment(key=plexapi_key, value=Prefs[key]) + # special cases + if key == 'int_plexapi_plexapi_timeout' and int(Prefs[key]) <= 0: + Log.Error("Setting '%s' must be greater than 0; Value '%s'" % (key, Prefs[key])) + error_message += "Setting '%s' must be greater than 0; Value '%s'
" % (key, Prefs[key]) if error_message != '': return MessageContainer(header='Error', message=error_message) @@ -376,7 +358,6 @@ def update(metadata, media, lang, force): theme_url = process_youtube(url=yt_video_url) if theme_url: - from plex_api_helper import add_themes # import here to allow environment variable to be fully setup add_themes(rating_key=rating_key, theme_urls=[theme_url]) return metadata diff --git a/Contents/Code/plex_api_helper.py b/Contents/Code/plex_api_helper.py index b6161f5d..4d552469 100644 --- a/Contents/Code/plex_api_helper.py +++ b/Contents/Code/plex_api_helper.py @@ -13,7 +13,7 @@ import requests from typing import Optional import urllib3 -from plexapi.server import PlexServer +import plexapi.server def setup_plexapi(): @@ -47,7 +47,8 @@ def setup_plexapi(): urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # Disable the insecure request warning # create the plex server object - plex = PlexServer(baseurl=plex_url, token=plex_token, session=sess) + plexapi.server.TIMEOUT = int(Prefs['int_plexapi_plexapi_timeout']) + plex = plexapi.server.PlexServer(baseurl=plex_url, token=plex_token, session=sess) return plex diff --git a/Contents/DefaultPrefs.json b/Contents/DefaultPrefs.json index eef11a78..214683f0 100644 --- a/Contents/DefaultPrefs.json +++ b/Contents/DefaultPrefs.json @@ -2,7 +2,7 @@ { "id": "int_plexapi_plexapi_timeout", "type": "text", - "label": "PlexAPI Timeout, in seconds (requires a Plex Media Server restart)", + "label": "PlexAPI Timeout, in seconds (min: 1)", "default": "180", "secure": "false" }, diff --git a/docs/source/about/usage.rst b/docs/source/about/usage.rst index 87e2c9a8..923f3fe0 100644 --- a/docs/source/about/usage.rst +++ b/docs/source/about/usage.rst @@ -29,6 +29,9 @@ Description Default ``180`` +Minimum + ``1`` + YouTube Username ^^^^^^^^^^^^^^^^