def send_headers(self): image = None preferred_type = None org_params = urlparse.parse_qs(self.path) params = {} for key, value in org_params.iteritems(): if value: value = value[0] if "%" in value: value = urllib.unquote(value) params[key] = value.decode("utf-8") action = params.get("action", "") title = params.get("title", "") fallback = params.get("fallback", "") if fallback.startswith("Default"): fallback = u"special://skin/media/" + fallback if action == "getthumb": image = artutils.searchThumb(title) elif action == "getanimatedposter": imdbid = params.get("imdbid", "") if imdbid: image = artutils.getAnimatedPosters(imdbid).get( "animated_poster", "") elif action == "getvarimage": title = title.replace("{", "[").replace("}", "]") image_tmp = xbmc.getInfoLabel(title) if xbmcvfs.exists(image_tmp): if image_tmp.startswith("resource://"): #texture packed resource images are failing: http://trac.kodi.tv/ticket/16366 logMsg( "WebService ERROR --> resource images are currently not supported due to a bug in Kodi", 0) else: image = image_tmp elif action == "getpvrthumb": channel = params.get("channel", "") preferred_type = params.get("type", "") if xbmc.getCondVisibility("Window.IsActive(MyPVRRecordings.xml)"): type = "recordings" else: type = "channels" artwork = artutils.getPVRThumbs(title, channel, type) if preferred_type: preferred_types = preferred_type.split(",") for preftype in preferred_types: if artwork.get(preftype): image = artwork.get(preftype) break else: if artwork.get("thumb"): image = artwork.get("thumb") if artwork.get("fanart"): image = artwork.get("fanart") if artwork.get("landscape"): image = artwork.get("landscape") elif action == "getallpvrthumb": channel = params.get("channel", "") images = artutils.getPVRThumbs(title, channel, "recordings") # Ensure no unicode in images... for key, value in images.iteritems(): images[key] = unicode(value).encode('utf-8') images = urllib.urlencode(images) self.send_response(200) self.send_header('Content-type', 'text/plaintext') self.send_header('Content-Length', len(images)) self.end_headers() return images, True elif action == "getartwork": year = params.get("year", "") arttype = params.get("type", "") artwork = artutils.getAddonArtwork(title, year, arttype) jsonstr = json.dumps(artwork) self.send_response(200) self.send_header('Content-type', 'application/json') self.send_header('Content-Length', len(jsonstr)) self.end_headers() return jsonstr, True elif action == "getmusicart": preferred_type = params.get("type", "") artist = params.get("artist", "") album = params.get("album", "") track = params.get("track", "") artwork = artutils.getMusicArtwork(artist, album, track) if preferred_type: preferred_types = preferred_type.split(",") for preftype in preferred_types: if artwork.get(preftype): image = artwork.get(preftype) break else: if artwork.get("thumb"): image = artwork.get("thumb") if artwork.get("fanart"): image = artwork.get("fanart") elif "getmoviegenreimages" in action or "gettvshowgenreimages" in action: artwork = {} cachestr = ("%s-%s" % (action, title)).encode("utf-8") cache = WINDOW.getProperty(cachestr).decode("utf-8") if cache: artwork = eval(cache) else: sort = '"order": "ascending", "method": "sorttitle", "ignorearticle": true' if "random" in action: sort = '"order": "descending", "method": "random"' action = action.replace("random", "") if action == "gettvshowgenreimages": json_result = getJSON( 'VideoLibrary.GetTvshows', '{ "sort": { %s }, "filter": {"operator":"is", "field":"genre", "value":"%s"}, "properties": [ %s ],"limits":{"end":%d} }' % (sort, title, fields_tvshows, 5)) else: json_result = getJSON( 'VideoLibrary.GetMovies', '{ "sort": { %s }, "filter": {"operator":"is", "field":"genre", "value":"%s"}, "properties": [ %s ],"limits":{"end":%d} }' % (sort, title, fields_movies, 5)) for count, item in enumerate(json_result): artwork["poster.%s" % count] = item["art"].get( "poster", "") artwork["fanart.%s" % count] = item["art"].get( "fanart", "") WINDOW.setProperty(cachestr, repr(artwork).encode("utf-8")) if artwork: preferred_type = params.get("type", "") if preferred_type: image = artwork.get(preferred_type, "") else: image = artwork.get("poster", "") #set fallback image if nothing else worked if not image and fallback: image = fallback if image: self.send_response(200) if ".jpg" in image: self.send_header('Content-type', 'image/jpg') elif image.lower().endswith(".gif"): self.send_header('Content-type', 'image/gif') else: self.send_header('Content-type', 'image/png') logMsg("found image for request %s --> %s" % (try_encode(self.path), try_encode(image))) st = xbmcvfs.Stat(image) modified = st.st_mtime() self.send_header('Last-Modified', "%s" % modified) image = xbmcvfs.File(image) size = image.size() self.send_header('Content-Length', str(size)) self.end_headers() else: self.send_error(404) return image, None
def send_headers(self): image = None images = None preferred_type = None params = urlparse.parse_qs(self.path) action = params.get("action","")[0] title = params.get("title","") if title: title = title[0].decode("utf-8") fallback = params.get("fallback","") if fallback: fallback = fallback[0].decode("utf-8") if fallback.startswith("Default"): fallback = "special://skin/media/" + fallback if action == "getthumb": image = artutils.searchThumb(title) elif action == "getvarimage": title = title.replace("{","[").replace("}","]") image_tmp = xbmc.getInfoLabel(title) if xbmcvfs.exists(image_tmp): if image_tmp.startswith("resource://"): #texture packed resource images are failing: http://trac.kodi.tv/ticket/16366 logMsg("WebService ERROR --> resource images are currently not supported due to a bug in Kodi" ,0) else: image = image_tmp elif action == "getpvrthumb": channel = params.get("channel","") preferred_type = params.get("type","") if channel: channel = channel[0].decode("utf-8") if preferred_type: preferred_type = preferred_type[0] if xbmc.getCondVisibility("Window.IsActive(MyPVRRecordings.xml)"): type = "recordings" else: type = "channels" artwork = artutils.getPVRThumbs(title, channel, type) if preferred_type: preferred_types = preferred_type.split(",") for preftype in preferred_types: if artwork.get(preftype): image = artwork.get(preftype) break else: if artwork.get("thumb"): image = artwork.get("thumb") if artwork.get("fanart"): image = artwork.get("fanart") if artwork.get("landscape"): image = artwork.get("landscape") elif action == "getallpvrthumb": channel = params.get("channel","") if channel: channel = channel[0].decode("utf-8") images = artutils.getPVRThumbs(title, channel, "recordings") # Ensure no unicode in images... for key, value in images.iteritems(): images[key] = unicode(value).encode('utf-8') images = urllib.urlencode(images) elif action == "getmusicart": preferred_type = params.get("type","") if preferred_type: preferred_type = preferred_type[0] artist = params.get("artist","") if artist: artist = artist[0] album = params.get("album","") if album: album = album[0] track = params.get("track","") if track: track = track[0] artwork = artutils.getMusicArtwork(artist, album, track) if preferred_type: preferred_types = preferred_type.split(",") for preftype in preferred_types: if artwork.get(preftype): image = artwork.get(preftype) break else: if artwork.get("thumb"): image = artwork.get("thumb") if artwork.get("fanart"): image = artwork.get("fanart") #set fallback image if nothing else worked if not image and fallback: image = fallback if images: self.send_response(200) self.send_header('Content-type','text/plaintext') self.send_header('Content-Length',len(images)) self.end_headers() return images, True elif image: self.send_response(200) if ".jpg" in image: self.send_header('Content-type','image/jpeg') else: self.send_header('Content-type','image/png') logMsg("found image for request %s --> %s" %(try_encode(self.path),try_encode(image))) st = xbmcvfs.Stat(image) modified = st.st_mtime() self.send_header('Last-Modified',"%s" %modified) image = xbmcvfs.File(image) size = image.size() self.send_header('Content-Length',str(size)) self.end_headers() else: self.send_error(404) return image, None
def send_headers(self): image = None images = None preferred_type = None params = urlparse.parse_qs(self.path) action = params.get("action", "")[0] title = params.get("title", "") if title: title = title[0].decode("utf-8") fallback = params.get("fallback", "") if fallback: fallback = fallback[0].decode("utf-8") if fallback.startswith("Default"): fallback = "special://skin/media/" + fallback if action == "getthumb": image = artutils.searchThumb(title) elif action == "getvarimage": title = title.replace("{", "[").replace("}", "]") image_tmp = xbmc.getInfoLabel(title) if xbmcvfs.exists(image_tmp): if image_tmp.startswith("resource://"): #texture packed resource images are failing: http://trac.kodi.tv/ticket/16366 logMsg( "WebService ERROR --> resource images are currently not supported due to a bug in Kodi", 0) else: image = image_tmp elif action == "getpvrthumb": channel = params.get("channel", "") preferred_type = params.get("type", "") if channel: channel = channel[0].decode("utf-8") if preferred_type: preferred_type = preferred_type[0] if xbmc.getCondVisibility("Window.IsActive(MyPVRRecordings.xml)"): type = "recordings" else: type = "channels" artwork = artutils.getPVRThumbs(title, channel, type) if preferred_type: preferred_types = preferred_type.split(",") for preftype in preferred_types: if artwork.get(preftype): image = artwork.get(preftype) break else: if artwork.get("thumb"): image = artwork.get("thumb") if artwork.get("fanart"): image = artwork.get("fanart") if artwork.get("landscape"): image = artwork.get("landscape") elif action == "getallpvrthumb": channel = params.get("channel", "") if channel: channel = channel[0].decode("utf-8") images = artutils.getPVRThumbs(title, channel, "recordings") # Ensure no unicode in images... for key, value in images.iteritems(): images[key] = unicode(value).encode('utf-8') images = urllib.urlencode(images) elif action == "getmusicart": preferred_type = params.get("type", "") if preferred_type: preferred_type = preferred_type[0] artist = params.get("artist", "") if artist: artist = artist[0] album = params.get("album", "") if album: album = album[0] track = params.get("track", "") if track: track = track[0] artwork = artutils.getMusicArtwork(artist, album, track) if preferred_type: preferred_types = preferred_type.split(",") for preftype in preferred_types: if artwork.get(preftype): image = artwork.get(preftype) break else: if artwork.get("thumb"): image = artwork.get("thumb") if artwork.get("fanart"): image = artwork.get("fanart") #set fallback image if nothing else worked if not image and fallback: image = fallback if images: self.send_response(200) self.send_header('Content-type', 'text/plaintext') self.send_header('Content-Length', len(images)) self.end_headers() return images, True elif image: self.send_response(200) if ".jpg" in image: self.send_header('Content-type', 'image/jpeg') else: self.send_header('Content-type', 'image/png') logMsg("found image for request %s --> %s" % (try_encode(self.path), try_encode(image))) st = xbmcvfs.Stat(image) modified = st.st_mtime() self.send_header('Last-Modified', "%s" % modified) image = xbmcvfs.File(image) size = image.size() self.send_header('Content-Length', str(size)) self.end_headers() else: self.send_error(404) return image, None
def send_headers(self): image = None preferred_type = None org_params = urlparse.parse_qs(self.path) params = {} for key, value in org_params.iteritems(): if value: value = value[0] if "%" in value: value = urllib.unquote(value) params[key] = value.decode("utf-8") action = params.get("action", "") title = params.get("title", "") fallback = params.get("fallback", "") if fallback.startswith("Default"): fallback = u"special://skin/media/" + fallback if action == "getthumb": image = artutils.searchThumb(title) elif action == "getanimatedposter": imdbid = params.get("imdbid", "") if imdbid: image = artutils.getAnimatedPosters(imdbid).get("animated_poster", "") elif action == "getvarimage": title = title.replace("{", "[").replace("}", "]") image_tmp = xbmc.getInfoLabel(title) if xbmcvfs.exists(image_tmp): if image_tmp.startswith("resource://"): # texture packed resource images are failing: http://trac.kodi.tv/ticket/16366 logMsg("WebService ERROR --> resource images are currently not supported due to a bug in Kodi", 0) else: image = image_tmp elif action == "getpvrthumb": channel = params.get("channel", "") preferred_type = params.get("type", "") if xbmc.getCondVisibility("Window.IsActive(MyPVRRecordings.xml)"): type = "recordings" else: type = "channels" artwork = artutils.getPVRThumbs(title, channel, type) if preferred_type: preferred_types = preferred_type.split(",") for preftype in preferred_types: if artwork.get(preftype): image = artwork.get(preftype) break else: if artwork.get("thumb"): image = artwork.get("thumb") if artwork.get("fanart"): image = artwork.get("fanart") if artwork.get("landscape"): image = artwork.get("landscape") elif action == "getallpvrthumb": channel = params.get("channel", "") images = artutils.getPVRThumbs(title, channel, "recordings") # Ensure no unicode in images... for key, value in images.iteritems(): images[key] = unicode(value).encode("utf-8") images = urllib.urlencode(images) self.send_response(200) self.send_header("Content-type", "text/plaintext") self.send_header("Content-Length", len(images)) self.end_headers() return images, True elif action == "getartwork": year = params.get("year", "") arttype = params.get("type", "") artwork = artutils.getAddonArtwork(title, year, arttype) jsonstr = json.dumps(artwork) self.send_response(200) self.send_header("Content-type", "application/json") self.send_header("Content-Length", len(jsonstr)) self.end_headers() return jsonstr, True elif action == "getmusicart": preferred_type = params.get("type", "") artist = params.get("artist", "") album = params.get("album", "") track = params.get("track", "") artwork = artutils.getMusicArtwork(artist, album, track) if preferred_type: preferred_types = preferred_type.split(",") for preftype in preferred_types: if artwork.get(preftype): image = artwork.get(preftype) break else: if artwork.get("thumb"): image = artwork.get("thumb") if artwork.get("fanart"): image = artwork.get("fanart") elif "getmoviegenreimages" in action or "gettvshowgenreimages" in action: artwork = {} cachestr = ("%s-%s" % (action, title)).encode("utf-8") cache = WINDOW.getProperty(cachestr).decode("utf-8") if cache: artwork = eval(cache) else: sort = '"order": "ascending", "method": "sorttitle", "ignorearticle": true' if "random" in action: sort = '"order": "descending", "method": "random"' action = action.replace("random", "") if action == "gettvshowgenreimages": json_result = getJSON( "VideoLibrary.GetTvshows", '{ "sort": { %s }, "filter": {"operator":"is", "field":"genre", "value":"%s"}, "properties": [ %s ],"limits":{"end":%d} }' % (sort, title, fields_tvshows, 5), ) else: json_result = getJSON( "VideoLibrary.GetMovies", '{ "sort": { %s }, "filter": {"operator":"is", "field":"genre", "value":"%s"}, "properties": [ %s ],"limits":{"end":%d} }' % (sort, title, fields_movies, 5), ) for count, item in enumerate(json_result): artwork["poster.%s" % count] = item["art"].get("poster", "") artwork["fanart.%s" % count] = item["art"].get("fanart", "") WINDOW.setProperty(cachestr, repr(artwork).encode("utf-8")) if artwork: preferred_type = params.get("type", "") if preferred_type: image = artwork.get(preferred_type, "") else: image = artwork.get("poster", "") # set fallback image if nothing else worked if not image and fallback: image = fallback if image: self.send_response(200) if ".jpg" in image: self.send_header("Content-type", "image/jpg") elif image.lower().endswith(".gif"): self.send_header("Content-type", "image/gif") else: self.send_header("Content-type", "image/png") logMsg("found image for request %s --> %s" % (try_encode(self.path), try_encode(image))) st = xbmcvfs.Stat(image) modified = st.st_mtime() self.send_header("Last-Modified", "%s" % modified) image = xbmcvfs.File(image) size = image.size() self.send_header("Content-Length", str(size)) self.end_headers() else: self.send_error(404) return image, None
if __name__ == '__main__': ##### Music Artwork ######## logMsg("Context menu artwork settings for PVR artwork",0) WINDOW.setProperty("artworkcontextmenu", "busy") options=[] options.append(ADDON.getLocalizedString(32144)) #Refresh item (auto lookup) options.append(ADDON.getLocalizedString(32157)) #cache all artwork options.append(ADDON.getLocalizedString(32126)) #Reset Cache options.append(ADDON.getLocalizedString(32148)) #Open addon settings header = ADDON.getLocalizedString(32143) + " - " + ADDON.getLocalizedString(32122) ret = xbmcgui.Dialog().select(header, options) if ret == 0: #refresh item artwork = artworkutils.getMusicArtwork(xbmc.getInfoLabel("ListItem.Artist").decode('utf-8'),xbmc.getInfoLabel("ListItem.Album").decode('utf-8'),xbmc.getInfoLabel("ListItem.Title").decode('utf-8'),ignoreCache=True) #clear properties WINDOW.clearProperty("SkinHelper.Music.Banner") WINDOW.clearProperty("SkinHelper.Music.ClearLogo") WINDOW.clearProperty("SkinHelper.Music.DiscArt") WINDOW.clearProperty("SkinHelper.Music.FanArt") WINDOW.clearProperty("SkinHelper.Music.Thumb") WINDOW.clearProperty("SkinHelper.Music.Info") WINDOW.clearProperty("SkinHelper.Music.TrackList") WINDOW.clearProperty("SkinHelper.Music.SongCount") WINDOW.clearProperty("SkinHelper.Music.albumCount") WINDOW.clearProperty("SkinHelper.Music.AlbumList") WINDOW.clearProperty("SkinHelper.Music.ExtraFanArt") #set new properties
logMsg("Context menu artwork settings for PVR artwork", 0) WINDOW.setProperty("artworkcontextmenu", "busy") options = [] options.append( ADDON.getLocalizedString(32144)) #Refresh item (auto lookup) options.append(ADDON.getLocalizedString(32157)) #cache all artwork options.append(ADDON.getLocalizedString(32126)) #Reset Cache options.append(ADDON.getLocalizedString(32148)) #Open addon settings header = ADDON.getLocalizedString( 32143) + " - " + ADDON.getLocalizedString(32122) ret = xbmcgui.Dialog().select(header, options) if ret == 0: #refresh item artwork = artworkutils.getMusicArtwork( xbmc.getInfoLabel("ListItem.Artist").decode('utf-8'), xbmc.getInfoLabel("ListItem.Album").decode('utf-8'), xbmc.getInfoLabel("ListItem.Title").decode('utf-8'), ignoreCache=True) #clear properties WINDOW.clearProperty("SkinHelper.Music.Banner") WINDOW.clearProperty("SkinHelper.Music.ClearLogo") WINDOW.clearProperty("SkinHelper.Music.DiscArt") WINDOW.clearProperty("SkinHelper.Music.FanArt") WINDOW.clearProperty("SkinHelper.Music.Thumb") WINDOW.clearProperty("SkinHelper.Music.Info") WINDOW.clearProperty("SkinHelper.Music.TrackList") WINDOW.clearProperty("SkinHelper.Music.SongCount") WINDOW.clearProperty("SkinHelper.Music.albumCount") WINDOW.clearProperty("SkinHelper.Music.AlbumList") WINDOW.clearProperty("SkinHelper.Music.ExtraFanArt")