def _json(url): with closing(urllib_request.urlopen(url)) as response: if response.code == 300: raise PlayerException(response.info().getheader('Location')) elif response.code == 301: raise RedirectException(response.info().getheader('Location')) elif response.code >= 302 and response.code <= 307: # Pause currently playing Elementum file to avoid doubling requests try: if xbmc.Player().isPlaying() and ADDON_ID in xbmc.Player( ).getPlayingFile(): xbmc.Player().pause() except: pass _infoLabels = InfoLabels(getInfoLabels()) if 'mediatype' not in _infoLabels or not _infoLabels['mediatype']: _infoLabels['mediatype'] = 'episode' _infoLabels['dbtype'] = 'episode' if PLATFORM['kodi'] >= 19: item = xbmcgui.ListItem(path=response.geturl(), label=_infoLabels["label"], label2=_infoLabels["label2"]) else: item = xbmcgui.ListItem( path=response.geturl(), label=_infoLabels["label"], label2=_infoLabels["label2"], thumbnailImage=_infoLabels["thumbnail"]) item.setArt({ "thumb": _infoLabels["artthumb"], "poster": _infoLabels["artposter"], "tvshowposter": _infoLabels["arttvshowposter"], "banner": _infoLabels["artbanner"], "fanart": _infoLabels["artfanart"], "clearart": _infoLabels["artclearart"], "clearlogo": _infoLabels["artclearlogo"], "landscape": _infoLabels["artlandscape"], "icon": _infoLabels["articon"] }) if 'castmembers' in _infoLabels: if PLATFORM['kodi'] >= 17: item.setCast(_infoLabels['castmembers']) del _infoLabels['castmembers'] _infoLabels = normalizeLabels(_infoLabels) item.setInfo(type='Video', infoLabels=_infoLabels) xbmcplugin.setResolvedUrl(HANDLE, True, item) return # TODO: If somebody wants to try to fix the issue with having correct naming in Kodi player information. # Currently Kodi pushes file name, which is stored on the disk (inside of strm file). # And the problem is that we can't change it (or at least, I'm not aware of any ways to do it). # So I have tried to remove it and create a playlist, but that does not work with starting anything from a library. # try: # log.debug("PLAYING: %s" % (xbmc.Player().getPlayingFile())) # except: # log.debug("NOT PLAYING") # if "elementum" in response.geturl().lower() and "http" not in response.geturl().lower(): # log.debug("RESOLVED: %s" % response.geturl().lower()) # xbmcplugin.setResolvedUrl(HANDLE, True, item) # else: # playlistId = xbmc.PLAYLIST_VIDEO # if xbmc.PlayList(1).size() > 0: # playlistId = 1 # elif xbmc.PlayList(0).size() > 0: # playlistId = 0 # playlist = xbmc.PlayList(playlistId) # playlist.clear() # playlist.add(url=response.geturl(), listitem=item, index=0) # log.debug("PLAYLIST: %s --- %d" % (response.geturl(), playlist.size())) # xbmc.Player().play(playlist) # return payload = to_unicode(response.read()) try: if payload: return json.loads(payload) except: raise Exception(payload)
def getInfoLabels(): id_list = [int(s) for s in sys.argv[0].split("/") if s.isdigit()] tmdb_id = id_list[0] if id_list else None # if xbmc.getInfoLabel("ListItem.DBID"): # url = "%s/infolabels" % (ELEMENTUMD_HOST) # elif not tmdb_id: if not tmdb_id: request_url = sys.argv[0] + sys.argv[2] parsed_url = urllib_parse.urlparse(request_url) query = urllib_parse.parse_qs(parsed_url.query) query['index'] = query['index'][0] if 'index' in query else '' log.debug("Parsed URL: %s, Query: %s", repr(parsed_url), repr(query)) if 'tmdb' in query and 'type' in query and query['type'][0] == 'search': tmdb_id = query['tmdb'][0] url = "%s/search/infolabels/%s?index=%s" % ( ELEMENTUMD_HOST, tmdb_id, query['index']) elif '/search' in parsed_url and 'tmdb' in query: tmdb_id = query['tmdb'][0] url = "%s/search/infolabels/%s?index=%s" % ( ELEMENTUMD_HOST, tmdb_id, query['index']) elif '/search' in parsed_url and 'q' in query: tmdb_id = py2_decode(query['q'][0]) url = "%s/search/infolabels/%s?index=%s" % ( ELEMENTUMD_HOST, tmdb_id, query['index']) elif 'tmdb' in query and 'type' in query and query['type'][ 0] == 'movie': tmdb_id = query['tmdb'][0] url = "%s/movie/%s/infolabels" % (ELEMENTUMD_HOST, tmdb_id) elif 'show' in query: tmdb_id = query['show'][0] if 'season' in query and 'episode' in query: url = "%s/show/%s/season/%s/episode/%s/infolabels" % ( ELEMENTUMD_HOST, tmdb_id, query['season'][0], query['episode'][0]) else: url = "%s/show/%s/infolabels" % (ELEMENTUMD_HOST, tmdb_id) else: url = "%s/infolabels" % (ELEMENTUMD_HOST) elif 'movie' in sys.argv[0]: url = "%s/movie/%s/infolabels" % (ELEMENTUMD_HOST, tmdb_id) elif ('episode' in sys.argv[0] or 'show' in sys.argv[0]) and len(id_list) > 2: url = "%s/show/%s/season/%s/episode/%s/infolabels" % ( ELEMENTUMD_HOST, tmdb_id, id_list[1], id_list[2]) elif 'show' in sys.argv[0] and len(id_list) == 2: url = "%s/show/%s/season/%s/episode/%s/infolabels" % ( ELEMENTUMD_HOST, tmdb_id, id_list[1], 1) else: url = "%s/infolabels" % (ELEMENTUMD_HOST) log.debug("Resolving TMDB item by calling %s for %s" % (url, repr(sys.argv))) try: with closing(urllib_request.urlopen(url)) as response: resolved = json.loads(to_unicode(response.read()), parse_int=str) if not resolved: return {} if 'info' in resolved and resolved['info']: resolved.update(resolved['info']) if 'art' in resolved and resolved['art']: resolved['artbanner'] = '' for k, v in resolved['art'].items(): resolved['art' + k] = v if 'info' in resolved: del resolved['info'] if 'art' in resolved: del resolved['art'] if 'stream_info' in resolved: del resolved['stream_info'] if 'DBTYPE' not in resolved: resolved['DBTYPE'] = 'video' if 'mediatype' not in resolved or resolved['mediatype'] == '': resolved['mediatype'] = resolved['DBTYPE'] return resolved except: log.debug("Could not resolve TMDB item: %s" % tmdb_id) return {}