diff --git a/resources/lib/TheMovieDB.py b/resources/lib/TheMovieDB.py index 142bd89dd..2281d0b98 100755 --- a/resources/lib/TheMovieDB.py +++ b/resources/lib/TheMovieDB.py @@ -31,8 +31,8 @@ IMAGE_BASE_URL = "http://image.tmdb.org/t/p/" POSTER_SIZE = "w500" URL_BASE = "http{}://api.themoviedb.org/3/".format("s" if addon.bool_setting("use_https") else "") -ALL_MOVIE_PROPS = "account_states,alternative_titles,credits,images,keywords,release_dates,videos,translations,similar,reviews,lists,rating" -ALL_TV_PROPS = "account_states,alternative_titles,content_ratings,credits,external_ids,images,keywords,rating,similar,translations,videos" +ALL_MOVIE_PROPS = "account_states,alternative_titles,credits,images,keywords,release_dates,videos,translations,similar,recommendations,reviews,lists,rating" +ALL_TV_PROPS = "account_states,alternative_titles,content_ratings,credits,external_ids,images,keywords,rating,similar,recommendations,translations,videos" ALL_ACTOR_PROPS = "tv_credits,movie_credits,combined_credits,images,tagged_images" ALL_SEASON_PROPS = "videos,images,external_ids,credits" ALL_EPISODE_PROPS = "account_states,credits,external_ids,images,rating,videos" @@ -1144,6 +1144,16 @@ def get_similar_movies(movie_id): return handle_movies(response["similar"]["results"]) +def get_recommed_movies(movie_id): + ''' + get dict list containing movies similar to *movie_id + ''' + response = get_movie(movie_id) + if not response or not response.get("recommendations"): + return [] + return handle_movies(response["recommendations"]["results"]) + + def get_similar_tvshows(tvshow_id): ''' return list with similar tvshows for show with *tvshow_id (TMDB ID) @@ -1161,6 +1171,23 @@ def get_similar_tvshows(tvshow_id): return handle_tvshows(response["similar"]["results"]) +def get_recommed_tvshows(tvshow_id): + ''' + return list with similar tvshows for show with *tvshow_id (TMDB ID) + ''' + params = {"append_to_response": ALL_TV_PROPS, + "language": addon.setting("LanguageID"), + "include_image_language": "en,null,%s" % addon.setting("LanguageID")} + if Login.check_login(): + params["session_id"] = Login.get_session_id() + response = get_data(url="tv/%s" % (tvshow_id), + params=params, + cache_days=10) + if not response.get("recommendations"): + return [] + return handle_tvshows(response["recommendations"]["results"]) + + def get_tvshows(tvshow_type): ''' return list with tv shows diff --git a/resources/lib/process.py b/resources/lib/process.py index e02d8b23f..8dad64e79 100644 --- a/resources/lib/process.py +++ b/resources/lib/process.py @@ -89,6 +89,13 @@ def start_info_actions(info, params): dbid=params.get("dbid")) if movie_id: return tmdb.get_similar_movies(movie_id) + elif info == 'recommedmovies': + 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_recommed_movies(movie_id) elif info == 'similartvshows': tvshow_id = None dbid = params.get("dbid") @@ -112,6 +119,29 @@ def start_info_actions(info, params): media_type="tv") if tvshow_id: return tmdb.get_similar_tvshows(tvshow_id) + elif info == 'recommedtvshows': + 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_recommed_tvshows(tvshow_id) elif info == 'studio': if params.get("id"): return tmdb.get_company_data(params["id"])