@@ -38,45 +38,36 @@ def doAssign():
38
38
except AttributeError :
39
39
path = sys .listitem .getPath ()
40
40
41
- use_tmdb_id = False
42
-
43
- if path .startswith ("plugin://plugin.video.elementum" ):
44
- """plugin://plugin.video.elementum/show/1622/season/15/episode/1/links/Supernatural%20S15E01
45
- plugin://plugin.video.elementum/show/1622/season/15/episodes
46
- plugin://plugin.video.elementum/movie/628/links/Interview%20with%20the%20Vampire%20%281994%29"""
47
- use_tmdb_id = True
48
- result = re .search (r'plugin://plugin.video.elementum/[^/]+/(\d+)/.*' , path )
49
- if result :
50
- tmdbID = result .group (1 )
51
- else :
52
- log .error ("Could not find TMDB id for %s" % path )
53
- xbmcgui .Dialog ().notification (ADDON .getLocalizedString (32007 ), ADDON .getLocalizedString (32014 ), xbmcgui .NOTIFICATION_WARNING , 3000 )
54
- return
41
+ use_elementum_path = False
55
42
56
- if mediatype == 'season' :
57
- result = re .search (r'plugin://plugin.video.elementum/[^/]+/\d+/season/(\d+)/.*' , path )
58
- if result :
59
- season_number = result .group (1 )
60
- else :
61
- log .error ("Could not find season number for %s" % path )
62
- xbmcgui .Dialog ().notification (ADDON .getLocalizedString (32007 ), ADDON .getLocalizedString (32014 ), xbmcgui .NOTIFICATION_WARNING , 3000 )
43
+ try :
44
+ tmdbID = sys .listitem .getUniqueID ('tmdb' )
45
+ except AttributeError :
46
+ tmdbID = ""
47
+
48
+ if tmdbID == "" :
49
+ if path .startswith ("plugin://plugin.video.elementum" ):
50
+ use_elementum_path = True
51
+ tmdbID = getTMDBidFromElementumPath (path )
52
+ if not tmdbID :
63
53
return
64
54
65
- if mediatype == 'episode' :
66
- result = re .search (r'plugin://plugin.video.elementum/[^/]+/\d+/season/(\d+)/episode/(\d+)/.*' , path )
67
- if result :
68
- season_number = result .group (1 )
69
- episode_number = result .group (2 )
70
- else :
71
- log .error ("Could not find season/episode number for %s" % path )
72
- xbmcgui .Dialog ().notification (ADDON .getLocalizedString (32007 ), ADDON .getLocalizedString (32014 ), xbmcgui .NOTIFICATION_WARNING , 3000 )
55
+ if mediatype == 'season' :
56
+ season_number = getSeasonNumberFromElementumPath (path )
57
+ if not season_number :
58
+ return
59
+
60
+ if mediatype == 'episode' :
61
+ season_number = getSeasonNumberFromElementumPath (path )
62
+ episode_number = getEpisodeNumberFromElementumPath (path )
63
+ if not season_number or not episode_number :
64
+ return
65
+ else :
66
+ dbid = getDbId ()
67
+ if not dbid .isdigit ():
68
+ log .error ("Kodi library ID is wrong %s" % dbid )
69
+ xbmcgui .Dialog ().notification (ADDON .getLocalizedString (32007 ), ADDON .getLocalizedString (32016 ), xbmcgui .NOTIFICATION_WARNING , 3000 )
73
70
return
74
- else :
75
- dbid = getDbId ()
76
- if not dbid .isdigit ():
77
- log .error ("Kodi library ID is wrong %s" % dbid )
78
- xbmcgui .Dialog ().notification (ADDON .getLocalizedString (32007 ), ADDON .getLocalizedString (32016 ), xbmcgui .NOTIFICATION_WARNING , 3000 )
79
- return
80
71
81
72
# we also can use plugin://plugin.video.elementum/torrents/
82
73
file = xbmcgui .Dialog ().browseSingle (1 , ADDON .getLocalizedString (32010 ), 'files' , '' , False , False , 'plugin://plugin.video.elementum/history/' )
@@ -96,24 +87,29 @@ def doAssign():
96
87
xbmcgui .Dialog ().notification (ADDON .getLocalizedString (32007 ), ADDON .getLocalizedString (32015 ), xbmcgui .NOTIFICATION_WARNING , 3000 )
97
88
return
98
89
99
- if not use_tmdb_id :
100
- url = "plugin://plugin.video.elementum/context/torrents/assign/%s/kodi/%s/%s" % (torrentid , mediatype , dbid )
101
- log .info ("Assigning torrent %s for: DBID=%s, MediaType=%s" % (torrentid , dbid , mediatype ))
102
- else :
90
+ if use_elementum_path :
103
91
if mediatype == 'movie' :
104
92
url = "plugin://plugin.video.elementum/context/torrents/assign/%s/tmdb/%s/%s" % (torrentid , mediatype , tmdbID )
105
93
elif mediatype == 'season' :
106
94
url = "plugin://plugin.video.elementum/context/torrents/assign/%s/tmdb/show/%s/%s/%s" % (torrentid , tmdbID , mediatype , season_number )
107
95
elif mediatype == 'episode' :
108
96
url = "plugin://plugin.video.elementum/context/torrents/assign/%s/tmdb/show/%s/season/%s/%s/%s" % (torrentid , tmdbID , season_number , mediatype , episode_number )
109
97
log .info ("Assigning torrent %s for: TMDBID=%s, MediaType=%s" % (torrentid , tmdbID , mediatype ))
98
+ else :
99
+ if tmdbID != "" :
100
+ url = "plugin://plugin.video.elementum/torrents/assign/%s/%s" % (torrentid , tmdbID )
101
+ log .info ("Assigning torrent %s for: TMDBID=%s, MediaType=%s" % (torrentid , tmdbID , mediatype ))
102
+ else :
103
+ url = "plugin://plugin.video.elementum/context/torrents/assign/%s/kodi/%s/%s" % (torrentid , mediatype , dbid )
104
+ log .info ("Assigning torrent %s for: DBID=%s, MediaType=%s" % (torrentid , dbid , mediatype ))
110
105
111
106
xbmcgui .Dialog ().notification (ADDON .getLocalizedString (32010 ), sys .listitem .getLabel (), xbmcgui .NOTIFICATION_INFO , 3000 )
112
107
113
108
log .info ("Starting Elementum with: %s" % url )
114
109
115
110
xbmc .Player ().play (url )
116
111
112
+
117
113
def doPlay ():
118
114
dbid = getDbId ()
119
115
mediatype = getMediaType ()
@@ -142,14 +138,21 @@ def doDownload():
142
138
143
139
def doLibraryAction (action ):
144
140
dbid = getDbId ()
141
+ try :
142
+ tmdbID = sys .listitem .getUniqueID ('tmdb' )
143
+ except AttributeError :
144
+ tmdbID = ""
145
145
mediatype = getMediaType ()
146
146
147
147
heading = ADDON .getLocalizedString (32017 ) if action == "add" else "Unsupported action"
148
148
xbmcgui .Dialog ().notification (heading , sys .listitem .getLabel (), xbmcgui .NOTIFICATION_INFO , 3000 )
149
149
150
150
log .info ("%s library item: DBID=%s, MediaType=%s" % (action , dbid , mediatype ))
151
151
152
- url = "plugin://plugin.video.elementum/context/library/%s/%s/%s" % (mediatype , dbid , action )
152
+ if tmdbID != "" :
153
+ url = "plugin://plugin.video.elementum/library/%s/%s/%s" % (mediatype , action , tmdbID )
154
+ else :
155
+ url = "plugin://plugin.video.elementum/context/library/%s/%s/%s" % (mediatype , dbid , action )
153
156
log .info ("Starting Elementum with: %s" % url )
154
157
xbmc .Player ().play (url )
155
158
@@ -164,11 +167,38 @@ def doTraktAction(action):
164
167
heading = ADDON .getLocalizedString (32019 )
165
168
else :
166
169
heading = "Unsupported action"
167
- xbmcgui .Dialog ().notification (heading , sys .listitem .getLabel (), xbmcgui .NOTIFICATION_INFO , 3000 )
168
170
169
- log .info ("%s library item: DBID=%s, MediaType=%s" % (action , dbid , mediatype ))
171
+ if not dbid .isdigit ():
172
+ showtmdbid = xbmc .getInfoLabel ('ListItem.Property(ShowTMDBId)' )
173
+ try :
174
+ tmdbID = sys .listitem .getUniqueID ('tmdb' )
175
+ except AttributeError :
176
+ tmdbID = ""
177
+ if tmdbID == "" or ((mediatype == 'season' or mediatype == 'episode' ) and showtmdbid == "" ):
178
+ log .error ("Could not find TMDB id for %s" % dbid )
179
+ xbmcgui .Dialog ().notification (ADDON .getLocalizedString (32007 ), ADDON .getLocalizedString (32014 ), xbmcgui .NOTIFICATION_WARNING , 3000 )
180
+ return
170
181
171
- url = "plugin://plugin.video.elementum/context/media/%s/%s/%s" % (mediatype , dbid , action )
182
+ xbmcgui .Dialog ().notification (heading , sys .listitem .getLabel (), xbmcgui .NOTIFICATION_INFO , 3000 )
183
+ if not dbid .isdigit ():
184
+ log .info ("Make %s non-library item: tmdbID=%s, MediaType=%s" % (action , tmdbID , mediatype ))
185
+ else :
186
+ log .info ("Make %s library item: DBID=%s, MediaType=%s" % (action , dbid , mediatype ))
187
+
188
+ if not dbid .isdigit ():
189
+ if mediatype == 'movie' :
190
+ url = "plugin://plugin.video.elementum/movie/%s/%s" % (tmdbID , action )
191
+ if mediatype == 'tvshow' :
192
+ url = "plugin://plugin.video.elementum/show/%s/%s" % (tmdbID , action )
193
+ elif mediatype == 'season' :
194
+ season = xbmc .getInfoLabel ('ListItem.Season' )
195
+ url = "plugin://plugin.video.elementum/show/%s/season/%s/%s" % (showtmdbid , season , action )
196
+ elif mediatype == 'episode' :
197
+ season = xbmc .getInfoLabel ('ListItem.Season' )
198
+ episode = xbmc .getInfoLabel ('ListItem.Episode' )
199
+ url = "plugin://plugin.video.elementum/show/%s/season/%s/episode/%s/%s" % (showtmdbid , season , episode , action )
200
+ else :
201
+ url = "plugin://plugin.video.elementum/context/media/%s/%s/%s" % (mediatype , dbid , action )
172
202
log .info ("Starting Elementum with: %s" % url )
173
203
xbmc .Player ().play (url )
174
204
@@ -212,7 +242,7 @@ def getMediaType():
212
242
if xbmc .getInfoLabel ('ListItem.DBTYPE' ):
213
243
# Seasons and calls from library will work
214
244
return xbmc .getInfoLabel ('ListItem.DBTYPE' )
215
- elif version >= 18 :
245
+ elif version >= 17 :
216
246
# Will work on Kodi 17 and further
217
247
return getVideoTag ().getMediaType ()
218
248
else :
@@ -248,45 +278,6 @@ def getVideoTag():
248
278
return sys .listitem .getVideoInfoTag ()
249
279
250
280
251
- def getTMDBId (mediatype , id ):
252
- if isTMDBId (mediatype , id ):
253
- return id
254
- else :
255
- if mediatype == 'movie' :
256
- url = "https://api.themoviedb.org/3/find/%s?api_key=%s&language=en-US&external_source=%s" % (id , api_key , 'imdb_id' )
257
- elif mediatype == 'show' :
258
- url = "https://api.themoviedb.org/3/find/%s?api_key=%s&language=en-US&external_source=%s" % (id , api_key , 'tvdb_id' )
259
-
260
- response = getJSON (url )
261
-
262
- if 'status_code' in response :
263
- xbmcgui .Dialog ().notification (ADDON .getLocalizedString (32007 ), ADDON .getLocalizedString (32008 ), xbmcgui .NOTIFICATION_WARNING , 3000 )
264
- return None
265
-
266
- if response ['movie_results' ]:
267
- return response ['movie_results' ][0 ]['id' ]
268
- elif response ['tv_results' ]:
269
- return response ['tv_results' ][0 ]['id' ]
270
- elif response ['tv_episode_results' ]:
271
- return response ['tv_episode_results' ][0 ]['id' ]
272
- else :
273
- return None
274
-
275
-
276
- def isTMDBId (mediatype , id ):
277
- if mediatype == 'show' :
278
- url = "https://api.themoviedb.org/3/tv/%s?api_key=%s&language=en-US" % (id , api_key )
279
- elif mediatype == 'movie' :
280
- url = "https://api.themoviedb.org/3/movie/%s?api_key=%s&language=en-US" % (id , api_key )
281
-
282
- response = getJSON (url )
283
-
284
- if 'status_code' in response :
285
- return False
286
- else :
287
- return True
288
-
289
-
290
281
def xbmcVersion ():
291
282
build = xbmc .getInfoLabel ('System.BuildVersion' )
292
283
@@ -312,6 +303,14 @@ def getJSONResponse(message):
312
303
return simplejson .loads (xbmc .executeJSONRPC (message ))
313
304
314
305
306
+ def getJSON (url ):
307
+ page = requests .get (url ).content
308
+ try :
309
+ return simplejson .loads (page )
310
+ except :
311
+ return simplejson .loads (page .decode ('utf-8' ))
312
+
313
+
315
314
def configureTMDB ():
316
315
global api_key
317
316
@@ -327,9 +326,84 @@ def configureTMDB():
327
326
return True
328
327
329
328
330
- def getJSON (url ):
331
- page = requests .get (url ).content
332
- try :
333
- return simplejson .loads (page )
334
- except :
335
- return simplejson .loads (page .decode ('utf-8' ))
329
+ def isTMDBId (mediatype , id ):
330
+ if mediatype == 'show' :
331
+ url = "https://api.themoviedb.org/3/tv/%s?api_key=%s&language=en-US" % (id , api_key )
332
+ elif mediatype == 'movie' :
333
+ url = "https://api.themoviedb.org/3/movie/%s?api_key=%s&language=en-US" % (id , api_key )
334
+
335
+ response = getJSON (url )
336
+
337
+ if 'status_code' in response :
338
+ return False
339
+ else :
340
+ return True
341
+
342
+
343
+ def getTMDBId (mediatype , id ):
344
+ if isTMDBId (mediatype , id ):
345
+ return id
346
+ else :
347
+ if mediatype == 'movie' :
348
+ url = "https://api.themoviedb.org/3/find/%s?api_key=%s&language=en-US&external_source=%s" % (id , api_key , 'imdb_id' )
349
+ elif mediatype == 'show' :
350
+ url = "https://api.themoviedb.org/3/find/%s?api_key=%s&language=en-US&external_source=%s" % (id , api_key , 'tvdb_id' )
351
+
352
+ response = getJSON (url )
353
+
354
+ if 'status_code' in response :
355
+ xbmcgui .Dialog ().notification (ADDON .getLocalizedString (32007 ), ADDON .getLocalizedString (32008 ), xbmcgui .NOTIFICATION_WARNING , 3000 )
356
+ return None
357
+
358
+ if response ['movie_results' ]:
359
+ return response ['movie_results' ][0 ]['id' ]
360
+ elif response ['tv_results' ]:
361
+ return response ['tv_results' ][0 ]['id' ]
362
+ elif response ['tv_episode_results' ]:
363
+ return response ['tv_episode_results' ][0 ]['id' ]
364
+ else :
365
+ return None
366
+
367
+
368
+ def getTMDBidFromElementumPath (path ):
369
+ """plugin://plugin.video.elementum/movie/628/links/Interview%20with%20the%20Vampire%20%281994%29"""
370
+ result = re .search (r'plugin://plugin.video.elementum/[^/]+/(\d+)/.*' , path )
371
+ if result :
372
+ tmdbID = result .group (1 )
373
+ return tmdbID
374
+ else :
375
+ log .error ("Could not find TMDB id for %s" % path )
376
+ xbmcgui .Dialog ().notification (ADDON .getLocalizedString (32007 ), ADDON .getLocalizedString (32014 ), xbmcgui .NOTIFICATION_WARNING , 3000 )
377
+ return ""
378
+
379
+
380
+ def getSeasonNumberFromElementumPath (path ):
381
+ """plugin://plugin.video.elementum/show/1622/season/15/episodes"""
382
+ season_number = xbmc .getInfoLabel ('ListItem.Season' )
383
+ if season_number :
384
+ return season_number
385
+ else :
386
+ result = re .search (r'plugin://plugin.video.elementum/[^/]+/\d+/season/(\d+)/.*' , path )
387
+ if result :
388
+ season_number = result .group (1 )
389
+ return season_number
390
+ else :
391
+ log .error ("Could not find season number for %s" % path )
392
+ xbmcgui .Dialog ().notification (ADDON .getLocalizedString (32007 ), ADDON .getLocalizedString (32014 ), xbmcgui .NOTIFICATION_WARNING , 3000 )
393
+ return ""
394
+
395
+
396
+ def getEpisodeNumberFromElementumPath (path ):
397
+ """plugin://plugin.video.elementum/show/1622/season/15/episode/1/links/Supernatural%20S15E01"""
398
+ episode_number = xbmc .getInfoLabel ('ListItem.Episode' )
399
+ if episode_number :
400
+ return episode_number
401
+ else :
402
+ result = re .search (r'plugin://plugin.video.elementum/[^/]+/\d+/season/\d+/episode/(\d+)/.*' , path )
403
+ if result :
404
+ episode_number = result .group (1 )
405
+ return episode_number
406
+ else :
407
+ log .error ("Could not find episode number for %s" % path )
408
+ xbmcgui .Dialog ().notification (ADDON .getLocalizedString (32007 ), ADDON .getLocalizedString (32014 ), xbmcgui .NOTIFICATION_WARNING , 3000 )
409
+ return ""
0 commit comments