diff --git a/plexpy/helpers.py b/plexpy/helpers.py index 01759272..907078dc 100644 --- a/plexpy/helpers.py +++ b/plexpy/helpers.py @@ -933,3 +933,36 @@ def eval_logic_groups_to_bool(logic_groups, eval_conds): result = result or eval_cond return result + +def get_plexpy_url(hostname=None): + if plexpy.CONFIG.ENABLE_HTTPS: + scheme = 'https' + else: + scheme = 'http' + + if hostname is None and plexpy.CONFIG.HTTP_HOST == '0.0.0.0': + import socket + try: + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) + s.connect(('', 0)) + hostname = s.getsockname()[0] + except socket.error: + hostname = socket.gethostbyname(socket.gethostname()) + + if not hostname: + hostname = 'localhost' + else: + hostname = hostname or plexpy.CONFIG.HTTP_HOST + + if plexpy.CONFIG.HTTP_PORT not in (80, 443): + port = ':' + str(plexpy.CONFIG.HTTP_PORT) + else: + port = '' + + if plexpy.CONFIG.HTTP_ROOT.strip('/'): + root = '/' + plexpy.CONFIG.HTTP_ROOT.strip('/') + else: + root = '' + + return scheme + '://' + hostname + port + root \ No newline at end of file diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py index 503b42bb..05f01d79 100644 --- a/plexpy/notifiers.py +++ b/plexpy/notifiers.py @@ -2954,6 +2954,13 @@ class SCRIPTS(Notifier): process.kill() self.script_killed = True + # Common environment variables + env = {'PLEX_URL': plexpy.CONFIG.PMS_URL, + 'PLEX_TOKEN': plexpy.CONFIG.PMS_TOKEN, + 'TAUTULLI_URL': helpers.get_plexpy_url(hostname='localhost'), + 'TAUTULLI_APIKEY': plexpy.CONFIG.API_KEY + } + self.script_killed = False output = error = '' try: @@ -2961,7 +2968,8 @@ class SCRIPTS(Notifier): stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - cwd=self.config['script_folder']) + cwd=self.config['script_folder'], + env=env) if self.config['timeout'] > 0: timer = threading.Timer(self.config['timeout'], kill_script, (process,)) @@ -2969,11 +2977,13 @@ class SCRIPTS(Notifier): timer = None try: - if timer: timer.start() + if timer: + timer.start() output, error = process.communicate() status = process.returncode finally: - if timer: timer.cancel() + if timer: + timer.cancel() except OSError as e: logger.error(u"Tautulli Notifiers :: Failed to run script: %s" % e) diff --git a/plexpy/webserve.py b/plexpy/webserve.py index 85f63804..9fbe47c6 100644 --- a/plexpy/webserve.py +++ b/plexpy/webserve.py @@ -5284,34 +5284,4 @@ class WebInterface(object): @cherrypy.tools.json_out() @requireAuth() def get_plexpy_url(self, **kwargs): - if plexpy.CONFIG.ENABLE_HTTPS: - scheme = 'https' - else: - scheme = 'http' - - # Have to return some hostname if socket fails even if 127.0.0.1 won't work - hostname = '127.0.0.1' - - if plexpy.CONFIG.HTTP_HOST == '0.0.0.0': - import socket - try: - s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) - s.connect(('', 0)) - hostname = s.getsockname()[0] - except socket.error: - hostname = socket.gethostbyname(socket.gethostname()) - else: - hostname = plexpy.CONFIG.HTTP_HOST - - if plexpy.CONFIG.HTTP_PORT not in (80, 443): - port = ':' + str(plexpy.CONFIG.HTTP_PORT) - else: - port = '' - - if plexpy.CONFIG.HTTP_ROOT.strip('/'): - root = '/' + plexpy.CONFIG.HTTP_ROOT.strip('/') - else: - root = '' - - return scheme + '://' + hostname + port + root \ No newline at end of file + return helpers.get_plexpy_url()