Move playback startup from thread to task
This commit is contained in:
parent
030c381f65
commit
fada7f707f
3 changed files with 16 additions and 29 deletions
|
@ -32,8 +32,6 @@ class App(object):
|
||||||
|
|
||||||
# Plex Companion Queue()
|
# Plex Companion Queue()
|
||||||
self.companion_queue = Queue.Queue(maxsize=100)
|
self.companion_queue = Queue.Queue(maxsize=100)
|
||||||
# Command Pipeline Queue()
|
|
||||||
self.command_pipeline_queue = Queue.Queue()
|
|
||||||
# Websocket_client queue to communicate with librarysync
|
# Websocket_client queue to communicate with librarysync
|
||||||
self.websocket_queue = Queue.Queue()
|
self.websocket_queue = Queue.Queue()
|
||||||
# xbmc.Monitor() instance from kodimonitor.py
|
# xbmc.Monitor() instance from kodimonitor.py
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import absolute_import, division, unicode_literals
|
from __future__ import absolute_import, division, unicode_literals
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from threading import Thread
|
|
||||||
from urlparse import parse_qsl
|
from urlparse import parse_qsl
|
||||||
|
|
||||||
from .kodi_db import KodiVideoDB
|
from .kodi_db import KodiVideoDB
|
||||||
|
@ -10,7 +9,7 @@ from . import playback
|
||||||
from . import context_entry
|
from . import context_entry
|
||||||
from . import json_rpc as js
|
from . import json_rpc as js
|
||||||
from . import pickler
|
from . import pickler
|
||||||
from . import app
|
from . import backgroundthread
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
@ -19,12 +18,17 @@ LOG = getLogger('PLEX.playback_starter')
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
|
|
||||||
class PlaybackStarter(Thread):
|
class PlaybackTask(backgroundthread.Task):
|
||||||
"""
|
"""
|
||||||
Processes new plays
|
Processes new plays
|
||||||
"""
|
"""
|
||||||
@staticmethod
|
def __init__(self, command):
|
||||||
def _triage(item):
|
self.command = command
|
||||||
|
super(PlaybackTask, self).__init__()
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
LOG.debug('Starting PlaybackTask with %s', self.command)
|
||||||
|
item = self.command
|
||||||
try:
|
try:
|
||||||
_, params = item.split('?', 1)
|
_, params = item.split('?', 1)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -59,16 +63,4 @@ class PlaybackStarter(Thread):
|
||||||
elif mode == 'context_menu':
|
elif mode == 'context_menu':
|
||||||
context_entry.ContextMenu(kodi_id=params.get('kodi_id'),
|
context_entry.ContextMenu(kodi_id=params.get('kodi_id'),
|
||||||
kodi_type=params.get('kodi_type'))
|
kodi_type=params.get('kodi_type'))
|
||||||
|
LOG.debug('Finished PlaybackTask')
|
||||||
def run(self):
|
|
||||||
queue = app.APP.command_pipeline_queue
|
|
||||||
LOG.info("----===## Starting PlaybackStarter ##===----")
|
|
||||||
while True:
|
|
||||||
item = queue.get()
|
|
||||||
if item is None:
|
|
||||||
# Need to shutdown - initiated by command_pipeline
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
self._triage(item)
|
|
||||||
queue.task_done()
|
|
||||||
LOG.info("----===## PlaybackStarter stopped ##===----")
|
|
||||||
|
|
|
@ -341,7 +341,6 @@ class Service():
|
||||||
self.alexa = websocket_client.Alexa_Websocket()
|
self.alexa = websocket_client.Alexa_Websocket()
|
||||||
self.sync = sync.Sync()
|
self.sync = sync.Sync()
|
||||||
self.plexcompanion = plex_companion.PlexCompanion()
|
self.plexcompanion = plex_companion.PlexCompanion()
|
||||||
self.playback_starter = playback_starter.PlaybackStarter()
|
|
||||||
self.playqueue = playqueue.PlayqueueMonitor()
|
self.playqueue = playqueue.PlayqueueMonitor()
|
||||||
|
|
||||||
# Main PKC program loop
|
# Main PKC program loop
|
||||||
|
@ -360,33 +359,30 @@ class Service():
|
||||||
# Commands/user interaction received from other PKC Python
|
# Commands/user interaction received from other PKC Python
|
||||||
# instances (default.py and context.py instead of service.py)
|
# instances (default.py and context.py instead of service.py)
|
||||||
utils.window('plex_command', clear=True)
|
utils.window('plex_command', clear=True)
|
||||||
|
task = None
|
||||||
if plex_command.startswith('PLAY-'):
|
if plex_command.startswith('PLAY-'):
|
||||||
# Add-on path playback!
|
# Add-on path playback!
|
||||||
app.APP.command_pipeline_queue.put(
|
task = playback_starter.PlaybackTask(
|
||||||
plex_command.replace('PLAY-', ''))
|
plex_command.replace('PLAY-', ''))
|
||||||
elif plex_command.startswith('NAVIGATE-'):
|
elif plex_command.startswith('NAVIGATE-'):
|
||||||
app.APP.command_pipeline_queue.put(
|
task = playback_starter.PlaybackTask(
|
||||||
plex_command.replace('NAVIGATE-', ''))
|
plex_command.replace('NAVIGATE-', ''))
|
||||||
elif plex_command.startswith('CONTEXT_menu?'):
|
elif plex_command.startswith('CONTEXT_menu?'):
|
||||||
app.APP.command_pipeline_queue.put(
|
task = playback_starter.PlaybackTask(
|
||||||
'dummy?mode=context_menu&%s'
|
'dummy?mode=context_menu&%s'
|
||||||
% plex_command.replace('CONTEXT_menu?', ''))
|
% plex_command.replace('CONTEXT_menu?', ''))
|
||||||
elif plex_command == 'choose_pms_server':
|
elif plex_command == 'choose_pms_server':
|
||||||
task = backgroundthread.FunctionAsTask(
|
task = backgroundthread.FunctionAsTask(
|
||||||
self.choose_pms_server, None)
|
self.choose_pms_server, None)
|
||||||
backgroundthread.BGThreader.addTasksToFront([task])
|
|
||||||
elif plex_command == 'switch_plex_user':
|
elif plex_command == 'switch_plex_user':
|
||||||
task = backgroundthread.FunctionAsTask(
|
task = backgroundthread.FunctionAsTask(
|
||||||
self.switch_plex_user, None)
|
self.switch_plex_user, None)
|
||||||
backgroundthread.BGThreader.addTasksToFront([task])
|
|
||||||
elif plex_command == 'enter_new_pms_address':
|
elif plex_command == 'enter_new_pms_address':
|
||||||
task = backgroundthread.FunctionAsTask(
|
task = backgroundthread.FunctionAsTask(
|
||||||
self.enter_new_pms_address, None)
|
self.enter_new_pms_address, None)
|
||||||
backgroundthread.BGThreader.addTasksToFront([task])
|
|
||||||
elif plex_command == 'toggle_plex_tv_sign_in':
|
elif plex_command == 'toggle_plex_tv_sign_in':
|
||||||
task = backgroundthread.FunctionAsTask(
|
task = backgroundthread.FunctionAsTask(
|
||||||
self.toggle_plex_tv, None)
|
self.toggle_plex_tv, None)
|
||||||
backgroundthread.BGThreader.addTasksToFront([task])
|
|
||||||
elif plex_command == 'repair-scan':
|
elif plex_command == 'repair-scan':
|
||||||
app.SYNC.run_lib_scan = 'repair'
|
app.SYNC.run_lib_scan = 'repair'
|
||||||
elif plex_command == 'full-scan':
|
elif plex_command == 'full-scan':
|
||||||
|
@ -397,6 +393,8 @@ class Service():
|
||||||
app.SYNC.run_lib_scan = 'textures'
|
app.SYNC.run_lib_scan = 'textures'
|
||||||
elif plex_command == 'RESET-PKC':
|
elif plex_command == 'RESET-PKC':
|
||||||
utils.reset()
|
utils.reset()
|
||||||
|
if task:
|
||||||
|
backgroundthread.BGThreader.addTasksToFront([task])
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if app.APP.suspend:
|
if app.APP.suspend:
|
||||||
|
@ -446,7 +444,6 @@ class Service():
|
||||||
self.ws.start()
|
self.ws.start()
|
||||||
self.sync.start()
|
self.sync.start()
|
||||||
self.plexcompanion.start()
|
self.plexcompanion.start()
|
||||||
self.playback_starter.start()
|
|
||||||
self.playqueue.start()
|
self.playqueue.start()
|
||||||
if utils.settings('enable_alexa') == 'true':
|
if utils.settings('enable_alexa') == 'true':
|
||||||
self.alexa.start()
|
self.alexa.start()
|
||||||
|
|
Loading…
Reference in a new issue