-
Notifications
You must be signed in to change notification settings - Fork 123
/
plugin.py
75 lines (53 loc) · 1.87 KB
/
plugin.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
67
68
69
70
71
72
73
74
75
from __future__ import absolute_import
from kodi_six import xbmc
from kodi_six import xbmcplugin
from kodi_six import xbmcgui
import sys
import base64
from lib import _included_packages, plex, util
from plexnet import audio, plexplayer, plexapp
from plexnet import util as plexnetUtil
HANDLE = int(sys.argv[1])
BASE_LOG = util.LOG
def LOG(msg):
BASE_LOG('(plugin) - {0}'.format(plexnetUtil.cleanToken(msg)))
util.LOG = LOG
def playTrack(track):
track.reload()
apobj = plexplayer.PlexAudioPlayer(track)
url = apobj.build()['url']
url = util.addURLParams(url, {
'X-Plex-Client-Profile-Name': 'Chrome',
'X-Plex-Client-Identifier': plexapp.util.INTERFACE.getGlobal('clientIdentifier')
})
LOG('Playing URL: {0}'.format(url))
return xbmcgui.ListItem(path=url)
def playVideo(video):
return None
def play(data):
try:
from plexnet import plexobjects
plexObject = plexobjects.PlexObject.deSerialize(base64.urlsafe_b64decode(data))
if plexObject.type == 'track':
listitem = playTrack(plexObject)
elif plexObject.type in ('episode', 'movie', 'clip'):
listitem = playVideo(plexObject)
except:
util.ERROR()
xbmcplugin.setResolvedUrl(HANDLE, False, None)
return
xbmcplugin.setResolvedUrl(HANDLE, True, listitem)
def main():
try:
if len(sys.argv) < 3:
return
path = sys.argv[0].split('/', 3)[-1]
data = sys.argv[2].lstrip('?')
if path == 'play':
play(data)
else: # This is a hack since it's both a plugin and a script. My Addons and Shortcuts otherwise can't launch the add-on
xbmc.executebuiltin('Action(back)') # This sometimes works to back out of the plugin directory display
xbmc.executebuiltin('RunScript(script.plex)')
except:
util.ERROR()
main()