forked from croneter/PlexKodiConnect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.py
179 lines (150 loc) · 6.1 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# -*- coding: utf-8 -*-
###############################################################################
import logging
import os
import sys
import urlparse
import xbmc
import xbmcaddon
import xbmcgui
_addon = xbmcaddon.Addon(id='plugin.video.plexkodiconnect')
try:
_addon_path = _addon.getAddonInfo('path').decode('utf-8')
except TypeError:
_addon_path = _addon.getAddonInfo('path').decode()
try:
_base_resource = xbmc.translatePath(os.path.join(
_addon_path,
'resources',
'lib')).decode('utf-8')
except TypeError:
_base_resource = xbmc.translatePath(os.path.join(
_addon_path,
'resources',
'lib')).decode()
sys.path.append(_base_resource)
###############################################################################
import entrypoint
import utils
###############################################################################
import loghandler
loghandler.config()
log = logging.getLogger("PLEX.default")
###############################################################################
class Main():
# MAIN ENTRY POINT
#@utils.profiling()
def __init__(self):
# Parse parameters
log.warn("Full sys.argv received: %s" % sys.argv)
base_url = sys.argv[0]
params = urlparse.parse_qs(sys.argv[2][1:])
try:
mode = params['mode'][0]
itemid = params.get('id', '')
if itemid:
try:
itemid = itemid[0]
except:
pass
except:
params = {}
mode = ""
modes = {
'reset': utils.reset,
'resetauth': entrypoint.resetAuth,
'play': entrypoint.doPlayback,
'passwords': utils.passwordsXML,
'channels': entrypoint.BrowseChannels,
'channelsfolder': entrypoint.BrowseChannels,
'browsecontent': entrypoint.BrowseContent,
'getsubfolders': entrypoint.GetSubFolders,
'nextup': entrypoint.getNextUpEpisodes,
'inprogressepisodes': entrypoint.getInProgressEpisodes,
'recentepisodes': entrypoint.getRecentEpisodes,
'refreshplaylist': entrypoint.refreshPlaylist,
'companion': entrypoint.plexCompanion,
'switchuser': entrypoint.switchPlexUser,
'deviceid': entrypoint.resetDeviceId,
'delete': entrypoint.deleteItem,
'browseplex': entrypoint.BrowsePlexContent,
'ondeck': entrypoint.getOnDeck,
'chooseServer': entrypoint.chooseServer,
'watchlater': entrypoint.watchlater,
'enterPMS': entrypoint.enterPMS,
'togglePlexTV': entrypoint.togglePlexTV,
'playwatchlater': entrypoint.playWatchLater
}
if "/extrafanart" in sys.argv[0]:
plexpath = sys.argv[2][1:]
plexid = params.get('id', [""])[0]
entrypoint.getExtraFanArt(plexid, plexpath)
entrypoint.getVideoFiles(plexid, plexpath)
return
# Called by e.g. 3rd party plugin video extras
if ("/Extras" in sys.argv[0] or "/VideoFiles" in sys.argv[0] or
"/Extras" in sys.argv[2]):
plexId = params.get('id', [None])[0]
entrypoint.getVideoFiles(plexId, params)
if modes.get(mode):
# Simple functions
if mode == "play":
dbid = params.get('dbid')
# modes[mode](itemid, dbid)
modes[mode](itemid, dbid)
elif mode in ("nextup", "inprogressepisodes"):
limit = int(params['limit'][0])
modes[mode](itemid, limit)
elif mode in ("channels","getsubfolders"):
modes[mode](itemid)
elif mode == "browsecontent":
modes[mode](itemid, params.get('type',[""])[0], params.get('folderid',[""])[0])
elif mode == 'browseplex':
modes[mode](
itemid,
params.get('type', [""])[0],
params.get('folderid', [""])[0])
elif mode in ('ondeck', 'recentepisodes'):
modes[mode](
itemid,
params.get('type', [""])[0],
params.get('tagname', [""])[0],
int(params.get('limit', [""])[0]))
elif mode == "channelsfolder":
folderid = params['folderid'][0]
modes[mode](itemid, folderid)
elif mode == "companion":
modes[mode](itemid, params=sys.argv[2])
elif mode == 'playwatchlater':
modes[mode](params.get('id')[0], params.get('viewOffset')[0])
else:
modes[mode]()
else:
# Other functions
if mode == "settings":
xbmc.executebuiltin('Addon.OpenSettings(plugin.video.plexkodiconnect)')
elif mode in ("manualsync", "repair"):
if utils.window('plex_online') != "true":
# Server is not online, do not run the sync
xbmcgui.Dialog().ok(
"PlexKodiConnect",
"Unable to run the sync, the add-on is not connected "
"to a Plex server.")
log.error("Not connected to a PMS.")
return
else:
if mode == 'repair':
utils.window('plex_runLibScan', value="repair")
log.warn("Requesting repair lib sync")
elif mode == 'manualsync':
log.warn("Requesting full library scan")
utils.window('plex_runLibScan', value="full")
elif mode == "texturecache":
import artwork
artwork.Artwork().fullTextureCacheSync()
else:
entrypoint.doMainListing()
if __name__ == "__main__":
log.info('plugin.video.plexkodiconnect started')
Main()
log.info('plugin.video.plexkodiconnect stopped')