2017-05-17 18:09:50 +10:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
###############################################################################
|
|
|
|
import logging
|
|
|
|
from threading import Thread
|
|
|
|
|
|
|
|
from xbmc import sleep
|
|
|
|
|
2017-05-17 21:55:24 +10:00
|
|
|
from utils import window, thread_methods
|
2017-05-17 18:09:50 +10:00
|
|
|
import state
|
|
|
|
|
|
|
|
###############################################################################
|
2018-01-07 01:19:12 +11:00
|
|
|
LOG = logging.getLogger("PLEX." + __name__)
|
2017-05-17 18:09:50 +10:00
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
2017-05-17 21:55:24 +10:00
|
|
|
@thread_methods
|
2017-05-17 18:09:50 +10:00
|
|
|
class Monitor_Window(Thread):
|
|
|
|
"""
|
|
|
|
Monitors window('plex_command') for new entries that we need to take care
|
|
|
|
of, e.g. for new plays initiated on the Kodi side with addon paths.
|
|
|
|
|
|
|
|
Adjusts state.py accordingly
|
|
|
|
"""
|
|
|
|
def run(self):
|
2018-02-12 00:57:39 +11:00
|
|
|
stopped = self.stopped
|
2018-01-07 01:19:12 +11:00
|
|
|
queue = state.COMMAND_PIPELINE_QUEUE
|
|
|
|
LOG.info("----===## Starting Kodi_Play_Client ##===----")
|
2018-02-12 00:57:39 +11:00
|
|
|
while not stopped():
|
2017-05-17 18:09:50 +10:00
|
|
|
if window('plex_command'):
|
|
|
|
value = window('plex_command')
|
|
|
|
window('plex_command', clear=True)
|
2017-08-22 02:59:47 +10:00
|
|
|
if value.startswith('PLAY-'):
|
|
|
|
queue.put(value.replace('PLAY-', ''))
|
2017-05-17 18:09:50 +10:00
|
|
|
elif value == 'SUSPEND_LIBRARY_THREAD-True':
|
|
|
|
state.SUSPEND_LIBRARY_THREAD = True
|
|
|
|
elif value == 'SUSPEND_LIBRARY_THREAD-False':
|
|
|
|
state.SUSPEND_LIBRARY_THREAD = False
|
|
|
|
elif value == 'STOP_SYNC-True':
|
|
|
|
state.STOP_SYNC = True
|
|
|
|
elif value == 'STOP_SYNC-False':
|
|
|
|
state.STOP_SYNC = False
|
|
|
|
elif value == 'PMS_STATUS-Auth':
|
|
|
|
state.PMS_STATUS = 'Auth'
|
|
|
|
elif value == 'PMS_STATUS-401':
|
|
|
|
state.PMS_STATUS = '401'
|
|
|
|
elif value == 'SUSPEND_USER_CLIENT-True':
|
|
|
|
state.SUSPEND_USER_CLIENT = True
|
|
|
|
elif value == 'SUSPEND_USER_CLIENT-False':
|
|
|
|
state.SUSPEND_USER_CLIENT = False
|
|
|
|
elif value.startswith('PLEX_TOKEN-'):
|
|
|
|
state.PLEX_TOKEN = value.replace('PLEX_TOKEN-', '') or None
|
2017-05-18 00:14:17 +10:00
|
|
|
elif value.startswith('PLEX_USERNAME-'):
|
|
|
|
state.PLEX_USERNAME = \
|
|
|
|
value.replace('PLEX_USERNAME-', '') or None
|
2017-08-22 02:53:38 +10:00
|
|
|
elif value.startswith('RUN_LIB_SCAN-'):
|
|
|
|
state.RUN_LIB_SCAN = value.replace('RUN_LIB_SCAN-', '')
|
2017-09-10 23:09:32 +10:00
|
|
|
elif value == 'CONTEXT_menu':
|
|
|
|
queue.put('dummy?mode=context_menu')
|
2017-05-18 00:14:17 +10:00
|
|
|
else:
|
|
|
|
raise NotImplementedError('%s not implemented' % value)
|
2017-05-17 18:09:50 +10:00
|
|
|
else:
|
|
|
|
sleep(50)
|
|
|
|
# Put one last item into the queue to let playback_starter end
|
|
|
|
queue.put(None)
|
2018-01-07 01:19:12 +11:00
|
|
|
LOG.info("----===## Kodi_Play_Client stopped ##===----")
|