def map_details(self, data, media_type): '''helper method to map the details received from tmdb to kodi compatible formatting''' if not data: return {} details = {} details["tmdb_id"] = data["id"] details["rating"] = data["vote_average"] details["votes"] = data["vote_count"] details["rating.tmdb"] = data["vote_average"] details["votes.tmdb"] = data["vote_count"] details["popularity"] = data["popularity"] details["popularity.tmdb"] = data["popularity"] details["plot"] = data["overview"] details["genre"] = [item["name"] for item in data["genres"]] details["homepage"] = data["homepage"] details["status"] = data["status"] details["cast"] = [] details["castandrole"] = [] details["writer"] = [] details["director"] = [] details["media_type"] = media_type # cast if "credits" in data: if "cast" in data["credits"]: for cast_member in data["credits"]["cast"]: cast_thumb = "" if cast_member["profile_path"]: cast_thumb = "http://image.tmdb.org/t/p/original%s" % cast_member[ "profile_path"] details["cast"].append({ "name": cast_member["name"], "role": cast_member["character"], "thumbnail": cast_thumb }) details["castandrole"].append( (cast_member["name"], cast_member["character"])) # crew (including writers and directors) if "crew" in data["credits"]: for crew_member in data["credits"]["crew"]: cast_thumb = "" if crew_member["profile_path"]: cast_thumb = "http://image.tmdb.org/t/p/original%s" % crew_member[ "profile_path"] if crew_member["job"] in ["Author", "Writer"]: details["writer"].append(crew_member["name"]) if crew_member["job"] in [ "Producer", "Executive Producer" ]: details["director"].append(crew_member["name"]) if crew_member["job"] in [ "Producer", "Executive Producer", "Author", "Writer" ]: details["cast"].append({ "name": crew_member["name"], "role": crew_member["job"], "thumbnail": cast_thumb }) # artwork details["art"] = {} if data.get("images"): if data["images"].get("backdrops"): fanarts = self.get_best_images(data["images"]["backdrops"]) details["art"]["fanarts"] = fanarts details["art"]["fanart"] = fanarts[0] if fanarts else "" if data["images"].get("posters"): posters = self.get_best_images(data["images"]["posters"]) details["art"]["posters"] = posters details["art"]["poster"] = posters[0] if posters else "" if not details["art"].get("poster") and data.get("poster_path"): details["art"][ "poster"] = "http://image.tmdb.org/t/p/original%s" % data[ "poster_path"] if not details["art"].get("fanart") and data.get("backdrop_path"): details["art"][ "fanart"] = "http://image.tmdb.org/t/p/original%s" % data[ "backdrop_path"] # movies only if media_type == "movie": details["title"] = data["title"] details["originaltitle"] = data["original_title"] if data["belongs_to_collection"]: details["set"] = data["belongs_to_collection"].get("name", "") if data.get("release_date"): details["premiered"] = data["release_date"] details["year"] = try_parse_int( data["release_date"].split("-")[0]) details["tagline"] = data["tagline"] if data["runtime"]: details["runtime"] = data["runtime"] * 60 details["imdbnumber"] = data["imdb_id"] details["budget"] = data["budget"] details["budget.formatted"] = int_with_commas(data["budget"]) details["revenue"] = data["revenue"] details["revenue.formatted"] = int_with_commas(data["revenue"]) if data.get("production_companies"): details["studio"] = [ item["name"] for item in data["production_companies"] ] if data.get("production_countries"): details["country"] = [ item["name"] for item in data["production_countries"] ] if data.get("keywords"): details["tag"] = [ item["name"] for item in data["keywords"]["keywords"] ] # tvshows only if media_type == "tvshow": details["title"] = data["name"] details["originaltitle"] = data["original_name"] if data.get("created_by"): details["director"] += [ item["name"] for item in data["created_by"] ] if data.get("episode_run_time"): details["runtime"] = data["episode_run_time"][0] * 60 if data.get("first_air_date"): details["premiered"] = data["first_air_date"] details["year"] = try_parse_int( data["first_air_date"].split("-")[0]) if "last_air_date" in data: details["lastaired"] = data["last_air_date"] if data.get("networks"): details["studio"] = [item["name"] for item in data["networks"]] if "origin_country" in data: details["country"] = data["origin_country"] if data.get("external_ids"): details["imdbnumber"] = data["external_ids"].get("imdb_id", "") details["tvdb_id"] = data["external_ids"].get("tvdb_id", "") if "results" in data["keywords"]: details["tag"] = [ item["name"] for item in data["keywords"]["results"] ] # trailer for video in data["videos"]["results"]: if video["site"] == "YouTube" and video["type"] == "Trailer": details[ "trailer"] = 'plugin://plugin.video.youtube/?action=play_video&videoid=%s' % video[ "key"] break return details
def map_details(self, data, media_type): '''helper method to map the details received from tmdb to kodi compatible formatting''' if not data: return {} details = {} details["tmdb_id"] = data["id"] details["rating"] = data["vote_average"] details["votes"] = data["vote_count"] details["rating.tmdb"] = data["vote_average"] details["votes.tmdb"] = data["vote_count"] details["popularity"] = data["popularity"] details["popularity.tmdb"] = data["popularity"] details["plot"] = data["overview"] details["genre"] = [item["name"] for item in data["genres"]] details["homepage"] = data["homepage"] details["status"] = data["status"] details["cast"] = [] details["castandrole"] = [] details["writer"] = [] details["director"] = [] details["media_type"] = media_type # cast if "credits" in data: if "cast" in data["credits"]: for cast_member in data["credits"]["cast"]: cast_thumb = "" if cast_member["profile_path"]: cast_thumb = "http://image.tmdb.org/t/p/original%s" % cast_member["profile_path"] details["cast"].append({"name": cast_member["name"], "role": cast_member["character"], "thumbnail": cast_thumb}) details["castandrole"].append((cast_member["name"], cast_member["character"])) # crew (including writers and directors) if "crew" in data["credits"]: for crew_member in data["credits"]["crew"]: cast_thumb = "" if crew_member["profile_path"]: cast_thumb = "http://image.tmdb.org/t/p/original%s" % crew_member["profile_path"] if crew_member["job"] in ["Author", "Writer"]: details["writer"].append(crew_member["name"]) if crew_member["job"] in ["Producer", "Executive Producer"]: details["director"].append(crew_member["name"]) if crew_member["job"] in ["Producer", "Executive Producer", "Author", "Writer"]: details["cast"].append({"name": crew_member["name"], "role": crew_member["job"], "thumbnail": cast_thumb}) # artwork details["art"] = {} if data.get("images"): if data["images"].get("backdrops"): fanarts = self.get_best_images(data["images"]["backdrops"]) details["art"]["fanarts"] = fanarts details["art"]["fanart"] = fanarts[0] if fanarts else "" if data["images"].get("posters"): posters = self.get_best_images(data["images"]["posters"]) details["art"]["posters"] = posters details["art"]["poster"] = posters[0] if posters else "" if not details["art"].get("poster") and data.get("poster_path"): details["art"]["poster"] = "http://image.tmdb.org/t/p/original%s" % data["poster_path"] if not details["art"].get("fanart") and data.get("backdrop_path"): details["art"]["fanart"] = "http://image.tmdb.org/t/p/original%s" % data["backdrop_path"] # movies only if media_type == "movie": details["title"] = data["title"] details["originaltitle"] = data["original_title"] if data["belongs_to_collection"]: details["set"] = data["belongs_to_collection"].get("name", "") if data.get("release_date"): details["premiered"] = data["release_date"] details["year"] = try_parse_int(data["release_date"].split("-")[0]) details["tagline"] = data["tagline"] if data["runtime"]: details["runtime"] = data["runtime"] * 60 details["imdbnumber"] = data["imdb_id"] details["budget"] = data["budget"] details["budget.formatted"] = int_with_commas(data["budget"]) details["revenue"] = data["revenue"] details["revenue.formatted"] = int_with_commas(data["revenue"]) if data.get("production_companies"): details["studio"] = [item["name"] for item in data["production_companies"]] if data.get("production_countries"): details["country"] = [item["name"] for item in data["production_countries"]] if data.get("keywords"): details["tag"] = [item["name"] for item in data["keywords"]["keywords"]] # tvshows only if media_type == "tvshow": details["title"] = data["name"] details["originaltitle"] = data["original_name"] if data.get("created_by"): details["director"] += [item["name"] for item in data["created_by"]] if data.get("episode_run_time"): details["runtime"] = data["episode_run_time"][0] * 60 if data.get("first_air_date"): details["premiered"] = data["first_air_date"] details["year"] = try_parse_int(data["first_air_date"].split("-")[0]) if "last_air_date" in data: details["lastaired"] = data["last_air_date"] if data.get("networks"): details["studio"] = [item["name"] for item in data["networks"]] if "origin_country" in data: details["country"] = data["origin_country"] if data.get("external_ids"): details["imdbnumber"] = data["external_ids"].get("imdb_id", "") details["tvdb_id"] = data["external_ids"].get("tvdb_id", "") if "results" in data["keywords"]: details["tag"] = [item["name"] for item in data["keywords"]["results"]] # trailer for video in data["videos"]["results"]: if video["site"] == "YouTube" and video["type"] == "Trailer": details["trailer"] = 'plugin://plugin.video.youtube/?action=play_video&videoid=%s' % video["key"] break return details
def map_details(data): '''helper method to map the details received from omdb to kodi compatible format''' result = {} for key, value in data.iteritems(): # filter the N/A values if value in ["N/A", "NA"] or not value: continue if key == "Title": result["title"] = value elif key == "Year": try: result["year"] = try_parse_int(value.split("-")[0]) except Exception: result["year"] = value elif key == "Year": result["year"] = value if key == "Rated": result["mpaa"] = value.replace("Rated", "") elif key == "Title": result["title"] = value elif key == "Released": date_time = arrow.get(value, "DD MMM YYYY") result["premiered"] = date_time.strftime( xbmc.getRegion("dateshort")) try: result["premiered.formatted"] = date_time.format( 'DD MMM YYYY', locale=KODI_LANGUAGE) except Exception: result["premiered.formatted"] = value elif key == "Runtime": result["runtime"] = try_parse_int(value.replace(" min", "")) * 60 elif key == "Genre": result["genre"] = value.split(", ") elif key == "Director": result["director"] = value.split(", ") elif key == "Writer": result["writer"] = value.split(", ") elif key == "Country": result["country"] = value.split(", ") elif key == "Awards": result["awards"] = value elif key == "Poster": result["thumbnail"] = value result["art"] = {} result["art"]["thumb"] = value elif key == "imdbVotes": result["votes.imdb"] = value result["votes"] = try_parse_int(value.replace(",", "")) elif key == "Ratings": for rating_item in value: if rating_item["Source"] == "Internet Movie Database": rating = rating_item["Value"] result["rating.imdb.text"] = rating rating = rating.split("/")[0] result["rating.imdb"] = rating result["rating"] = float(rating) result["rating.percent.imdb"] = "%s" % (try_parse_int( float(rating) * 10)) elif rating_item["Source"] == "Rotten Tomatoes": rating = rating_item["Value"] result["rottentomatoes.rating.percent"] = rating rating = rating.replace("%", "") # this should be a dedicated rt rating instead of the meter result["rottentomatoes.rating"] = rating result["rating.rt"] = rating result["rottentomatoes.meter"] = rating result["rottentomatoesmeter"] = rating rating = int(rating) if rating < 60: result["rottentomatoes.rotten"] = rating result["rottentomatoes.image"] = "rotten" else: result["rottentomatoes.fresh"] = rating result["rottentomatoes.image"] = "fresh" elif rating_item["Source"] == "Metacritic": rating = rating_item["Value"] result["rating.mc.text"] = rating rating = rating.split("/")[0] result["metacritic.rating"] = rating result["rating.mc"] = rating result["metacritic.rating.percent"] = "%s" % rating elif key == "imdbID": result["imdbnumber"] = value elif key == "BoxOffice": result["boxoffice"] = value elif key == "DVD": date_time = arrow.get(value, "DD MMM YYYY") result["dvdrelease"] = date_time.format('YYYY-MM-DD') result["dvdrelease.formatted"] = date_time.format( 'DD MMM YYYY', locale=KODI_LANGUAGE) elif key == "Production": result["studio"] = value.split(", ") elif key == "Website": result["homepage"] = value # rotten tomatoes - will probably never work again (OMDBAPI doesnt't provide them anymore) elif key == "tomatoReviews": result["rottentomatoes.reviews"] = formatted_number(value) elif key == "tomatoConsensus": result["rottentomatoes.consensus"] = value elif key == "tomatoUserMeter": result["rottentomatoes.usermeter"] = value elif key == "tomatoUserRating": result["rottentomatoes.userrating"] = value result["rottentomatoes.userrating.percent"] = "%s" % ( try_parse_int(float(value) * 10)) elif key == "tomatoUserReviews": result["rottentomatoes.userreviews"] = int_with_commas(value) elif key == "tomatoURL": result["rottentomatoes.url"] = value return result
def map_details(data): """helper method to map the details received from omdb to kodi compatible format""" result = {} if sys.version_info.major == 3: for key, value in data.items(): # filter the N/A values if value in ["N/A", "NA"] or not value: continue if key == "title": result["title"] = value elif key == "year": try: result["year"] = try_parse_int(value.split("-")[0]) except Exception: result["year"] = value elif key == "rated": result["mpaa"] = value.replace("Rated", "") elif key == "released": date_time = arrow.get(value, "DD MMM YYYY") result["premiered"] = date_time.strftime( xbmc.getRegion("dateshort")) try: result["premiered.formatted"] = date_time.format( 'DD MMM YYYY', locale=KODI_LANGUAGE) except Exception: result["premiered.formatted"] = value elif key == "runtime": result["runtime"] = try_parse_int(value.replace( " min", "")) * 60 elif key == "genre": result["genre"] = value.split(", ") elif key == "director": result["director"] = value.split(", ") elif key == "writer": result["writer"] = value.split(", ") elif key == "country": result["country"] = value.split(", ") result["country.0"] = value.split(", ")[0] elif key == "awards": result["awards"] = value elif key == "poster": result["thumbnail"] = value result["art"] = {} result["art"]["thumb"] = value elif key == "imdbVotes": result["votes.imdb"] = value result["votes"] = try_parse_int(value.replace(",", "")) elif key == "imdbRating": result["rating.imdb"] = value result["rating"] = float(value) result["rating.percent.imdb"] = "%s" % (try_parse_int( float(value) * 10)) elif key == "metascore": result["metacritic.rating"] = value result["metacritic.rating.percent"] = "%s" % value elif key == "imdbID": result["imdbnumber"] = value elif key == "BoxOffice": result["boxoffice"] = value elif key == "DVD": date_time = arrow.get(value, "DD MMM YYYY") result["dvdrelease"] = date_time.format('YYYY-MM-DD') result["dvdrelease.formatted"] = date_time.format( 'DD MMM YYYY', locale=KODI_LANGUAGE) elif key == "Production": result["studio"] = value.split(", ") elif key == "Website": result["homepage"] = value elif key == "plot": result["plot"] = value result["imdb.plot"] = value elif key == "type": if value == "series": result["type"] = "tvshow" else: result["type"] = value result["media_type"] = result["type"] # rotten tomatoes elif key == "tomatoMeter": result["rottentomatoes.meter"] = value result["rottentomatoesmeter"] = value elif key == "tomatoImage": result["rottentomatoes.image"] = value elif key == "tomatoRating": result["rottentomatoes.rating"] = value result["rottentomatoes.rating.percent"] = "%s" % ( try_parse_int(float(value) * 10)) result["rating.rt"] = value elif key == "tomatoReviews": result["rottentomatoes.reviews"] = formatted_number(value) elif key == "tomatoFresh": result["rottentomatoes.fresh"] = value elif key == "tomatoRotten": result["rottentomatoes.rotten"] = value elif key == "tomatoConsensus": result["rottentomatoes.consensus"] = value elif key == "tomatoUserMeter": result["rottentomatoes.usermeter"] = value elif key == "tomatoUserRating": result["rottentomatoes.userrating"] = value result["rottentomatoes.userrating.percent"] = "%s" % ( try_parse_int(float(value) * 10)) elif key == "tomatoUserReviews": result["rottentomatoes.userreviews"] = int_with_commas( value) elif key == "tomatoeURL": result["rottentomatoes.url"] = value else: for key, value in data.iteritems(): # filter the N/A values if value in ["N/A", "NA"] or not value: continue if key == "title": result["title"] = value elif key == "Year": try: result["year"] = try_parse_int(value.split("-")[0]) except Exception: result["year"] = value elif key == "rated": result["mpaa"] = value.replace("Rated", "") elif key == "released": date_time = arrow.get(value, "DD MMM YYYY") result["premiered"] = date_time.strftime( xbmc.getRegion("dateshort")) try: result["premiered.formatted"] = date_time.format( 'DD MMM YYYY', locale=KODI_LANGUAGE) except Exception: result["premiered.formatted"] = value elif key == "runtime": result["runtime"] = try_parse_int(value.replace( " min", "")) * 60 elif key == "genre": result["genre"] = value.split(", ") elif key == "director": result["director"] = value.split(", ") elif key == "writer": result["writer"] = value.split(", ") elif key == "country": result["country"] = value.split(", ") elif key == "awards": result["awards"] = value elif key == "poster": result["thumbnail"] = value result["art"] = {} result["art"]["thumb"] = value elif key == "imdbVotes": result["votes.imdb"] = value result["votes"] = try_parse_int(value.replace(",", "")) elif key == "imdbRating": result["rating.imdb"] = value result["rating"] = float(value) result["rating.percent.imdb"] = "%s" % (try_parse_int( float(value) * 10)) elif key == "metascore": result["metacritic.rating"] = value result["metacritic.rating.percent"] = "%s" % value elif key == "imdbID": result["imdbnumber"] = value elif key == "BoxOffice": result["boxoffice"] = value elif key == "DVD": date_time = arrow.get(value, "DD MMM YYYY") result["dvdrelease"] = date_time.format('YYYY-MM-DD') result["dvdrelease.formatted"] = date_time.format( 'DD MMM YYYY', locale=KODI_LANGUAGE) elif key == "Production": result["studio"] = value.split(", ") elif key == "Website": result["homepage"] = value elif key == "plot": result["plot"] = value result["imdb.plot"] = value elif key == "type": if value == "series": result["type"] = "tvshow" else: result["type"] = value result["media_type"] = result["type"] # rotten tomatoes elif key == "tomatoMeter": result["rottentomatoes.meter"] = value result["rottentomatoesmeter"] = value elif key == "tomatoImage": result["rottentomatoes.image"] = value elif key == "tomatoRating": result["rottentomatoes.rating"] = value result["rottentomatoes.rating.percent"] = "%s" % ( try_parse_int(float(value) * 10)) result["rating.rt"] = value elif key == "tomatoReviews": result["rottentomatoes.reviews"] = formatted_number(value) elif key == "tomatoFresh": result["rottentomatoes.fresh"] = value elif key == "tomatoRotten": result["rottentomatoes.rotten"] = value elif key == "tomatoConsensus": result["rottentomatoes.consensus"] = value elif key == "tomatoUserMeter": result["rottentomatoes.usermeter"] = value elif key == "tomatoUserRating": result["rottentomatoes.userrating"] = value result["rottentomatoes.userrating.percent"] = "%s" % ( try_parse_int(float(value) * 10)) elif key == "tomatoUserReviews": result["rottentomatoes.userreviews"] = int_with_commas( value) elif key == "tomatoeURL": result["rottentomatoes.url"] = value return result
def map_details(data): '''helper method to map the details received from omdb to kodi compatible format''' result = {} for key, value in data.iteritems(): # filter the N/A values if value in ["N/A", "NA"] or not value: continue if key == "Title": result["title"] = value elif key == "Year": try: result["year"] = try_parse_int(value.split("-")[0]) except Exception: result["year"] = value elif key == "Year": result["year"] = value if key == "Rated": result["mpaa"] = value.replace("Rated", "") elif key == "Title": result["title"] = value elif key == "Released": date_time = arrow.get(value, "DD MMM YYYY") result["premiered"] = date_time.strftime(xbmc.getRegion("dateshort")) try: result["premiered.formatted"] = date_time.format('DD MMM YYYY', locale=KODI_LANGUAGE) except Exception: result["premiered.formatted"] = value elif key == "Runtime": result["runtime"] = try_parse_int(value.replace(" min", "")) * 60 elif key == "Genre": result["genre"] = value.split(", ") elif key == "Director": result["director"] = value.split(", ") elif key == "Writer": result["writer"] = value.split(", ") elif key == "Country": result["country"] = value.split(", ") elif key == "Awards": result["awards"] = value elif key == "Poster": result["thumbnail"] = value result["art"] = {} result["art"]["thumb"] = value elif key == "imdbVotes": result["votes.imdb"] = value result["votes"] = try_parse_int(value.replace(",", "")) elif key == "Ratings": for rating_item in value: if rating_item["Source"] == "Internet Movie Database": rating = rating_item["Value"] result["rating.imdb.text"] = rating rating = rating.split("/")[0] result["rating.imdb"] = rating result["rating"] = float(rating) result["rating.percent.imdb"] = "%s" % (try_parse_int(float(rating) * 10)) elif rating_item["Source"] == "Rotten Tomatoes": rating = rating_item["Value"] result["rottentomatoes.rating.percent"] = rating rating = rating.replace("%", "") # this should be a dedicated rt rating instead of the meter result["rottentomatoes.rating"] = rating result["rating.rt"] = rating result["rottentomatoes.meter"] = rating result["rottentomatoesmeter"] = rating rating = int(rating) if rating < 60: result["rottentomatoes.rotten"] = rating result["rottentomatoes.image"] = "rotten" else: result["rottentomatoes.fresh"] = rating result["rottentomatoes.image"] = "fresh" elif rating_item["Source"] == "Metacritic": rating = rating_item["Value"] result["rating.mc.text"] = rating rating = rating.split("/")[0] result["metacritic.rating"] = rating result["rating.mc"] = rating result["metacritic.rating.percent"] = "%s" % rating elif key == "imdbID": result["imdbnumber"] = value elif key == "BoxOffice": result["boxoffice"] = value elif key == "DVD": date_time = arrow.get(value, "DD MMM YYYY") result["dvdrelease"] = date_time.format('YYYY-MM-DD') result["dvdrelease.formatted"] = date_time.format('DD MMM YYYY', locale=KODI_LANGUAGE) elif key == "Production": result["studio"] = value.split(", ") elif key == "Website": result["homepage"] = value # rotten tomatoes - will probably never work again (OMDBAPI doesnt't provide them anymore) elif key == "tomatoReviews": result["rottentomatoes.reviews"] = formatted_number(value) elif key == "tomatoConsensus": result["rottentomatoes.consensus"] = value elif key == "tomatoUserMeter": result["rottentomatoes.usermeter"] = value elif key == "tomatoUserRating": result["rottentomatoes.userrating"] = value result["rottentomatoes.userrating.percent"] = "%s" % (try_parse_int(float(value) * 10)) elif key == "tomatoUserReviews": result["rottentomatoes.userreviews"] = int_with_commas(value) elif key == "tomatoURL": result["rottentomatoes.url"] = value return result