def get_movies(movie_type): movies = ItemList(content_type="movies") url = '%s.json?apikey=%s' % (movie_type, RT_KEY) results = utils.get_JSON_response(BASE_URL + url, folder="RottenTomatoes") if "error" in results: utils.notify("Error", results["error"]) if not results or "movies" not in results: return [] for item in results["movies"]: if "alternate_ids" not in item: continue imdb_id = str(item["alternate_ids"]["imdb"]) if addon.bool_setting("infodialog_onclick"): path = PLUGIN_BASE + 'extendedinfo&&imdb_id=%s' % imdb_id else: search_string = "%s %s trailer" % (item["title"], item["year"]) path = PLUGIN_BASE + "playtrailer&&title=%s&&imdb_id=%s" % (search_string, imdb_id) movie = VideoItem(label=item.get('title'), path=path) movie.set_infos({'title': item["title"], 'mediatype': "movie", 'duration': item["runtime"] * 60, 'year': item["year"], 'premiered': item["release_dates"].get("theater", ""), 'rating': item["ratings"]["audience_score"] / 10.0, 'plot': item["synopsis"], 'imdbnumber': imdb_id, 'mpaa': item["mpaa_rating"]}) movie.set_properties({'imdb_id': imdb_id}) movie.set_artwork({'thumb': item["posters"]["original"], 'poster': item["posters"]["original"]}) movies.append(movie) return local_db.merge_with_local(media_type="movie", items=movies, library_first=False)
def decorator(cls, *args, **kwargs): self.show_busy() result = None try: result = func(cls, *args, **kwargs) except Exception: utils.log(traceback.format_exc()) utils.notify("Error", "please contact add-on author") finally: self.hide_busy() return result
def open_dialog(self, dialog, prev_window): if dialog.info: self.active_dialog = dialog check_version() if prev_window: self.add_to_stack(prev_window) prev_window.close() dialog.doModal() else: self.active_dialog = None utils.notify(addon.LANG(32143))
def search_location(self): self.location = xbmcgui.Dialog().input(heading=addon.LANG(32032), type=xbmcgui.INPUT_ALPHANUM) if not self.location: return None self.street_view = False data = googlemaps.get_coords_by_location(True, self.location) if data: self.lat, self.lon, self.zoom = data else: utils.notify("Error", "No Search results found.")
def get_string_from_url(url): for i in range(0, 3): try: request = urllib2.Request(url) request.add_header('User-agent', 'XBMC/14.2 ( [email protected] )') response = urllib2.urlopen(request, timeout=3) return response.read() except: xbmc.sleep(500) utils.notify("Error", "Could not download data. Internet connection OK?") utils.log("get_string_from_url: could not get data from %s" % url) return ""
def fetch_data(self, force=False): # TODO: rewrite sort_by = self.sort + "." + self.order temp = "tv" if self.type == "tv" else "movies" if self.mode == "search": self.filter_label = addon.LANG( 32146) % self.search_str if self.search_str else "" return tmdb.multi_search(search_str=self.search_str, page=self.page, cache_days=0 if force else 2) elif self.mode == "list": xbmc.log("fetching list of movies...........", 2) return tmdb.get_list_movies(list_id=self.list_id, force=force) elif self.mode == "favorites": self.filter_label = addon.LANG( 32144) if self.type == "tv" else addon.LANG(32134) return tmdb.get_fav_items(media_type=temp, sort_by=sort_by, page=self.page) elif self.mode == "rating": self.filter_label = addon.LANG( 32145) if self.type == "tv" else addon.LANG(32135) return tmdb.get_rated_media_items(media_type=temp, sort_by=sort_by, page=self.page, cache_days=0) else: self.set_filter_label() params = { "sort_by": sort_by, "language": addon.setting("LanguageID"), "page": self.page, "include_adult": include_adult } filters = {item["type"]: item["id"] for item in self.filters} response = tmdb.get_data(url="discover/%s" % (self.type), params=utils.merge_dicts( params, filters), cache_days=0 if force else 2) if not response["results"]: utils.notify(addon.LANG(284)) return None if self.type == "movie": itemlist = tmdb.handle_movies(results=response["results"], local_first=False, sortkey=None) else: itemlist = tmdb.handle_tvshows(results=response["results"], local_first=False, sortkey=None) itemlist.set_totals(response["total_results"]) itemlist.set_total_pages(response["total_pages"]) return itemlist
def fetch_data(self, force=False): # TODO: rewrite sort_by = self.sort + "." + self.order temp = "tv" if self.type == "tv" else "movies" if self.mode == "search": self.filter_label = addon.LANG(32146) % self.search_str if self.search_str else "" return tmdb.multi_search(search_str=self.search_str, page=self.page, cache_days=0 if force else 2) elif self.mode == "list": return tmdb.get_list_movies(list_id=self.list_id, force=force) elif self.mode == "favorites": self.filter_label = addon.LANG(32144) if self.type == "tv" else addon.LANG(32134) return tmdb.get_fav_items(media_type=temp, sort_by=sort_by, page=self.page) elif self.mode == "rating": self.filter_label = addon.LANG(32145) if self.type == "tv" else addon.LANG(32135) return tmdb.get_rated_media_items(media_type=temp, sort_by=sort_by, page=self.page, cache_days=0) else: self.set_filter_label() params = {"sort_by": sort_by, "language": addon.setting("LanguageID"), "page": self.page, "include_adult": include_adult} filters = {item["type"]: item["id"] for item in self.filters} response = tmdb.get_data(url="discover/%s" % (self.type), params=utils.merge_dicts(params, filters), cache_days=0 if force else 2) if not response["results"]: utils.notify(addon.LANG(284)) return None if self.type == "movie": itemlist = tmdb.handle_movies(results=response["results"], local_first=False, sortkey=None) else: itemlist = tmdb.handle_tvshows(results=response["results"], local_first=False, sortkey=None) itemlist.set_totals(response["total_results"]) itemlist.set_total_pages(response["total_pages"]) return itemlist
def get_places(self, lat, lon, query="", category_id=""): params = {"limit": 26, "ll": '%.8f,%.8f' % (lat, lon), "query": query, "categoryId": category_id} results = self.get_data(method="venues/search", params=params, cache_days=7) if results and 'meta' in results: if results['meta']['code'] == 200: return self.handle_places(results['response']['venues']) elif results['meta']['code'] == 400: utils.notify("Error", "LIMIT EXCEEDED") else: utils.notify("ERROR", "Could not get requested information") else: utils.log("ERROR") return []
def set_company_filter(self, control_id): result = xbmcgui.Dialog().input(heading=addon.LANG(16017), type=xbmcgui.INPUT_ALPHANUM) if not result or result < 0: return None items = tmdb.search_companies(result) if len(items) > 1: index = selectdialog.open(header=addon.LANG(32151), listitems=items) if index > -1: item = items[index] elif items: item = items[0] else: utils.notify("No company found") self.add_filter(key="with_companies", value=item.get_property("id"), label=item.get_label())
def set_company_filter(self, control_id): result = xbmcgui.Dialog().input(heading=addon.LANG(16017), type=xbmcgui.INPUT_ALPHANUM) if not result or result < 0: return None response = tmdb.search_company(result) if len(response) > 1: selection = xbmcgui.Dialog().select(heading=addon.LANG(32151), list=[i["name"] for i in response]) if selection > -1: response = response[selection] elif response: response = response[0] else: utils.notify("No company found") self.add_filter(key="with_companies", value=str(response["id"]), typelabel=addon.LANG(20388), label=response["name"])
def get_places_by_section(self, lat, lon, placetype): params = {"venuePhotos": 1, "ll": '%.8f,%.8f' % (float(lat), float(lon)), "section": placetype} results = self.get_data(method="venues/explore", params=params, cache_days=7) if not results or 'meta' not in results: return [] if results['meta']['code'] == 200: if results['response']['groups'][0]['items']: return self.handle_places(results['response']['groups'][0]['items']) else: utils.notify("Error", "No results found near the selected area.") elif results['meta']['code'] == 400: utils.log("LIMIT EXCEEDED") else: utils.log("ERROR" + str(results['meta']['code'])) return []
def set_company_filter(self, control_id): result = xbmcgui.Dialog().input(heading=addon.LANG(16017), type=xbmcgui.INPUT_ALPHANUM) if not result or result < 0: return None response = tmdb.search_company(result) if len(response) > 1: selection = xbmcgui.Dialog().select( heading=addon.LANG(32151), list=[i["name"] for i in response]) if selection > -1: response = response[selection] elif response: response = response[0] else: utils.notify("No company found") self.add_filter(key="with_companies", value=str(response["id"]), typelabel=addon.LANG(20388), label=response["name"])
def play_youtube_video(self, youtube_id="", listitem=None): """ play youtube vid with info from *listitem """ url, yt_listitem = player.youtube_info_by_id(youtube_id) if not listitem: listitem = yt_listitem if not url: utils.notify(header=addon.LANG(257), message="no youtube id found") return None if self.active_dialog and self.active_dialog.window_type == "dialog": self.active_dialog.close() xbmc.executebuiltin("Dialog.Close(movieinformation)") xbmc.Player().play(item=url, listitem=listitem, windowed=False, startpos=-1) if self.active_dialog and self.active_dialog.window_type == "dialog": player.wait_for_video_end() self.active_dialog.doModal()
def get_incidents(lat, lon, zoom): lat_high, lon_high, lat_low, lon_low = Utils.get_bounding_box(lat, lon, zoom) params = {"key": MAPQUEST_KEY, "inFormat": "kvp", "boundingBox": "%s,%s,%s,%s" % (lat_high, lon_high, lat_low, lon_low)} url = BASE_URL + 'incidents?' + urllib.urlencode(params) results = Utils.get_JSON_response(url) places = ItemList() if results['info']['statuscode'] == 400: utils.notify("Error", " - ".join(results['info']['messages']), time=10000) return [] elif "incidents" not in results: utils.notify("Error", "Could not fetch results") return [] for place in results['incidents'][:MAX_LIMIT]: lat = str(place['lat']) lon = str(place['lng']) params = {"key": MAPQUEST_KEY, "mapLat": place['lat'], "mapLng": place['lng'], "mapHeight": 400, "mapWidth": 400, "mapScale": 433342} url = BASE_URL + "flow?" + urllib.urlencode(params) item = VideoItem(label=place['shortDesc'], label2=place['startTime']) item.set_properties({'name': place['shortDesc'], 'description': place['fullDesc'], 'distance': str(place['distance']), 'delaytypical': str(place['delayFromTypical']), 'delayfreeflow': str(place['delayFromFreeFlow']), 'date': place['startTime'], 'severity': str(place['severity']), 'type': incident_types.get(place['type'], ""), "lat": lat, "lon": lon}) item.set_artwork({"thumb": url, "icon": place['iconURL'], "googlemap": googlemaps.get_static_map(lat=lat, lon=lon)}) places.append(item) return places
def play_youtube_video(self, youtube_id="", listitem=None, window=False): """ play youtube vid with info from *listitem """ url, yt_listitem = player.youtube_info_by_id(youtube_id) if not listitem: listitem = yt_listitem if url: if window and window.window_type == "dialog": self.add_to_stack(window) window.close() xbmc.executebuiltin("Dialog.Close(movieinformation)") xbmc.Player().play(item=url, listitem=listitem, windowed=False, startpos=-1) if window and window.window_type == "dialog": player.wait_for_video_end() self.pop_stack() else: utils.notify(header=addon.LANG(257), message="no youtube id found")
def start_info_actions(info, params): if "artistname" in params: params["artistname"] = params.get("artistname", "").split(" feat. ")[0].strip() params["artist_mbid"] = utils.fetch_musicbrainz_id(params["artistname"]) utils.log(info) utils.pp(params) if "prefix" in params and not params["prefix"].endswith('.'): params["prefix"] = params["prefix"] + '.' # Audio if info == 'discography': discography = AudioDB.get_artist_discography(params["artistname"]) if not discography: discography = LastFM.get_artist_albums(params.get("artist_mbid")) return discography elif info == 'mostlovedtracks': return AudioDB.get_most_loved_tracks(params["artistname"]) elif info == 'trackdetails': return AudioDB.get_track_details(params.get("id", "")) elif info == 'topartists': return LastFM.get_top_artists() # RottenTomatoesMovies elif info == 'intheatermovies': return RottenTomatoes.get_movies("movies/in_theaters") elif info == 'boxofficemovies': return RottenTomatoes.get_movies("movies/box_office") elif info == 'openingmovies': return RottenTomatoes.get_movies("movies/opening") elif info == 'comingsoonmovies': return RottenTomatoes.get_movies("movies/upcoming") elif info == 'toprentalmovies': return RottenTomatoes.get_movies("dvds/top_rentals") elif info == 'currentdvdmovies': return RottenTomatoes.get_movies("dvds/current_releases") elif info == 'newdvdmovies': return RottenTomatoes.get_movies("dvds/new_releases") elif info == 'upcomingdvdmovies': return RottenTomatoes.get_movies("dvds/upcoming") # The MovieDB elif info == 'incinemamovies': return tmdb.get_tmdb_movies("now_playing") elif info == 'upcomingmovies': return tmdb.get_tmdb_movies("upcoming") elif info == 'topratedmovies': return tmdb.get_tmdb_movies("top_rated") elif info == 'popularmovies': return tmdb.get_tmdb_movies("popular") elif info == 'ratedmovies': return tmdb.get_rated_media_items("movies") elif info == 'starredmovies': return tmdb.get_fav_items("movies") elif info == 'accountlists': account_lists = tmdb.handle_misc(tmdb.get_account_lists()) for item in account_lists: item["directory"] = True return account_lists elif info == 'listmovies': return tmdb.get_movies_from_list(params["id"]) elif info == 'airingtodaytvshows': return tmdb.get_tmdb_shows("airing_today") elif info == 'onairtvshows': return tmdb.get_tmdb_shows("on_the_air") elif info == 'topratedtvshows': return tmdb.get_tmdb_shows("top_rated") elif info == 'populartvshows': return tmdb.get_tmdb_shows("popular") elif info == 'ratedtvshows': return tmdb.get_rated_media_items("tv") elif info == 'ratedepisodes': return tmdb.get_rated_media_items("tv/episodes") elif info == 'starredtvshows': return tmdb.get_fav_items("tv") elif info == 'similarmovies': movie_id = params.get("id") if not movie_id: movie_id = tmdb.get_movie_tmdb_id(imdb_id=params.get("imdb_id"), dbid=params.get("dbid")) if movie_id: return tmdb.get_similar_movies(movie_id) elif info == 'similartvshows': tvshow_id = None dbid = params.get("dbid") name = params.get("name") tmdb_id = params.get("tmdb_id") tvdb_id = params.get("tvdb_id") imdb_id = params.get("imdb_id") if tmdb_id: tvshow_id = tmdb_id elif dbid and int(dbid) > 0: tvdb_id = local_db.get_imdb_id("tvshow", dbid) if tvdb_id: tvshow_id = tmdb.get_show_tmdb_id(tvdb_id) elif tvdb_id: tvshow_id = tmdb.get_show_tmdb_id(tvdb_id) elif imdb_id: tvshow_id = tmdb.get_show_tmdb_id(imdb_id, "imdb_id") elif name: tvshow_id = tmdb.search_media(media_name=name, year="", media_type="tv") if tvshow_id: return tmdb.get_similar_tvshows(tvshow_id) elif info == 'studio': if params.get("id"): return tmdb.get_company_data(params["id"]) elif params.get("studio"): company_data = tmdb.search_company(params["studio"]) if company_data: return tmdb.get_company_data(company_data[0]["id"]) elif info == 'set': if params.get("dbid"): name = local_db.get_set_name(params["dbid"]) if name: params["setid"] = tmdb.get_set_id(name) if params.get("setid"): set_data, _ = tmdb.get_set_movies(params["setid"]) return set_data elif info == 'movielists': movie_id = params.get("id") if not movie_id: movie_id = tmdb.get_movie_tmdb_id(imdb_id=params.get("imdb_id"), dbid=params.get("dbid")) if movie_id: return tmdb.get_movie_lists(movie_id) elif info == 'keywords': movie_id = params.get("id") if not movie_id: movie_id = tmdb.get_movie_tmdb_id(imdb_id=params.get("imdb_id"), dbid=params.get("dbid")) if movie_id: return tmdb.get_keywords(movie_id) elif info == 'popularpeople': return tmdb.get_popular_actors() elif info == 'personmovies': person = tmdb.get_person_info(person_label=params.get("person"), skip_dialog=True) if person and person.get("id"): movies = tmdb.get_person_movies(person["id"]) for item in movies: del item["credit_id"] return utils.reduce_list(movies, key="department") elif info == 'traktsimilarmovies': if params.get("id") or params.get("dbid"): if params.get("dbid"): movie_id = local_db.get_imdb_id("movie", params["dbid"]) else: movie_id = params["id"] return Trakt.get_similar("movie", movie_id) elif info == 'traktsimilartvshows': if params.get("id") or params.get("dbid"): if params.get("dbid"): if params.get("type") == "episode": tvshow_id = local_db.get_tvshow_id_by_episode(params["dbid"]) else: tvshow_id = local_db.get_imdb_id(media_type="tvshow", dbid=params["dbid"]) else: tvshow_id = params["id"] return Trakt.get_similar("show", tvshow_id) elif info == 'airingepisodes': return Trakt.get_episodes("shows") elif info == 'premiereepisodes': return Trakt.get_episodes("premieres") elif info == 'trendingshows': return Trakt.get_shows("trending") elif info == 'popularshows': return Trakt.get_shows("popular") elif info == 'anticipatedshows': return Trakt.get_shows("anticipated") elif info == 'mostcollectedshows': return Trakt.get_shows_from_time("collected") elif info == 'mostplayedshows': return Trakt.get_shows_from_time("played") elif info == 'mostwatchedshows': return Trakt.get_shows_from_time("watched") elif info == 'trendingmovies': return Trakt.get_movies("trending") elif info == 'traktpopularmovies': return Trakt.get_movies("popular") elif info == 'mostplayedmovies': return Trakt.get_movies_from_time("played") elif info == 'mostwatchedmovies': return Trakt.get_movies_from_time("watched") elif info == 'mostcollectedmovies': return Trakt.get_movies_from_time("collected") elif info == 'mostanticipatedmovies': return Trakt.get_movies("anticipated") elif info == 'traktboxofficemovies': return Trakt.get_movies("boxoffice") elif info == 'similarartistsinlibrary': return local_db.get_similar_artists(params.get("artist_mbid")) elif info == 'trackinfo': addon.clear_global('%sSummary' % params.get("prefix", "")) if params["artistname"] and params["trackname"]: track_info = LastFM.get_track_info(artist_name=params["artistname"], track=params["trackname"]) addon.set_global('%sSummary' % params.get("prefix", ""), track_info["summary"]) elif info == 'topartistsnearevents': artists = local_db.get_artists() import BandsInTown return BandsInTown.get_near_events(artists[0:49]) elif info == 'youtubesearchvideos': addon.set_global('%sSearchValue' % params.get("prefix", ""), params.get("id", "")) if params.get("id"): listitems = YouTube.search(search_str=params.get("id", ""), hd=params.get("hd"), orderby=params.get("orderby", "relevance")) return listitems.get("listitems", []) elif info == 'youtubeplaylistvideos': return YouTube.get_playlist_videos(params.get("id", "")) elif info == 'youtubeusersearchvideos': user_name = params.get("id") if user_name: playlists = YouTube.get_user_playlists(user_name) return YouTube.get_playlist_videos(playlists["uploads"]) elif info == 'favourites': if params.get("id"): items = favs.get_favs_by_type(params["id"]) else: items = favs.get_favs() addon.set_global('favourite.count', str(len(items))) if items: addon.set_global('favourite.1.name', items[-1]["label"]) return items elif info == 'similarlocalmovies' and "dbid" in params: return local_db.get_similar_movies(params["dbid"]) elif info == 'iconpanel': return favs.get_icon_panel(int(params["id"])), "IconPanel" + str(params["id"]) # ACTIONS if params.get("handle"): xbmcplugin.setResolvedUrl(handle=int(params.get("handle")), succeeded=False, listitem=xbmcgui.ListItem()) if info in ['playmovie', 'playepisode', 'playmusicvideo', 'playalbum', 'playsong']: kodijson.play_media(media_type=info.replace("play", ""), dbid=params.get("dbid"), resume=params.get("resume", "true")) elif info == "openinfodialog": if xbmc.getCondVisibility("System.HasModalDialog"): container_id = "" else: container_id = "Container(%s)" % utils.get_infolabel("System.CurrentControlId") dbid = utils.get_infolabel("%sListItem.DBID" % container_id) db_type = utils.get_infolabel("%sListItem.DBType" % container_id) if db_type == "movie": params = {"dbid": dbid, "id": utils.get_infolabel("%sListItem.Property(id)" % container_id), "name": utils.get_infolabel("%sListItem.Title" % container_id)} start_info_actions("extendedinfo", params) elif db_type == "tvshow": params = {"dbid": dbid, "tvdb_id": utils.get_infolabel("%sListItem.Property(tvdb_id)" % container_id), "id": utils.get_infolabel("%sListItem.Property(id)" % container_id), "name": utils.get_infolabel("%sListItem.Title" % container_id)} start_info_actions("extendedtvinfo", params) elif db_type == "season": params = {"tvshow": utils.get_infolabel("%sListItem.TVShowTitle" % container_id), "season": utils.get_infolabel("%sListItem.Season" % container_id)} start_info_actions("seasoninfo", params) elif db_type == "episode": params = {"tvshow": utils.get_infolabel("%sListItem.TVShowTitle" % container_id), "season": utils.get_infolabel("%sListItem.Season" % container_id), "episode": utils.get_infolabel("%sListItem.Episode" % container_id)} start_info_actions("extendedepisodeinfo", params) elif db_type in ["actor", "director"]: params = {"name": utils.get_infolabel("%sListItem.Label" % container_id)} start_info_actions("extendedactorinfo", params) else: utils.notify("Error", "Could not find valid content type") elif info == "ratedialog": if xbmc.getCondVisibility("System.HasModalDialog"): container_id = "" else: container_id = "Container(%s)" % utils.get_infolabel("System.CurrentControlId") dbid = utils.get_infolabel("%sListItem.DBID" % container_id) db_type = utils.get_infolabel("%sListItem.DBType" % container_id) if db_type == "movie": params = {"dbid": dbid, "id": utils.get_infolabel("%sListItem.Property(id)" % container_id), "type": "movie"} start_info_actions("ratemedia", params) elif db_type == "tvshow": params = {"dbid": dbid, "id": utils.get_infolabel("%sListItem.Property(id)" % container_id), "type": "tv"} start_info_actions("ratemedia", params) if db_type == "episode": params = {"tvshow": utils.get_infolabel("%sListItem.TVShowTitle" % container_id), "season": utils.get_infolabel("%sListItem.Season" % container_id), "type": "episode"} start_info_actions("ratemedia", params) elif info == 'youtubebrowser': wm.open_youtube_list(search_str=params.get("id", "")) elif info == 'moviedbbrowser': if addon.get_global('infodialogs.active'): return None addon.set_global('infodialogs.active', "true") search_str = params.get("id", "") if not search_str and params.get("search"): result = xbmcgui.Dialog().input(heading=addon.LANG(16017), type=xbmcgui.INPUT_ALPHANUM) if result and result > -1: search_str = result else: return None wm.open_video_list(search_str=search_str, mode="search") addon.clear_global('infodialogs.active') elif info == 'extendedinfo': if addon.get_global('infodialogs.active'): return None addon.set_global('infodialogs.active', "true") wm.open_movie_info(movie_id=params.get("id"), dbid=params.get("dbid"), imdb_id=params.get("imdb_id"), name=params.get("name")) addon.clear_global('infodialogs.active') elif info == 'extendedactorinfo': if addon.get_global('infodialogs.active'): return None addon.set_global('infodialogs.active', "true") wm.open_actor_info(actor_id=params.get("id"), name=params.get("name")) addon.clear_global('infodialogs.active') elif info == 'extendedtvinfo': if addon.get_global('infodialogs.active'): return None addon.set_global('infodialogs.active', "true") wm.open_tvshow_info(tmdb_id=params.get("id"), tvdb_id=params.get("tvdb_id"), dbid=params.get("dbid"), imdb_id=params.get("imdb_id"), name=params.get("name")) addon.clear_global('infodialogs.active') elif info == 'seasoninfo': if addon.get_global('infodialogs.active'): return None addon.set_global('infodialogs.active', "true") wm.open_season_info(tvshow=params.get("tvshow"), dbid=params.get("dbid"), season=params.get("season")) addon.clear_global('infodialogs.active') elif info == 'extendedepisodeinfo': if addon.get_global('infodialogs.active'): return None addon.set_global('infodialogs.active', "true") wm.open_episode_info(tvshow=params.get("tvshow"), tvshow_id=params.get("tvshow_id"), dbid=params.get("dbid"), episode=params.get("episode"), season=params.get("season")) addon.clear_global('infodialogs.active') elif info == 'albuminfo': if params.get("id"): album_details = AudioDB.get_album_details(params.get("id")) utils.dict_to_windowprops(album_details, params.get("prefix", "")) elif info == 'artistdetails': artist_details = AudioDB.get_artist_details(params["artistname"]) utils.dict_to_windowprops(artist_details, params.get("prefix", "")) elif info == 'ratemedia': media_type = params.get("type") if not media_type: return None if params.get("id"): tmdb_id = params["id"] elif media_type == "movie": tmdb_id = tmdb.get_movie_tmdb_id(imdb_id=params.get("imdb_id"), dbid=params.get("dbid"), name=params.get("name")) elif media_type == "tv" and params.get("dbid"): tvdb_id = local_db.get_imdb_id(media_type="tvshow", dbid=params["dbid"]) tmdb_id = tmdb.get_show_tmdb_id(tvdb_id=tvdb_id) else: return False rating = utils.input_userrating() tmdb.set_rating(media_type=media_type, media_id=tmdb_id, rating=rating, dbid=params.get("dbid")) elif info == 'action': for builtin in params.get("id", "").split("$$"): xbmc.executebuiltin(builtin) elif info == "youtubevideo": xbmc.executebuiltin("Dialog.Close(all,true)") wm.play_youtube_video(params.get("id", "")) elif info == 'playtrailer': wm.show_busy() if params.get("id"): movie_id = params["id"] elif int(params.get("dbid", -1)) > 0: movie_id = local_db.get_imdb_id(media_type="movie", dbid=params["dbid"]) elif params.get("imdb_id"): movie_id = tmdb.get_movie_tmdb_id(params["imdb_id"]) else: movie_id = "" if movie_id: trailer = tmdb.get_trailer(movie_id) wm.hide_busy() time.sleep(0.1) if trailer: wm.play_youtube_video(trailer) elif params.get("title"): wm.open_youtube_list(search_str=params["title"]) else: wm.hide_busy() elif info == 'deletecache': addon.clear_globals() for rel_path in os.listdir(addon.DATA_PATH): path = os.path.join(addon.DATA_PATH, rel_path) try: if os.path.isdir(path): shutil.rmtree(path) except Exception as e: utils.log(e) utils.notify("Cache deleted") elif info == 'syncwatchlist': pass
def fetch_data(self, force=False): # TODO: rewrite sort_by = self.sort + "." + self.order temp = "tv" if self.type == "tv" else "movies" if self.mode == "search": params = {"query": self.search_str, "include_adult": include_adult, "page": self.page} url = "search/multi" self.filter_label = addon.LANG(32146) % self.search_str if self.search_str else "" elif self.mode == "list": params = {"language": addon.setting("LanguageID")} url = "list/%s" % (self.list_id) # self.filter_label = addon.LANG(32036) elif self.mode == "favorites": params = {"sort_by": sort_by, "language": addon.setting("LanguageID"), "page": self.page, "session_id": tmdb.Login.get_session_id()} url = "account/%s/favorite/%s" % (tmdb.Login.get_account_id(), temp) self.filter_label = addon.LANG(32144) if self.type == "tv" else addon.LANG(32134) elif self.mode == "rating": force = True # workaround, should be updated after setting rating if self.logged_in: session_id = tmdb.Login.get_session_id() if not session_id: utils.notify("Could not get session id") return {"listitems": [], "results_per_page": 0, "total_results": 0} params = {"sort_by": sort_by, "language": addon.setting("LanguageID"), "page": self.page, "session_id": session_id} url = "account/%s/rated/%s" % (tmdb.Login.get_account_id(), temp) else: session_id = tmdb.Login.get_guest_session_id() if not session_id: utils.notify("Could not get session id") return {"listitems": [], "results_per_page": 0, "total_results": 0} params = {"language": addon.setting("LanguageID")} url = "guest_session/%s/rated_movies" % (session_id) self.filter_label = addon.LANG(32145) if self.type == "tv" else addon.LANG(32135) else: self.set_filter_label() params = {"sort_by": sort_by, "language": addon.setting("LanguageID"), "page": self.page, "include_adult": include_adult} filters = {item["type"]: item["id"] for item in self.filters} params = utils.merge_dicts(params, filters) url = "discover/%s" % (self.type) response = tmdb.get_data(url=url, params=params, cache_days=0 if force else 2) if not response: return None if self.mode == "list": info = {"listitems": tmdb.handle_movies(results=response["items"], local_first=True, sortkey=None), "results_per_page": 1, "total_results": len(response["items"])} return info if "results" not in response: # self.close() return {"listitems": [], "results_per_page": 0, "total_results": 0} if not response["results"]: utils.notify(addon.LANG(284)) if self.mode == "search": listitems = tmdb.handle_multi_search(response["results"]) elif self.type == "movie": listitems = tmdb.handle_movies(results=response["results"], local_first=False, sortkey=None) else: listitems = tmdb.handle_tvshows(results=response["results"], local_first=False, sortkey=None) info = {"listitems": listitems, "results_per_page": response["total_pages"], "total_results": response["total_results"]} return info
def open_infodialog(self, dialog): if dialog.info: self.open_dialog(dialog) else: self.active_dialog = None utils.notify(addon.LANG(32143))
def fetch_data(self, force=False): # TODO: rewrite sort_by = self.sort + "." + self.order temp = "tv" if self.type == "tv" else "movies" if self.mode == "search": params = { "query": self.search_str, "include_adult": include_adult, "page": self.page } url = "search/multi" self.filter_label = addon.LANG( 32146) % self.search_str if self.search_str else "" elif self.mode == "list": params = {"language": addon.setting("LanguageID")} url = "list/%s" % (self.list_id) # self.filter_label = addon.LANG(32036) elif self.mode == "favorites": params = { "sort_by": sort_by, "language": addon.setting("LanguageID"), "page": self.page, "session_id": tmdb.Login.get_session_id() } url = "account/%s/favorite/%s" % (tmdb.Login.get_account_id(), temp) self.filter_label = addon.LANG( 32144) if self.type == "tv" else addon.LANG(32134) elif self.mode == "rating": force = True # workaround, should be updated after setting rating if self.logged_in: session_id = tmdb.Login.get_session_id() if not session_id: utils.notify("Could not get session id") return { "listitems": [], "results_per_page": 0, "total_results": 0 } params = { "sort_by": sort_by, "language": addon.setting("LanguageID"), "page": self.page, "session_id": session_id } url = "account/%s/rated/%s" % (tmdb.Login.get_account_id(), temp) else: session_id = tmdb.Login.get_guest_session_id() if not session_id: utils.notify("Could not get session id") return { "listitems": [], "results_per_page": 0, "total_results": 0 } params = {"language": addon.setting("LanguageID")} url = "guest_session/%s/rated_movies" % (session_id) self.filter_label = addon.LANG( 32145) if self.type == "tv" else addon.LANG(32135) else: self.set_filter_label() params = { "sort_by": sort_by, "language": addon.setting("LanguageID"), "page": self.page, "include_adult": include_adult } filters = {item["type"]: item["id"] for item in self.filters} params = utils.merge_dicts(params, filters) url = "discover/%s" % (self.type) response = tmdb.get_data(url=url, params=params, cache_days=0 if force else 2) if not response: return None if self.mode == "list": info = { "listitems": tmdb.handle_movies(results=response["items"], local_first=True, sortkey=None), "results_per_page": 1, "total_results": len(response["items"]) } return info if "results" not in response: # self.close() return { "listitems": [], "results_per_page": 0, "total_results": 0 } if not response["results"]: utils.notify(addon.LANG(284)) if self.mode == "search": listitems = tmdb.handle_multi_search(response["results"]) elif self.type == "movie": listitems = tmdb.handle_movies(results=response["results"], local_first=False, sortkey=None) else: listitems = tmdb.handle_tvshows(results=response["results"], local_first=False, sortkey=None) info = { "listitems": listitems, "results_per_page": response["total_pages"], "total_results": response["total_results"] } return info