Improve terminate stream error messages

This commit is contained in:
JonnyWong16 2019-03-18 11:57:08 -07:00
parent 00405f0b18
commit 76b9b3e474
3 changed files with 33 additions and 11 deletions

View file

@ -842,9 +842,13 @@ class PlexTV(object):
return False return False
if subscription and helpers.get_xml_attr(subscription[0], 'active') == '1': if subscription and helpers.get_xml_attr(subscription[0], 'active') == '1':
plexpy.CONFIG.__setattr__('PMS_PLEXPASS', 1)
plexpy.CONFIG.write()
return True return True
else: else:
logger.debug(u"Tautulli PlexTV :: Plex Pass subscription not found.") logger.debug(u"Tautulli PlexTV :: Plex Pass subscription not found.")
plexpy.CONFIG.__setattr__('PMS_PLEXPASS', 0)
plexpy.CONFIG.write()
return False return False
def get_devices_list(self): def get_devices_list(self):

View file

@ -101,7 +101,7 @@ class PmsConnect(object):
Output: array Output: array
""" """
uri = '/status/sessions/terminate?sessionId=%s&reason=%s' % (session_id, reason) uri = '/status/sessions/terminate?sessionId=%s&reason=%s' % (session_id, urllib.quote_plus(reason))
request = self.request_handler.make_request(uri=uri, request = self.request_handler.make_request(uri=uri,
request_type='GET', request_type='GET',
output_format=output_format) output_format=output_format)
@ -2018,25 +2018,41 @@ class PmsConnect(object):
Output: bool Output: bool
""" """
message = message.encode('utf-8') or 'The server owner has ended the stream.' plex_tv = plextv.PlexTV()
if not plex_tv.get_plexpass_status():
msg = 'No Plex Pass subscription'
logger.warn(u"Tautulli Pmsconnect :: Failed to terminate session: %s." % msg)
return msg
if session_key and not session_id: message = message.encode('utf-8') or 'The server owner has ended the stream.'
session = None
if not session_key and not session_id:
session_key = session_id = None
elif session_key and not session_id:
ap = activity_processor.ActivityProcessor() ap = activity_processor.ActivityProcessor()
session = ap.get_session_by_key(session_key=session_key) session = ap.get_session_by_key(session_key=session_key)
session_id = session['session_id'] session_id = session['session_id'] if session else None
elif session_id and not session_key: elif session_id and not session_key:
ap = activity_processor.ActivityProcessor() ap = activity_processor.ActivityProcessor()
session = ap.get_session_by_id(session_id=session_id) session = ap.get_session_by_id(session_id=session_id)
session_key = session['session_key'] session_key = session['session_key'] if session else None
if not session:
msg = 'Invalid session_key (%s) or session_id (%s)' % (session_key, session_id)
logger.warn(u"Tautulli Pmsconnect :: Failed to terminate session: %s." % msg)
return msg
if session_id: if session_id:
logger.info(u"Tautulli Pmsconnect :: Terminating session %s (session_id %s)." % (session_key, session_id)) logger.info(u"Tautulli Pmsconnect :: Terminating session %s (session_id %s)." % (session_key, session_id))
result = self.get_sessions_terminate(session_id=session_id, reason=urllib.quote_plus(message)) result = self.get_sessions_terminate(session_id=session_id, reason=message)
return result return True
else: else:
logger.warn(u"Tautulli Pmsconnect :: Failed to terminate session %s. Missing session_id." % session_key) msg = 'Missing session_id'
return False logger.warn(u"Tautulli Pmsconnect :: Failed to terminate session: %s." % msg)
return msg
def get_item_children(self, rating_key='', get_grandchildren=False): def get_item_children(self, rating_key='', get_grandchildren=False):
""" """

View file

@ -246,7 +246,7 @@ class WebInterface(object):
@cherrypy.tools.json_out() @cherrypy.tools.json_out()
@requireAuth(member_of("admin")) @requireAuth(member_of("admin"))
@addtoapi() @addtoapi()
def terminate_session(self, session_key=None, session_id=None, message=None, **kwargs): def terminate_session(self, session_key='', session_id='', message='', **kwargs):
""" Stop a streaming session. """ Stop a streaming session.
``` ```
@ -264,8 +264,10 @@ class WebInterface(object):
pms_connect = pmsconnect.PmsConnect() pms_connect = pmsconnect.PmsConnect()
result = pms_connect.terminate_session(session_key=session_key, session_id=session_id, message=message) result = pms_connect.terminate_session(session_key=session_key, session_id=session_id, message=message)
if result: if result is True:
return {'result': 'success', 'message': 'Session terminated.'} return {'result': 'success', 'message': 'Session terminated.'}
elif result:
return {'result': 'error', 'message': 'Failed to terminate session: {}.'.format(result)}
else: else:
return {'result': 'error', 'message': 'Failed to terminate session.'} return {'result': 'error', 'message': 'Failed to terminate session.'}