-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdefault.py
66 lines (57 loc) · 2.21 KB
/
default.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: utf-8 -*-
# We need this in order to use add-on paths like
# 'plugin://plugin.video.plexkodiconnect.MOVIES' in the Kodi video database
###############################################################################
from __future__ import absolute_import, division, unicode_literals
from logging import getLogger
import sys
import os
import xbmc
import xbmcgui
import xbmcplugin
import xbmcaddon
# Import from the main pkc add-on
__addon__ = xbmcaddon.Addon(id='plugin.video.plexkodiconnect')
__temp_path__ = os.path.join(__addon__.getAddonInfo('path').decode('utf-8'), 'resources', 'lib')
__base__ = xbmc.translatePath(__temp_path__.encode('utf-8')).decode('utf-8')
sys.path.append(__base__)
import transfer, loghandler
from tools import unicode_paths
###############################################################################
loghandler.config()
LOG = getLogger('PLEX.TVSHOWS')
###############################################################################
HANDLE = int(sys.argv[1])
def play():
"""
Start up playback_starter in main Python thread
"""
LOG.debug('Full sys.sys.argv received: %s', sys.argv)
# Put the request into the 'queue'
if not sys.argv[2]:
# Browsing to a tv show from a tv show info dialog - picked up
# by kodimonitor.py and its method OnAdd
xbmcplugin.setResolvedUrl(HANDLE, False, xbmcgui.ListItem())
return
else:
request = '%s&handle=%s' % (unicode_paths.decode(sys.argv[2]), HANDLE)
if b'resume:true' in sys.argv:
request += '&resume=1'
elif b'resume:false' in sys.argv:
request += '&resume=0'
transfer.plex_command('PLAY-%s' % request)
if HANDLE == -1:
# Handle -1 received, not waiting for main thread
return
# Wait for the result
result = transfer.wait_for_transfer(source='main')
if result is True:
xbmcplugin.setResolvedUrl(HANDLE, False, xbmcgui.ListItem())
# Tell main thread that we're done
transfer.send(True, target='main')
else:
xbmcplugin.setResolvedUrl(HANDLE, True, result)
if __name__ == '__main__':
LOG.info('PKC add-on for tv shows started')
play()
LOG.info('PKC add-on for tv shows stopped')