2018-07-12 18:46:02 +02:00
|
|
|
#!/usr/bin/env python
|
2017-01-02 14:07:24 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-07-12 18:46:02 +02:00
|
|
|
from __future__ import absolute_import, division, unicode_literals
|
2017-12-09 14:35:08 +01:00
|
|
|
from logging import getLogger
|
2017-01-02 14:07:24 +01:00
|
|
|
from urlparse import parse_qsl
|
|
|
|
|
2018-11-08 21:22:16 +01:00
|
|
|
from .kodi_db import KodiVideoDB
|
2018-06-21 19:24:37 +02:00
|
|
|
from . import playback
|
|
|
|
from . import context_entry
|
|
|
|
from . import json_rpc as js
|
|
|
|
from . import pickler
|
2018-11-26 07:48:45 +01:00
|
|
|
from . import backgroundthread
|
2017-01-02 14:07:24 +01:00
|
|
|
|
|
|
|
###############################################################################
|
2018-01-06 15:19:12 +01:00
|
|
|
|
2018-06-21 19:24:37 +02:00
|
|
|
LOG = getLogger('PLEX.playback_starter')
|
2017-01-02 14:07:24 +01:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
2018-11-26 07:48:45 +01:00
|
|
|
class PlaybackTask(backgroundthread.Task):
|
2017-01-02 14:07:24 +01:00
|
|
|
"""
|
|
|
|
Processes new plays
|
|
|
|
"""
|
2018-11-26 07:48:45 +01:00
|
|
|
def __init__(self, command):
|
|
|
|
self.command = command
|
|
|
|
super(PlaybackTask, self).__init__()
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
LOG.debug('Starting PlaybackTask with %s', self.command)
|
|
|
|
item = self.command
|
2018-05-04 15:11:18 +02:00
|
|
|
try:
|
|
|
|
_, params = item.split('?', 1)
|
|
|
|
except ValueError:
|
|
|
|
# E.g. other add-ons scanning for Extras folder
|
|
|
|
LOG.debug('Detected 3rd party add-on call - ignoring')
|
2018-06-21 19:24:37 +02:00
|
|
|
pickler.pickle_me(pickler.Playback_Successful())
|
2018-05-04 15:11:18 +02:00
|
|
|
return
|
2017-01-02 14:07:24 +01:00
|
|
|
params = dict(parse_qsl(params))
|
2017-03-13 21:39:07 +01:00
|
|
|
mode = params.get('mode')
|
2018-04-15 18:13:48 +02:00
|
|
|
resolve = False if params.get('handle') == '-1' else True
|
2018-01-06 15:19:12 +01:00
|
|
|
LOG.debug('Received mode: %s, params: %s', mode, params)
|
2018-01-10 20:14:05 +01:00
|
|
|
if mode == 'play':
|
2018-01-28 17:21:28 +01:00
|
|
|
playback.playback_triage(plex_id=params.get('plex_id'),
|
|
|
|
plex_type=params.get('plex_type'),
|
2018-04-15 18:13:48 +02:00
|
|
|
path=params.get('path'),
|
|
|
|
resolve=resolve)
|
2018-01-10 20:14:05 +01:00
|
|
|
elif mode == 'plex_node':
|
2018-04-15 18:13:48 +02:00
|
|
|
playback.process_indirect(params['key'],
|
|
|
|
params['offset'],
|
|
|
|
resolve=resolve)
|
|
|
|
elif mode == 'navigation':
|
|
|
|
# e.g. when plugin://...tvshows is called for entire season
|
2018-11-08 21:22:16 +01:00
|
|
|
with KodiVideoDB() as kodidb:
|
|
|
|
show_id = kodidb.show_id_from_path(params.get('path'))
|
2018-04-15 18:13:48 +02:00
|
|
|
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:
|
2018-06-21 19:24:37 +02:00
|
|
|
pickler.pickle_me(pickler.Playback_Successful())
|
2018-01-10 20:14:05 +01:00
|
|
|
elif mode == 'context_menu':
|
2018-06-21 19:24:37 +02:00
|
|
|
context_entry.ContextMenu(kodi_id=params.get('kodi_id'),
|
|
|
|
kodi_type=params.get('kodi_type'))
|
2018-11-26 07:48:45 +01:00
|
|
|
LOG.debug('Finished PlaybackTask')
|