Example #1
0
def handle_tvshows(results, local_first=True, sortkey="year"):
    tvshows = []
    response = get_data(url="genre/tv/list",
                        params={"language": SETTING("LanguageID")},
                        cache_days=30)
    ids = [item["id"] for item in response["genres"]]
    labels = [item["name"] for item in response["genres"]]
    for tv in results:
        tmdb_id = fetch(tv, 'id')
        artwork = get_image_urls(poster=tv.get("poster_path"),
                                 fanart=tv.get("backdrop_path"))
        genres = [
            labels[ids.index(id_)] for id_ in tv.get("genre_ids", [])
            if id_ in ids
        ]
        duration = ""
        if "episode_run_time" in tv:
            if len(tv["episode_run_time"]) > 1:
                duration = "%i - %i" % (min(
                    tv["episode_run_time"]), max(tv["episode_run_time"]))
            elif len(tv["episode_run_time"]) == 1:
                duration = "%i" % (tv["episode_run_time"][0])
        newtv = {
            'title': fetch(tv, 'name'),
            'TVShowTitle': fetch(tv, 'name'),
            'OriginalTitle': fetch(tv, 'original_name'),
            'duration': duration,
            'id': tmdb_id,
            'genre': " / ".join(genres),
            'country': fetch(tv, 'original_language'),
            'Popularity': fetch(tv, 'popularity'),
            'credit_id': fetch(tv, 'credit_id'),
            'Plot': fetch(tv, "overview"),
            'year': get_year(fetch(tv, 'first_air_date')),
            'media_type': "tv",
            'character': fetch(tv, 'character'),
            'path': PLUGIN_BASE + 'extendedtvinfo&&id=%s' % tmdb_id,
            'Rating': fetch(tv, 'vote_average'),
            'User_Rating': str(fetch(tv, 'rating')),
            'Votes': fetch(tv, 'vote_count'),
            'TotalEpisodes': fetch(tv, 'number_of_episodes'),
            'TotalSeasons': fetch(tv, 'number_of_seasons'),
            'Release_Date': fetch(tv, 'first_air_date'),
            'Premiered': fetch(tv, 'first_air_date')
        }
        newtv.update(artwork)
        tvshows.append(newtv)
    tvshows = local_db.merge_with_local_tvshow_info(tvshows, local_first,
                                                    sortkey)
    return tvshows
Example #2
0
def handle_tvshows(results, local_first=True, sortkey="year"):
    tvshows = []
    response = get_data(url="genre/tv/list",
                        params={"language": SETTING("LanguageID")},
                        cache_days=30)
    ids = [item["id"] for item in response["genres"]]
    labels = [item["name"] for item in response["genres"]]
    for tv in results:
        tmdb_id = fetch(tv, 'id')
        artwork = get_image_urls(poster=tv.get("poster_path"),
                                 fanart=tv.get("backdrop_path"))
        genres = [labels[ids.index(id_)] for id_ in tv.get("genre_ids", []) if id_ in ids]
        genres = [i for i in genres if i]
        duration = ""
        if "episode_run_time" in tv:
            if len(tv["episode_run_time"]) > 1:
                duration = "%i - %i" % (min(tv["episode_run_time"]), max(tv["episode_run_time"]))
            elif len(tv["episode_run_time"]) == 1:
                duration = "%i" % (tv["episode_run_time"][0])
        newtv = {'title': fetch(tv, 'name'),
                 'TVShowTitle': fetch(tv, 'name'),
                 'OriginalTitle': fetch(tv, 'original_name'),
                 'duration': duration,
                 'id': tmdb_id,
                 'genre': " / ".join(genres),
                 'country': fetch(tv, 'original_language'),
                 'Popularity': fetch(tv, 'popularity'),
                 'credit_id': fetch(tv, 'credit_id'),
                 'Plot': fetch(tv, "overview"),
                 'year': get_year(fetch(tv, 'first_air_date')),
                 'mediatype': "tvshow",
                 'character': fetch(tv, 'character'),
                 'path': PLUGIN_BASE + 'extendedtvinfo&&id=%s' % tmdb_id,
                 'Rating': fetch(tv, 'vote_average'),
                 'User_Rating': str(fetch(tv, 'rating')),
                 'Votes': fetch(tv, 'vote_count'),
                 'TotalEpisodes': fetch(tv, 'number_of_episodes'),
                 'TotalSeasons': fetch(tv, 'number_of_seasons'),
                 'Release_Date': fetch(tv, 'first_air_date'),
                 'Premiered': fetch(tv, 'first_air_date')}
        newtv.update(artwork)
        tvshows.append(newtv)
    tvshows = local_db.merge_with_local_tvshow_info(tvshows, local_first, sortkey)
    return tvshows
Example #3
0
def handle_tvshows(results):
    shows = []
    for tvshow in results:
        airs = fetch(tvshow['show'], "airs")
        path = PLUGIN_BASE + 'extendedtvinfo&&tvdb_id=%s' % tvshow['show'][
            'ids']["tvdb"]
        show = {
            'title': tvshow['show']["title"],
            'Label': tvshow['show']["title"],
            'TVShowTitle': tvshow['show']["title"],
            'Runtime': tvshow['show']["runtime"],
            'duration': tvshow['show']["runtime"],
            'duration(h)': format_time(tvshow['show']["runtime"], "h"),
            'duration(m)': format_time(tvshow['show']["runtime"], "m"),
            'year': tvshow['show']["year"],
            'Status': fetch(tvshow['show'], "status"),
            'mpaa': tvshow['show']["certification"],
            'Studio': tvshow['show']["network"],
            'Plot': tvshow['show']["overview"],
            'id': tvshow['show']['ids']["tmdb"],
            'tvdb_id': tvshow['show']['ids']["tvdb"],
            'imdb_id': tvshow['show']['ids']["imdb"],
            'mediatype': "tvshow",
            'path': path,
            'AirDay': fetch(airs, "day"),
            'AirShortTime': fetch(airs, "time"),
            'Premiered': tvshow['show']["first_aired"][:10],
            'Country': tvshow['show']["country"],
            'Rating': round(tvshow['show']["rating"], 1),
            'Votes': tvshow['show']["votes"],
            'Watchers': fetch(tvshow, "watchers"),
            'genre': " / ".join(tvshow['show']["genres"]),
            'poster': tvshow['show']["images"]["poster"]["full"],
            'Banner': tvshow['show']["images"]["banner"]["full"],
            'fanart': tvshow['show']["images"]["fanart"]["full"],
            'thumb': tvshow['show']["images"]["poster"]["thumb"]
        }
        shows.append(show)
    shows = local_db.merge_with_local_tvshow_info(online_list=shows,
                                                  library_first=False)
    return shows
Example #4
0
def handle_tvshows(results):
    shows = []
    for tvshow in results:
        airs = fetch(tvshow['show'], "airs")
        path = PLUGIN_BASE + 'extendedtvinfo&&tvdb_id=%s' % tvshow['show']['ids']["tvdb"]
        show = {'title': tvshow['show']["title"],
                'Label': tvshow['show']["title"],
                'TVShowTitle': tvshow['show']["title"],
                'Runtime': tvshow['show']["runtime"],
                'duration': tvshow['show']["runtime"],
                'duration(h)': format_time(tvshow['show']["runtime"], "h"),
                'duration(m)': format_time(tvshow['show']["runtime"], "m"),
                'year': tvshow['show']["year"],
                'Status': fetch(tvshow['show'], "status"),
                'mpaa': tvshow['show']["certification"],
                'Studio': tvshow['show']["network"],
                'Plot': tvshow['show']["overview"],
                'id': tvshow['show']['ids']["tmdb"],
                'tvdb_id': tvshow['show']['ids']["tvdb"],
                'imdb_id': tvshow['show']['ids']["imdb"],
                'mediatype': "tvshow",
                'path': path,
                'AirDay': fetch(airs, "day"),
                'AirShortTime': fetch(airs, "time"),
                'Premiered': tvshow['show']["first_aired"][:10],
                'Country': tvshow['show']["country"],
                'Rating': round(tvshow['show']["rating"], 1),
                'Votes': tvshow['show']["votes"],
                'Watchers': fetch(tvshow, "watchers"),
                'genre': " / ".join(tvshow['show']["genres"]),
                'poster': tvshow['show']["images"]["poster"]["full"],
                'Banner': tvshow['show']["images"]["banner"]["full"],
                'fanart': tvshow['show']["images"]["fanart"]["full"],
                'thumb': tvshow['show']["images"]["poster"]["thumb"]}
        shows.append(show)
    shows = local_db.merge_with_local_tvshow_info(online_list=shows,
                                                  library_first=False)
    return shows
Example #5
0
def extended_tvshow_info(tvshow_id=None, cache_time=7, dbid=None):
    if not tvshow_id:
        return None
    params = {"append_to_response": ALL_TV_PROPS,
              "language": SETTING("LanguageID"),
              "include_image_language": "en,null,%s" % 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=cache_time)
    if not response:
        return False
    account_states = response.get("account_states")
    videos = handle_videos(response["videos"]["results"]) if "videos" in response else []
    tmdb_id = fetch(response, 'id')
    artwork = get_image_urls(poster=response.get("poster_path"),
                             fanart=response.get("backdrop_path"))
    if len(response.get("episode_run_time", -1)) > 1:
        duration = "%i - %i" % (min(response["episode_run_time"]), max(response["episode_run_time"]))
    elif len(response.get("episode_run_time", -1)) == 1:
        duration = "%i" % (response["episode_run_time"][0])
    else:
        duration = ""
    us_cert = dictfind(response['content_ratings']['results'], "iso_3166_1", "US")
    if us_cert:
        mpaa = us_cert["rating"]
    elif response['content_ratings']['results']:
        mpaa = response['content_ratings']['results'][0]['rating']
    else:
        mpaa = ""
    genres = [item["name"] for item in response["genres"]]
    tvshow = {'title': fetch(response, 'name'),
              'TVShowTitle': fetch(response, 'name'),
              'OriginalTitle': fetch(response, 'original_name'),
              'duration': duration,
              'duration(h)': format_time(duration, "h"),
              'duration(m)': format_time(duration, "m"),
              'id': tmdb_id,
              'mpaa': mpaa,
              'genre': " / ".join(genres),
              'credit_id': fetch(response, 'credit_id'),
              'Plot': clean_text(fetch(response, "overview")),
              'year': get_year(fetch(response, 'first_air_date')),
              'mediatype': "tvshow",
              'path': PLUGIN_BASE + 'extendedtvinfo&&id=%s' % tmdb_id,
              'Popularity': fetch(response, 'popularity'),
              'Rating': round(response['vote_average'], 1) if response.get('vote_average') else "",
              'country': fetch(response, 'original_language'),
              'User_Rating': str(fetch(response, 'rating')),
              'Votes': fetch(response, 'vote_count'),
              'Status': translate_status(fetch(response, 'status')),
              'ShowType': fetch(response, 'type'),
              'homepage': fetch(response, 'homepage'),
              'last_air_date': fetch(response, 'last_air_date'),
              'first_air_date': fetch(response, 'first_air_date'),
              'TotalEpisodes': fetch(response, 'number_of_episodes'),
              'TotalSeasons': fetch(response, 'number_of_seasons'),
              'in_production': fetch(response, 'in_production'),
              'Release_Date': fetch(response, 'first_air_date'),
              'Premiered': fetch(response, 'first_air_date')}
    tvshow.update(artwork)
    if dbid:
        local_item = local_db.get_tvshow(dbid)
        tvshow.update(local_item)
    else:
        tvshow = local_db.merge_with_local_tvshow_info([tvshow])[0]
    tvshow['Rating'] = round(response['vote_average'], 1) if response.get('vote_average') else ""
    listitems = {"actors": handle_people(response["credits"]["cast"]),
                 "similar": handle_tvshows(response["similar"]["results"]),
                 "studios": handle_misc(response["production_companies"]),
                 "networks": handle_misc(response["networks"]),
                 "certifications": handle_misc(response["content_ratings"]["results"]),
                 "crew": handle_people(response["credits"]["crew"]),
                 "genres": handle_misc(response["genres"]),
                 "keywords": handle_misc(response["keywords"]["results"]),
                 "videos": videos,
                 "seasons": handle_seasons(response["seasons"]),
                 "images": handle_images(response["images"]["posters"]),
                 "backdrops": handle_images(response["images"]["backdrops"])}
    return (tvshow, listitems, account_states)
Example #6
0
def extended_tvshow_info(tvshow_id=None, cache_time=7, dbid=None):
    if not tvshow_id:
        return None
    params = {"append_to_response": ALL_TV_PROPS,
              "language": SETTING("LanguageID"),
              "include_image_language": "en,null,%s" % 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=cache_time)
    if not response:
        return False
    account_states = response.get("account_states")
    videos = handle_videos(response["videos"]["results"]) if "videos" in response else []
    tmdb_id = fetch(response, 'id')
    artwork = get_image_urls(poster=response.get("poster_path"),
                             fanart=response.get("backdrop_path"))
    if len(response.get("episode_run_time", -1)) > 1:
        duration = "%i - %i" % (min(response["episode_run_time"]), max(response["episode_run_time"]))
    elif len(response.get("episode_run_time", -1)) == 1:
        duration = "%i" % (response["episode_run_time"][0])
    else:
        duration = ""
    us_cert = dictfind(response['content_ratings']['results'], "iso_3166_1", "US")
    if us_cert:
        mpaa = us_cert["rating"]
    elif response['content_ratings']['results']:
        mpaa = response['content_ratings']['results'][0]['rating']
    else:
        mpaa = ""
    genres = [item["name"] for item in response["genres"]]
    tvshow = {'title': response.get('name'),
              'TVShowTitle': response.get('name'),
              'OriginalTitle': response.get('original_name', ""),
              'duration': duration,
              'duration(h)': format_time(duration, "h"),
              'duration(m)': format_time(duration, "m"),
              'id': tmdb_id,
              'mpaa': mpaa,
              'genre': " / ".join(genres),
              'credit_id': response.get('credit_id'),
              'Plot': clean_text(response.get("overview")),
              'year': get_year(response.get('first_air_date')),
              'mediatype': "tvshow",
              'path': PLUGIN_BASE + 'extendedtvinfo&&id=%s' % tmdb_id,
              'Popularity': response.get('popularity'),
              'Rating': response.get('vote_average'),
              'country': response.get('original_language'),
              'User_Rating': response.get('rating'),
              'Votes': response.get('vote_count'),
              'Status': translate_status(response.get('status')),
              'ShowType': response.get('type'),
              'homepage': response.get('homepage'),
              'last_air_date': response.get('last_air_date'),
              'TotalEpisodes': response.get('number_of_episodes'),
              'TotalSeasons': response.get('number_of_seasons'),
              'in_production': response.get('in_production'),
              'Premiered': response.get('first_air_date')}
    tvshow.update(artwork)
    if dbid:
        local_item = local_db.get_tvshow(dbid)
        tvshow.update(local_item)
    else:
        tvshow = local_db.merge_with_local_tvshow_info([tvshow])[0]
    tvshow['Rating'] = fetch(response, 'vote_average')  # hack to get tmdb rating instead of local one
    listitems = {"actors": handle_people(response["credits"]["cast"]),
                 "similar": handle_tvshows(response["similar"]["results"]),
                 "studios": handle_misc(response["production_companies"]),
                 "networks": handle_misc(response["networks"]),
                 "certifications": handle_misc(response["content_ratings"]["results"]),
                 "crew": handle_people(response["credits"]["crew"]),
                 "genres": handle_misc(response["genres"]),
                 "keywords": handle_misc(response["keywords"]["results"]),
                 "videos": videos,
                 "seasons": handle_seasons(response["seasons"]),
                 "images": handle_images(response["images"]["posters"]),
                 "backdrops": handle_images(response["images"]["backdrops"])}
    return (tvshow, listitems, account_states)