Ejemplo n.º 1
0
def get_episode_parameters(show, season, episode):
    articles = ['a ', 'A ', 'An ', 'an ', 'The ', 'the ']
    import_tmdb()
    if season in show and episode in show[season]:
        season_obj = show[season]
        episode_obj = show[season][episode]
    else:
        return
    # Get parameters
    parameters = {'id': show['id'], 'season': season, 'episode': episode}
    show_info = get_tvshow_metadata_tvdb(show, banners=True)
    network = show.get('network', '')
    parameters['network'] = network
    if network:
        parameters['network_clean'] = re.sub("(\(.*?\))", "", network).strip()
    else:
        parameters['network_clean'] = network
    parameters['showname'] = show['seriesname']
    parameters['clearname'] = re.sub("(\(.*?\))", "", show['seriesname']).strip()
    parameters['sortname'] = to_utf8(parameters['clearname'])
    for article in articles:
        if to_utf8(parameters['clearname']).startswith(article): parameters['sortname'] = to_utf8(parameters['clearname']).replace(article,'')
    parameters['urlname'] = urllib.quote(to_utf8(parameters['clearname']))
    articles = ['a ', 'A ', 'An ', 'an ', 'The ', 'the ']
    parameters['sortname'] = to_utf8(parameters['clearname'])
    for article in articles:
        if to_utf8(parameters['clearname']).startswith(article): parameters['sortname'] = to_utf8(parameters['clearname']).replace(article,'')
    parameters['shortname'] = to_utf8(parameters['clearname'][1:-1])
    try:
        parameters['absolute_number'] = int(episode_obj.get('absolute_number'))
    except:
        parameters['absolute_number'] = "na"
    parameters['title'] = episode_obj.get('episodename', str(episode))
    parameters['urltitle'] = urllib.quote(to_utf8(parameters['title']))
    parameters['sorttitle'] = to_utf8(parameters['title'])
    for article in articles:
        if to_utf8(parameters['title']).startswith(article): parameters['sorttitle'] = to_utf8(parameters['title']).replace(article,'')
    parameters['shorttitle'] = to_utf8(parameters['title'][1:-1])
    parameters['firstaired'] = episode_obj.get('firstaired')
    parameters['year'] = show.get('year', 0)
    trakt_ids = get_trakt_ids("tvdb", show['id'], parameters['clearname'], "show", parameters['year'])
#    if trakt_ids["slug"]:
#        if trakt_ids["slug"] != None and trakt_ids["slug"] != "": parameters['slug'] = trakt_ids["slug"]
#        else: parameters['slug'] = parameters['clearname'].lower().replace(" ","-")
    if parameters['firstaired']:
        parameters['epyear'] = int(parameters['firstaired'].split("-")[0].strip())
        parameters['epmonth'] = int(parameters['firstaired'].split("-")[1].strip())
        parameters['epday'] = int(parameters['firstaired'].split("-")[2].strip())
    else:
        parameters["epyear"] = 1980
        parameters["epmonth"] = 0
        parameters["epday"] = 0
    parameters['imdb'] = show.get('imdb_id', '')
    parameters['epid'] = episode_obj.get('id')
    if episode_obj.get('id') != "": parameters['plot'] = episode_obj.get('overview')
    else: parameters['plot'] = show['overview']
    if episode_obj.get('Rating') != "": parameters['rating'] = episode_obj.get('Rating')
    else: parameters['rating'] = show['Rating']
    if episode_obj.get('RatingCount') != "": parameters['votes'] = episode_obj.get('RatingCount')
    else: parameters['votes'] = show['RatingCount']
    parameters['writer'] = episode_obj.get('Writer')
    parameters['director'] = episode_obj.get('Director')
    parameters['status'] = show.get('Status')
    parameters['mpaa'] = show.get('ContentRating')
    parameters['actors'] = show.get('Actors')
    if show.get('Genre') != None and '|' in show.get('Genre'): parameters['genres'] = show.get('Genre').replace('|',' / ')[3:-3]
    else: parameters['genres'] = show.get('Genre')
    parameters['runtime'] = show['runtime']
    parameters['duration'] = int(show['runtime']) * 60
    tvdb_base = "http://thetvdb.com/banners/"
    if episode_obj.get('filename') != "": parameters['thumbnail'] = tvdb_base + str(episode_obj.get('filename'))
    elif show.get('poster') != "": parameters['thumbnail'] = tvdb_base + show.get('poster')
    else: parameters['thumbnail'] = get_icon("metalliq")
    if show.get('poster') != "": parameters['poster'] = tvdb_base + show.get('poster')
    else: parameters['poster'] = get_icon("metalliq")
    parameters['thumbnail'] = "http://thetvdb.com/banners/episodes/" + str(show['id']) + "/" + str(parameters['epid']) + ".jpg"
    if show.get('banner') != "": parameters['banner'] = tvdb_base + show.get('banner')
    else: parameters['banner'] = get_banner_path()
    if show.get('fanart') != None and show.get('fanart') != "": parameters['fanart'] = tvdb_base + show.get('fanart')
    else: parameters['fanart'] = get_background_path()
    is_anime = False
    if parameters['genres'] != None and parameters['absolute_number'] and parameters['absolute_number'] != '0' and "animation" in parameters['genres'].lower():
        tmdb_results = tmdb.Find(show['id']).info(external_source="tvdb_id")
        for tmdb_show in tmdb_results.get("tv_results", []):
            if "JP" in tmdb_show['origin_country']:
                is_anime = True
    if is_anime:
        parameters['name'] = u'{showname} {absolute_number}'.format(**parameters)
    else:
        parameters['name'] = u'{showname} S{season:02d}E{episode:02d}'.format(**parameters)
    parameters['now'] = datetime.datetime.now().strftime('%Y%m%d%H%M%S%f')
    return parameters
Ejemplo n.º 2
0
def get_episode_parameters(show, season, episode):
    articles = ['a ', 'A ', 'An ', 'an ', 'The ', 'the ']
    import_tmdb()
    if season in show and episode in show[season]:
        season_obj = show[season]
        episode_obj = show[season][episode]
    else:
        return
    # Get parameters
    parameters = {'id': show['id'], 'season': season, 'episode': episode}
    show_info = get_tvshow_metadata_tvdb(show, banners=True)
    network = show.get('network', '')
    parameters['network'] = network
    if network:
        parameters['network_clean'] = re.sub("(\(.*?\))", "", network).strip()
    else:
        parameters['network_clean'] = network
    parameters['showname'] = show['seriesname']
    parameters['clearname'] = re.sub("(\(.*?\))", "", show['seriesname']).strip()
    parameters['sortname'] = to_utf8(parameters['clearname'])
    for article in articles:
        if to_utf8(parameters['clearname']).startswith(article): parameters['sortname'] = to_utf8(parameters['clearname']).replace(article,'')
    parameters['urlname'] = urllib.quote(to_utf8(parameters['clearname']))
    articles = ['a ', 'A ', 'An ', 'an ', 'The ', 'the ']
    parameters['sortname'] = to_utf8(parameters['clearname'])
    for article in articles:
        if to_utf8(parameters['clearname']).startswith(article): parameters['sortname'] = to_utf8(parameters['clearname']).replace(article,'')
    parameters['shortname'] = to_utf8(parameters['clearname'][1:-1])
    try:
        parameters['absolute_number'] = int(episode_obj.get('absolute_number'))
    except:
        parameters['absolute_number'] = "na"
    parameters['title'] = episode_obj.get('episodename', str(episode))
    parameters['urltitle'] = urllib.quote(to_utf8(parameters['title']))
    parameters['sorttitle'] = to_utf8(parameters['title'])
    for article in articles:
        if to_utf8(parameters['title']).startswith(article): parameters['sorttitle'] = to_utf8(parameters['title']).replace(article,'')
    parameters['shorttitle'] = to_utf8(parameters['title'][1:-1])
    parameters['firstaired'] = episode_obj.get('firstaired')
    parameters['year'] = show.get('year', 0)
    trakt_ids = get_trakt_ids("tvdb", show['id'], parameters['clearname'], "show", parameters['year'])
#    if trakt_ids["slug"]:
#        if trakt_ids["slug"] != None and trakt_ids["slug"] != "": parameters['slug'] = trakt_ids["slug"]
#        else: parameters['slug'] = parameters['clearname'].lower().replace(" ","-")
    if parameters['firstaired']:
        parameters['epyear'] = int(parameters['firstaired'].split("-")[0].strip())
        parameters['epmonth'] = int(parameters['firstaired'].split("-")[1].strip())
        parameters['epday'] = int(parameters['firstaired'].split("-")[2].strip())
    else:
        parameters["epyear"] = 1980
        parameters["epmonth"] = 0
        parameters["epday"] = 0
    parameters['imdb'] = show.get('imdb_id', '')
    parameters['epid'] = episode_obj.get('id')
    if episode_obj.get('id') != "": parameters['plot'] = episode_obj.get('overview')
    else: parameters['plot'] = show['overview']
    if episode_obj.get('Rating') != "": parameters['rating'] = episode_obj.get('Rating')
    else: parameters['rating'] = show['Rating']
    if episode_obj.get('RatingCount') != "": parameters['votes'] = episode_obj.get('RatingCount')
    else: parameters['votes'] = show['RatingCount']
    parameters['writer'] = episode_obj.get('Writer')
    parameters['director'] = episode_obj.get('Director')
    parameters['status'] = show.get('Status')
    parameters['mpaa'] = show.get('ContentRating')
    parameters['actors'] = show.get('Actors')
    if show.get('Genre') != None and '|' in show.get('Genre'): parameters['genres'] = show.get('Genre').replace('|',' / ')[3:-3]
    else: parameters['genres'] = show.get('Genre')
    parameters['runtime'] = show['runtime']
    parameters['duration'] = int(show['runtime']) * 60
    tvdb_base = "http://thetvdb.com/banners/"
    if episode_obj.get('filename') != "": parameters['thumbnail'] = tvdb_base + str(episode_obj.get('filename'))
    elif show.get('poster') != "": parameters['thumbnail'] = tvdb_base + show.get('poster')
    else: parameters['thumbnail'] = get_icon("metalliq")
    if show.get('poster') != "": parameters['poster'] = tvdb_base + show.get('poster')
    else: parameters['poster'] = get_icon("metalliq")
    parameters['thumbnail'] = "http://thetvdb.com/banners/episodes/" + str(show['id']) + "/" + str(parameters['epid']) + ".jpg"
    if show.get('banner') != "": parameters['banner'] = tvdb_base + show.get('banner')
    else: parameters['banner'] = get_banner_path()
    if show.get('fanart') != None and show.get('fanart') != "": parameters['fanart'] = tvdb_base + show.get('fanart')
    else: parameters['fanart'] = get_background_path()
    is_anime = False
    if parameters['genres'] != None and parameters['absolute_number'] and parameters['absolute_number'] != '0' and "animation" in parameters['genres'].lower():
        tmdb_results = tmdb.Find(show['id']).info(external_source="tvdb_id")
        for tmdb_show in tmdb_results.get("tv_results", []):
            if "JP" in tmdb_show['origin_country']:
                is_anime = True
    if is_anime:
        parameters['name'] = u'{showname} {absolute_number}'.format(**parameters)
    else:
        parameters['name'] = u'{showname} S{season:02d}E{episode:02d}'.format(**parameters)
    parameters['now'] = datetime.datetime.now().strftime('%Y%m%d%H%M%S%f')
    return parameters