2018-07-13 02:46:02 +10:00
|
|
|
#!/usr/bin/env python
|
2017-01-03 00:07:24 +11:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-07-13 02:46:02 +10:00
|
|
|
from __future__ import absolute_import, division, unicode_literals
|
2017-12-10 00:35:08 +11:00
|
|
|
from logging import getLogger
|
2017-01-03 00:07:24 +11:00
|
|
|
|
2019-03-30 20:32:56 +11:00
|
|
|
from . import utils, playback, context_entry, transfer, backgroundthread
|
2017-01-03 00:07:24 +11:00
|
|
|
|
|
|
|
###############################################################################
|
2018-01-07 01:19:12 +11:00
|
|
|
|
2018-06-22 03:24:37 +10:00
|
|
|
LOG = getLogger('PLEX.playback_starter')
|
2017-01-03 00:07:24 +11:00
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
|
2018-11-26 17:48:45 +11:00
|
|
|
class PlaybackTask(backgroundthread.Task):
|
2017-01-03 00:07:24 +11:00
|
|
|
"""
|
|
|
|
Processes new plays
|
|
|
|
"""
|
2018-11-26 17:48:45 +11: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 23:11:18 +10: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')
|
2019-01-26 18:43:51 +11:00
|
|
|
transfer.send(True)
|
2019-05-30 22:24:18 +10:00
|
|
|
# Wait for default.py to have completed xbmcplugin.setResolvedUrl()
|
|
|
|
transfer.wait_for_transfer(source='default')
|
2018-05-04 23:11:18 +10:00
|
|
|
return
|
2019-03-30 20:32:56 +11:00
|
|
|
params = dict(utils.parse_qsl(params))
|
2017-03-14 07:39:07 +11:00
|
|
|
mode = params.get('mode')
|
2018-04-16 02:13:48 +10:00
|
|
|
resolve = False if params.get('handle') == '-1' else True
|
2018-01-07 01:19:12 +11:00
|
|
|
LOG.debug('Received mode: %s, params: %s', mode, params)
|
2018-01-11 06:14:05 +11:00
|
|
|
if mode == 'play':
|
2019-10-26 02:06:50 +11:00
|
|
|
if params.get('resume'):
|
|
|
|
resume = params.get('resume') == '1'
|
|
|
|
else:
|
|
|
|
resume = None
|
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'),
|
2019-10-26 02:06:50 +11:00
|
|
|
resolve=resolve,
|
|
|
|
resume=resume)
|
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)
|
2018-01-11 06:14:05 +11:00
|
|
|
elif mode == 'context_menu':
|
2018-06-22 03:24:37 +10:00
|
|
|
context_entry.ContextMenu(kodi_id=params.get('kodi_id'),
|
|
|
|
kodi_type=params.get('kodi_type'))
|
2018-11-26 17:48:45 +11:00
|
|
|
LOG.debug('Finished PlaybackTask')
|