PlexKodiConnect/resources/lib/playback_starter.py

68 lines
2.5 KiB
Python
Raw Normal View History

2017-01-03 00:07:24 +11:00
# -*- coding: utf-8 -*-
###############################################################################
2017-12-10 00:35:08 +11:00
from logging import getLogger
2017-01-03 00:07:24 +11:00
from threading import Thread
from urlparse import parse_qsl
2018-01-11 06:14:05 +11:00
import playback
from context_entry import ContextMenu
import state
import json_rpc as js
from pickler import pickle_me, Playback_Successful
import kodidb_functions as kodidb
2017-01-03 00:07:24 +11:00
###############################################################################
LOG = getLogger("PLEX." + __name__)
2017-01-03 00:07:24 +11:00
###############################################################################
2018-04-16 00:34:45 +10:00
class PlaybackStarter(Thread):
2017-01-03 00:07:24 +11:00
"""
Processes new plays
"""
2018-04-16 00:34:45 +10:00
@staticmethod
def _triage(item):
2018-04-16 02:13:48 +10:00
_, params = item.split('?', 1)
2017-01-03 00:07:24 +11:00
params = dict(parse_qsl(params))
mode = params.get('mode')
2018-04-16 02:13:48 +10:00
resolve = False if params.get('handle') == '-1' else True
LOG.debug('Received mode: %s, params: %s', mode, params)
2018-01-11 06:14:05 +11:00
if mode == 'play':
2018-01-29 03:21:28 +11:00
playback.playback_triage(plex_id=params.get('plex_id'),
plex_type=params.get('plex_type'),
2018-04-16 02:13:48 +10:00
path=params.get('path'),
resolve=resolve)
2018-01-11 06:14:05 +11:00
elif mode == 'plex_node':
2018-04-16 02:13:48 +10:00
playback.process_indirect(params['key'],
params['offset'],
resolve=resolve)
elif mode == 'navigation':
# e.g. when plugin://...tvshows is called for entire season
with kodidb.GetKodiDB('video') as kodi_db:
show_id = kodi_db.show_id_from_path(params.get('path'))
if show_id:
js.activate_window('videos',
'videodb://tvshows/titles/%s' % show_id)
else:
LOG.error('Could not find tv show id for %s', item)
if resolve:
pickle_me(Playback_Successful())
2018-01-11 06:14:05 +11:00
elif mode == 'context_menu':
ContextMenu(kodi_id=params.get('kodi_id'),
kodi_type=params.get('kodi_type'))
2018-02-23 04:20:42 +11:00
2017-01-03 00:07:24 +11:00
def run(self):
queue = state.COMMAND_PIPELINE_QUEUE
2018-04-16 00:37:13 +10:00
LOG.info("----===## Starting PlaybackStarter ##===----")
2017-01-03 00:07:24 +11:00
while True:
item = queue.get()
if item is None:
# Need to shutdown - initiated by command_pipeline
2017-01-03 00:07:24 +11:00
break
else:
2018-04-16 00:34:45 +10:00
self._triage(item)
2017-01-03 00:07:24 +11:00
queue.task_done()
2018-04-16 00:37:13 +10:00
LOG.info("----===## PlaybackStarter stopped ##===----")