Repository navigation
Expand file tree
/
Copy pathdefault.py
More file actions
263 lines (243 loc) · 9.17 KB
/
Copy pathdefault.py
File metadata and controls
263 lines (243 loc) · 9.17 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# -*- coding: utf-8 -*-
import logging
from sys import argv
from urllib.parse import parse_qsl, urlencode
import xbmc
import xbmcgui
import xbmcplugin
from resources.lib import utils, transfer, variables as v, watchlist, loghandler
loghandler.config()
LOG = logging.getLogger("PLEX.default")
WATCHLIST_ACTION_MODES = frozenset(
(
"watchlist_add_key",
"watchlist_remove_key",
"watchlist_add_tmdb",
"watchlist_remove_tmdb",
"watchlist_status_key",
"watchlist_status_tmdb",
"watchlist_status_monitor",
"watchlist_status_search",
"watchlist_add_search",
"watchlist_remove_search",
)
)
def _enqueue_watchlist_detail(command, request):
if request is not None:
transfer.plex_command("%s?%s" % (command, urlencode(request)))
def triage(mode, params, path, arguments, itemid):
if mode == "play":
play()
return
elif mode == "plex_node":
play()
return
elif mode == "route_to_extras":
# Hack so we can store this path in the Kodi DB
handle = "plugin://%s?mode=extras&plex_id=%s" % (
v.ADDON_ID,
params.get("plex_id"),
)
xbmc.executebuiltin('ActivateWindow(videos,"%s",return)' % handle)
return
elif mode == "settings":
xbmc.executebuiltin("Addon.OpenSettings(%s)" % v.ADDON_ID)
return
elif mode == "skip_marker":
transfer.plex_command("skip-marker")
return
elif mode == "enterPMS":
LOG.info("Request to manually enter new PMS address")
transfer.plex_command("enter_new_pms_address")
return
elif mode == "reset":
transfer.plex_command("RESET-PKC")
return
elif mode == "togglePlexTV":
LOG.info("Toggle of Plex.tv sign-in requested")
transfer.plex_command("toggle_plex_tv_sign_in")
return
elif mode == "passwords":
from resources.lib.windows import direct_path_sources
direct_path_sources.start()
return
elif mode == "switchuser":
LOG.info("Plex home user switch requested")
transfer.plex_command("switch_plex_user")
return
elif mode in ("manualsync", "repair"):
if mode == "repair":
LOG.info("Requesting repair lib sync")
transfer.plex_command("repair-scan")
elif mode == "manualsync":
LOG.info("Requesting full library scan")
transfer.plex_command("full-scan")
return
elif mode == "texturecache":
LOG.info("Requesting texture caching of all textures")
transfer.plex_command("textures-scan")
return
elif mode == "chooseServer":
LOG.info("Choosing PMS server requested, starting")
transfer.plex_command("choose_pms_server")
return
elif mode == "deviceid":
LOG.info("New PKC UUID / unique device id requested")
transfer.plex_command("generate_new_uuid")
return
elif mode == "fanart":
LOG.info("User requested fanarttv refresh")
transfer.plex_command("fanart-scan")
return
elif mode == "watchlist_add_key":
_enqueue_watchlist_detail(
"WATCHLIST_DETAIL_KEY", watchlist.begin_key(params, "present")
)
return
elif mode == "watchlist_remove_key":
_enqueue_watchlist_detail(
"WATCHLIST_DETAIL_KEY", watchlist.begin_key(params, "absent")
)
return
elif mode == "watchlist_add_tmdb":
_enqueue_watchlist_detail(
"WATCHLIST_DETAIL_TMDB", watchlist.begin_tmdb(params, "present")
)
return
elif mode == "watchlist_remove_tmdb":
_enqueue_watchlist_detail(
"WATCHLIST_DETAIL_TMDB", watchlist.begin_tmdb(params, "absent")
)
return
elif mode == "watchlist_status_key":
watchlist.bootstrap_status_key(params)
transfer.plex_command("WATCHLIST_STATUS_KEY?%s" % urlencode(params))
return
elif mode == "watchlist_status_tmdb":
watchlist.bootstrap_status_tmdb(params)
transfer.plex_command("WATCHLIST_STATUS_TMDB?%s" % urlencode(params))
return
elif mode == "watchlist_status_monitor":
transfer.plex_command("WATCHLIST_STATUS_MONITOR")
return
elif mode == "watchlist_status_search":
watchlist.bootstrap_status_search(params)
transfer.plex_command("WATCHLIST_STATUS_SEARCH?%s" % urlencode(params))
return
elif mode == "discover_detail":
from resources.lib import entrypoint
entrypoint.discover_detail(params.get("rating_key"))
return
elif mode == "watchlist_add_search":
transfer.plex_command("WATCHLIST_ADD_SEARCH?%s" % urlencode(params))
return
elif mode == "watchlist_remove_search":
transfer.plex_command("WATCHLIST_REMOVE_SEARCH?%s" % urlencode(params))
return
from resources.lib import entrypoint
# Listings: we list ListItems and need to tell Kodi when we're done
try:
if mode == "browseplex":
entrypoint.browse_plex(
key=params.get("key"),
plex_type=params.get("plex_type"),
section_id=params.get("section_id"),
synched=params.get("synched") != "false",
prompt=params.get("prompt"),
query=params.get("query"),
)
elif mode == "show_section":
entrypoint.show_section(params.get("section_index"))
elif mode == "watchlater":
entrypoint.watchlater()
elif mode == "watchlist":
entrypoint.watchlist(section_id=params.get("section_id"))
elif mode == "discover_hubs":
entrypoint.discover_hubs()
elif mode == "discover_hub":
entrypoint.discover_hub(params.get("hub_id"))
elif mode == "channels":
entrypoint.browse_plex(key="/channels/all")
elif mode == "search":
# "Search"
entrypoint.browse_plex(
key="/hubs/search",
args={"includeCollections": 1, "includeExternalMedia": 1},
prompt=utils.lang(137),
query=params.get("query"),
)
elif mode == "route_to_extras":
# Hack so we can store this path in the Kodi DB
handle = "plugin://%s?mode=extras&plex_id=%s" % (
v.ADDON_ID,
params.get("plex_id"),
)
xbmc.executebuiltin('ActivateWindow(videos,"%s",return)' % handle)
elif mode == "extras":
entrypoint.extras(plex_id=params.get("plex_id"))
# Called by e.g. 3rd party plugin video extras
elif "/Extras" in path or "/VideoFiles" in path or "/Extras" in arguments:
plexId = itemid or None
entrypoint.get_video_files(plexId, params)
elif mode == "playlists":
entrypoint.playlists(params.get("content_type"))
elif mode == "hub":
entrypoint.hub(params.get("content_type"))
elif mode == "select-libraries":
LOG.info("User requested to select Plex libraries")
transfer.plex_command("select-libraries")
elif mode == "refreshplaylist":
LOG.info("User requested to refresh Kodi playlists and nodes")
transfer.plex_command("refreshplaylist")
elif "/extrafanart" in path:
plexpath = arguments[1:]
plexid = itemid
entrypoint.extra_fanart(plexid, plexpath)
entrypoint.get_video_files(plexid, plexpath)
else:
entrypoint.show_main_menu(content_type=params.get("content_type"))
except entrypoint.ListingException:
# Tell Kodi listing is done and we failed
xbmcplugin.endOfDirectory(int(argv[1]), False)
else:
# Tell Kodi listing is done and we were successful
xbmcplugin.endOfDirectory(int(argv[1]))
def play():
"""
Start up playback_starter in main Python thread
"""
request = "%s&handle=%s" % (argv[2], int(argv[1]))
# Put the request into the 'queue'
transfer.plex_command("PLAY-%s" % request)
if int(argv[1]) == -1:
# Handle -1 received, not waiting for main thread
return
# Wait for the result from the main PKC thread
result = transfer.wait_for_transfer(source="main")
if result is True:
xbmcplugin.setResolvedUrl(int(argv[1]), False, xbmcgui.ListItem())
# Tell main thread that we're done
transfer.send(True, target="main")
else:
# Received a xbmcgui.ListItem()
xbmcplugin.setResolvedUrl(int(argv[1]), True, result)
def main():
LOG.debug("Full sys.argv received: %s", argv)
# Parse parameters that were passed
params = dict(parse_qsl(argv[2][1:]))
mode = params.get("mode", "")
path = argv[0]
arguments = argv[2]
itemid = params.get("id", "")
if mode not in WATCHLIST_ACTION_MODES:
v.database_paths()
triage(mode, params, path, arguments, itemid)
if __name__ == "__main__":
LOG.info("%s started" % v.ADDON_ID)
try:
main()
except RuntimeError as err:
# Database does not exists
LOG.error("The current Kodi version is incompatible")
LOG.error("Error: %s", err)
LOG.info("%s stopped" % v.ADDON_ID)