def get_predictions(self, search_str): """ get dict list with autocomplete labels from locally saved lists """ self.listitems = [] json_result = "" json_result2 = "" Donnees = None MaxItems = 50 RecherchePartout = xbmc.getCondVisibility( "Skin.HasSetting(AutoCompleteTous)") if self.PurgeCache and SETTING("autocomplete_cache") == "true": logMsg("purge_cache ") self.create_cache() if len(search_str) > 3: if SETTING("autocomplete_cache") == "true": if not self.PurgeCache: self.create_cache() #logMsg("basetype (%s)" %self.basetype) #if self.basetype=="videos" or RecherchePartout: if not xbmc.getCondVisibility("Window.IsVisible(10040)"): if RecherchePartout or xbmc.getCondVisibility( "Skin.HasSetting(AutoCompleteFilms)"): json_result = utils.GetCache(search_str, cache_path + "films") if json_result: self.createlistitems(json_result, "movie") if RecherchePartout or xbmc.getCondVisibility( "Skin.HasSetting(AutoCompletetvshows)"): json_result = utils.GetCache(search_str, cache_path + "tvshows") if json_result: self.createlistitems(json_result, "tvshow") #http://127.0.0.1:8080/jsonrpc?request={"jsonrpc":"2.0","method":"VideoLibrary.GetEpisodes","params":{"limits":{"end":2},"filter":{"field":"title","operator":"contains","value":"the"},"properties":["title","tvshowid"]},"id":"1"} json_result = utils.GetCache(search_str, cache_path + "episodes") if json_result: self.createlistitems(json_result, "episode") if RecherchePartout or xbmc.getCondVisibility( "Skin.HasSetting(AutoCompleteActeurs)"): #http://127.0.0.1:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Files.GetDirectory","params":{"directory":"videodb://movies/actors","limits":{"end":4}},"id":1} json_result = utils.GetCache(search_str, cache_path + "acteurs") if json_result: ListeActorsMovie = [] ListeActorsTvShow = [] recherche = search_str.lower() for item in json_result: if recherche in item["label"].lower(): if item.get("actormovieid"): ListeActorsMovie.append({ "actormovieid": item.get("actormovieid"), "label": item["label"] }) if item.get("actortvshowid"): ListeActorsTvShow.append({ "actortvshowid": item.get("actortvshowid"), "label": item["label"] }) if len(ListeActorsMovie) > 0: self.createlistitems(ListeActorsMovie, "actormovie") if len(ListeActorsTvShow) > 0: self.createlistitems(ListeActorsTvShow, "actortvshow") #json_result = utils.getJSON("Files.GetDirectory", '{"directory":"videodb://tvshows/actors"}') """ json_result=utils.GetCache("") if json_result: ListeActors=[] recherche=search_str.lower() for item in json_result: if recherche in item["label"].lower(): ListeActors.append({"actortvshowid":item.get("id"),"label":item["label"]}) if len(ListeActors)>0: self.createlistitems(ListeActors,"actortvshow") """ if RecherchePartout or xbmc.getCondVisibility( "Skin.HasSetting(AutoCompleteRealisateurs)"): #http://127.0.0.1:8080/jsonrpc?request={"jsonrpc":"2.0","method":"Files.GetDirectory","params":{"directory":"videodb://movies/directors","limits":{"end":4}},"id":1} json_result = utils.GetCache(search_str, cache_path + "realisateurs") if json_result: Listedirectors = [] recherche = search_str.lower() for item in json_result: if recherche in item["label"].lower(): Listedirectors.append({ "directormovieid": item.get("directormovieid"), "label": item["label"] }) if len(Listedirectors) > 0: self.createlistitems(Listedirectors, "directormovie") #json_result = utils.getJSON("Files.GetDirectory", '{"directory":"videodb://tvshows/directors"}') """ json_result=utils.GetCache(search_str,cache_path+"realisateurs") if json_result: Listedirectors=[] recherche=search_str.lower() for item in json_result: if recherche in item["label"].lower(): Listedirectors.append({"directortvshowid":item.get("id"),"label":item["label"]}) if len(Listedirectors)>0: self.createlistitems(Listedirectors,"directortvshow") """ #if self.basetype=="music" or RecherchePartout: #http://127.0.0.1:8080/jsonrpc?request={"jsonrpc":"2.0","method":"AudioLibrary.GetArtists","params":{"limits":{"end":2},"filter":{"field":"artist","operator":"contains","value":"madon"}},"id":"1"} #http://127.0.0.1:8080/jsonrpc?request={"jsonrpc":"2.0","method":"AudioLibrary.GetAlbums","params":{"limits":{"end":2},"filter":{"field":"album","operator":"contains","value":"Fear"}},"id":"1"} if RecherchePartout or xbmc.getCondVisibility( "Skin.HasSetting(AutoCompleteArtistes)"): json_result = utils.GetCache(search_str, cache_path + "artistes") if json_result: self.createlistitems(json_result, "artist") if RecherchePartout or xbmc.getCondVisibility( "Skin.HasSetting(AutoCompleteAlbums)"): json_result = utils.GetCache(search_str, cache_path + "albums") if json_result: self.createlistitems(json_result, "album") else: json_result = utils.GetCache(search_str, cache_path + "addons") if json_result: self.createlistitems(json_result, "addon") #logMsg("Items (%s)" %self.listitems) LL = [] #if (SETTING("autocomplete_tri")=="titre" or xbmc.getCondVisibility("Skin.HasSetting(AutoCompleteTriTitre)")) and not xbmc.getCondVisibility("Skin.HasSetting(AutoCompleteTriCategorie)"): if xbmc.getCondVisibility("Skin.HasSetting(AutoCompleteTriTitre)"): #LL=sorted(self.listitems,key=operator.itemgetter('label')) LL = sorted(self.listitems, key=lambda x: (x['label'])) #logMsg("tri par titre") else: #LL=sorted(self.listitems,key=operator.itemgetter('dbtype')) LL = sorted(self.listitems, key=lambda x: (x['dbtype'], x['label'])) #logMsg("tri par categorie") return LL
def create_cache(self): updateActorMovie = None updateActorTvShow = None updateDirectorMovie = None #--- ---------------CACHE ---------------------------------------------- Titre = None self.dp = None self.GlobalCache = utils.GetCache(None, cache_path + "total") if self.check_update( WINDOW.getProperty("Movies.count"), "films") or not xbmcvfs.exists(cache_path + "films") or self.PurgeCache: self.dpupdate(0, "Films") json_result = utils.getJSON("VideoLibrary.GetMovies", '{"properties":["setid"]}') self.Data["resultats"] = json_result utils.SaveFile(cache_path + "films", self.Data) self.GlobalCache["films"] = self.Data.get("total") updateActorMovie = True if self.check_update( WINDOW.getProperty("TVShows.count"), "tvshows") or not xbmcvfs.exists(cache_path + "tvshows") or self.PurgeCache: self.dpupdate(16, "tvshows") json_result = utils.getJSON("VideoLibrary.GetTvShows", '{"properties":["episode"]}') self.Data["resultats"] = json_result utils.SaveFile(cache_path + "tvshows", self.Data) self.GlobalCache["tvshows"] = self.Data.get("total") updateActorTvShow = True if self.check_update( WINDOW.getProperty("Episodes.count"), "episodes" ) or not xbmcvfs.exists(cache_path + "episodes") or self.PurgeCache: self.dpupdate(32, "Episodes") json_result = utils.getJSON("VideoLibrary.GetEpisodes", '{"properties":["tvshowid"]}') self.Data["resultats"] = json_result utils.SaveFile(cache_path + "episodes", self.Data) self.GlobalCache["episodes"] = self.Data.get("total") ListeActors = [] if updateActorMovie or not xbmcvfs.exists( cache_path + "acteurs") or self.PurgeCache: self.dpupdate(48, "Acteurs") json_result = utils.getJSON( "Files.GetDirectory", '{"directory":"videodb://movies/actors"}') if json_result: for item in json_result: ListeActors.append({ "actormovieid": item.get("id"), "label": item["label"] }) self.GlobalCache["actormovie"] = len(ListeActors) if updateActorTvShow or not xbmcvfs.exists( cache_path + "acteurs") or self.PurgeCache: self.dpupdate(58, "Acteurs") json_result = utils.getJSON( "Files.GetDirectory", '{"directory":"videodb://tvshows/actors"}') if json_result: for item in json_result: ListeActors.append({ "actortvshowid": item.get("id"), "label": item["label"] }) self.GlobalCache["actortv"] = len(ListeActors) self.Data["resultats"] = ListeActors utils.SaveFile(cache_path + "acteurs", self.Data) Listedirectors = [] if updateActorMovie or not xbmcvfs.exists( cache_path + "realisateurs") or self.PurgeCache: self.dpupdate(64, "Realisateurs") json_result = utils.getJSON( "Files.GetDirectory", '{"directory":"videodb://movies/directors"}') if json_result: for item in json_result: Listedirectors.append({ "directormovieid": item.get("id"), "label": item["label"] }) self.GlobalCache["directormovie"] = len(Listedirectors) if updateActorTvShow or not xbmcvfs.exists( cache_path + "realisateurs") or self.PurgeCache: json_result = utils.getJSON( "Files.GetDirectory", '{"directory":"videodb://tvshows/directors"}') if json_result: for item in json_result: Listedirectors.append({ "directortvshowid": item.get("id"), "label": item["label"] }) self.GlobalCache["directortv"] = len(Listedirectors) self.Data["resultats"] = Listedirectors utils.SaveFile(cache_path + "realisateurs", self.Data) if self.check_update( WINDOW.getProperty("Music.Artistscount"), "artistes" ) or not xbmcvfs.exists(cache_path + "artistes") or self.PurgeCache: self.dpupdate(80, "Artistes") json_result = utils.getJSON("AudioLibrary.GetArtists", '{}') self.Data["resultats"] = json_result utils.SaveFile(cache_path + "artistes", self.Data) self.GlobalCache["artistes"] = self.Data.get("total") if self.check_update( WINDOW.getProperty("Music.Albumscount"), "albums") or not xbmcvfs.exists(cache_path + "albums") or self.PurgeCache: self.dpupdate(96, "Albums") json_result = utils.getJSON("AudioLibrary.GetAlbums", '{"properties":["artistid"]}') self.Data["resultats"] = json_result utils.SaveFile(cache_path + "albums", self.Data) self.GlobalCache["albums"] = self.Data.get("total") if (xbmc.getCondVisibility("Window.IsVisible(10040)") and not xbmcvfs.exists(cache_path + "addons")) or self.PurgeCache: self.dpupdate(99, "Addons") json_result = utils.getJSON("Addons.GetAddons", '{"properties":["name"]}') Listeaddons = [] if json_result: for item in json_result: Listeaddons.append({ "addonid": item.get("addonid"), "label": item["name"], "type": item["type"] }) self.Data["resultats"] = Listeaddons utils.SaveFile(cache_path + "addons", self.Data) self.GlobalCache["addons"] = len(Listeaddons) GlobalSave = {} GlobalSave["resultats"] = self.GlobalCache utils.SaveFile(cache_path + "total", GlobalSave) self.PurgeCache = None if self.dp: self.dp.close()