def handle_tmdb_misc(results):
    listitems = []
    for item in results:
        artwork = get_image_urls(poster=item.get('poster_path'))
        listitem = {
            'title':
            Utils.clean_text(Utils.fetch(item, 'name')),
            'certification':
            Utils.fetch(item, 'certification') + Utils.fetch(item, 'rating'),
            'item_count':
            Utils.fetch(item, 'item_count'),
            'release_date':
            Utils.fetch(item, 'release_date'),
            'path':
            'plugin://script.extendedinfo?info=listmovies&---id=%s' %
            Utils.fetch(item, 'id'),
            'year':
            Utils.get_year(Utils.fetch(item, 'release_date')),
            'iso_3166_1':
            Utils.fetch(item, 'iso_3166_1').lower(),
            'author':
            Utils.fetch(item, 'author'),
            'content':
            Utils.clean_text(Utils.fetch(item, 'content')),
            'id':
            Utils.fetch(item, 'id'),
            'url':
            Utils.fetch(item, 'url'),
            'Description':
            Utils.clean_text(Utils.fetch(item, 'description'))
        }
        listitem.update(artwork)
        listitems.append(listitem)
    return listitems
def handle_tmdb_episodes(results):
    listitems = []
    for item in results:
        title = Utils.clean_text(Utils.fetch(item, 'name'))
        if not title:
            title = '%s %s' % ('Episode', Utils.fetch(item, 'episode_number'))
        try:
            artwork = get_image_urls(still=item.get('still_path'))
        except:
            artwork = []
        listitem = {
            'media_type': 'episode',
            'title': title,
            'release_date': Utils.fetch(item, 'air_date'),
            'episode': Utils.fetch(item, 'episode_number'),
            'production_code': Utils.fetch(item, 'production_code'),
            'season': Utils.fetch(item, 'season_number'),
            'Rating': round(float(Utils.fetch(item, 'vote_average')), 1),
            'Votes': Utils.fetch(item, 'vote_count'),
            'Plot': Utils.fetch(item, 'overview'),
            'id': Utils.fetch(item, 'id'),
            'Description': Utils.clean_text(Utils.fetch(item, 'overview'))
        }
        listitem.update(artwork)
        date = Utils.fetch(item, 'air_date')
        listitems.append(listitem)
    return listitems
def handle_tmdb_people(results):
    people = []
    for person in results:
        artwork = get_image_urls(profile=person.get('profile_path'))
        also_known_as = ' / '.join(Utils.fetch(person, 'also_known_as'))
        newperson = {
            'adult':
            str(Utils.fetch(person, 'adult')),
            'name':
            person['name'],
            'title':
            person['name'],
            'also_known_as':
            also_known_as,
            'alsoknownas':
            also_known_as,
            'biography':
            Utils.clean_text(Utils.fetch(person, 'biography')),
            'birthday':
            Utils.fetch(person, 'birthday'),
            'age':
            Utils.calculate_age(Utils.fetch(person, 'birthday'),
                                Utils.fetch(person, 'deathday')),
            'character':
            Utils.fetch(person, 'character'),
            'department':
            Utils.fetch(person, 'department'),
            'job':
            Utils.fetch(person, 'job'),
            'media_type':
            'person',
            'id':
            str(person['id']),
            'cast_id':
            str(Utils.fetch(person, 'cast_id')),
            'credit_id':
            str(Utils.fetch(person, 'credit_id')),
            'path':
            'plugin://script.extendedinfo?info=extendedactorinfo&&id=' +
            str(person['id']),
            'deathday':
            Utils.fetch(person, 'deathday'),
            'place_of_birth':
            Utils.fetch(person, 'place_of_birth'),
            'placeofbirth':
            Utils.fetch(person, 'place_of_birth'),
            'homepage':
            Utils.fetch(person, 'homepage')
        }
        newperson.update(artwork)
        people.append(newperson)
    return people
Beispiel #4
0
 def show_review(self):
     author = self.listitem.getProperty('author')
     text = '[B]%s[/B][CR]%s' % (
         author, Utils.clean_text(self.listitem.getProperty('content')))
     wm.open_textviewer(header='Plot', text=text, color='FFFFFFFF')
def extended_episode_info(tvshow_id, season, episode, cache_time=7):
    if not tvshow_id or not episode:
        return None
    if not season:
        season = 0
    session_str = ''
    tvshow = get_tmdb_data(
        'tv/%s?append_to_response=alternative_titles,content_ratings,credits,external_ids,images,keywords,rating,similar,translations,videos&language=%s&include_image_language=en,null,%s&%s'
        % (tvshow_id, xbmcaddon.Addon().getSetting('LanguageID'),
           xbmcaddon.Addon().getSetting('LanguageID'), session_str), 99999)
    response = get_tmdb_data(
        'tv/%s/season/%s/episode/%s?append_to_response=credits,external_ids,images,rating,videos&language=%s&include_image_language=en,null,%s&%s&'
        % (tvshow_id, season,
           episode, xbmcaddon.Addon().getSetting('LanguageID'),
           xbmcaddon.Addon().getSetting('LanguageID'), session_str),
        cache_time)
    tmdb_id = Utils.fetch(tvshow, 'id')
    TVShowTitle = Utils.fetch(tvshow, 'name')
    external_ids = Utils.fetch(tvshow, 'external_ids')
    year = Utils.get_year(Utils.fetch(tvshow, 'first_air_date')),
    if external_ids:
        imdb_id = Utils.fetch(external_ids, 'imdb_id')
        freebase_id = Utils.fetch(external_ids, 'freebase_id')
        tvdb_id = Utils.fetch(external_ids, 'tvdb_id')
        tvrage_id = Utils.fetch(external_ids, 'tvrage_id')
    videos = handle_tmdb_videos(
        response['videos']['results']) if 'videos' in response else []
    try:
        actors = handle_tmdb_people(response['credits']['cast'])
    except:
        actors = []
    try:
        crew = handle_tmdb_people(response['credits']['crew'])
    except:
        crew = []
    try:
        guest_stars = handle_tmdb_people(response['credits']['guest_stars'])
    except:
        guest_stars = []
    try:
        images = handle_tmdb_images(response['images']['stills'])
    except:
        images = []
    answer = {
        'SeasonDescription':
        Utils.clean_text(response['overview']),
        'Plot':
        Utils.clean_text(response['overview']),
        'TVShowTitle':
        TVShowTitle,
        'tvshow_id':
        tmdb_id,
        'tvdb_id':
        tvdb_id,
        'actors':
        actors,
        'path':
        'plugin://script.extendedinfo?info=extendedepisodeinfo&tvshow_id=%s&season=%s&episode=%s'
        % (tvshow_id, season, episode),
        'crew':
        crew,
        'guest_stars':
        guest_stars,
        'videos':
        videos,
        'images':
        images
    }
    return (handle_tmdb_episodes([response])[0], answer)
def extended_season_info(tvshow_id, season_number):
    if not tvshow_id or not season_number:
        return None
    session_str = ''
    tvshow = get_tmdb_data(
        'tv/%s?append_to_response=alternative_titles,content_ratings,credits,external_ids,images,keywords,rating,similar,translations,videos&language=%s&include_image_language=en,null,%s&%s'
        % (tvshow_id, xbmcaddon.Addon().getSetting('LanguageID'),
           xbmcaddon.Addon().getSetting('LanguageID'), session_str), 99999)
    response = get_tmdb_data(
        'tv/%s/season/%s?append_to_response=videos,images,external_ids,credits&language=%s&include_image_language=en,null,%s&'
        %
        (tvshow_id, season_number, xbmcaddon.Addon().getSetting('LanguageID'),
         xbmcaddon.Addon().getSetting('LanguageID')), 7)
    dbid = Utils.fetch(tvshow, 'dbid')
    tmdb_id = Utils.fetch(tvshow, 'id')
    external_ids = Utils.fetch(tvshow, 'external_ids')
    year = Utils.get_year(Utils.fetch(tvshow, 'first_air_date'))
    if external_ids:
        imdb_id = Utils.fetch(external_ids, 'imdb_id')
        freebase_id = Utils.fetch(external_ids, 'freebase_id')
        tvdb_id = Utils.fetch(external_ids, 'tvdb_id')
        tvrage_id = Utils.fetch(external_ids, 'tvrage_id')
    if not response:
        Utils.notify('Could not find season info')
        return None
    if response.get('name', False):
        title = response['name']
    else:
        title = 'Specials' if season_number == '0' else u'Season %s' % season_number
    season = {
        'SeasonDescription':
        Utils.clean_text(response['overview']),
        'Plot':
        Utils.clean_text(response['overview']),
        'TVShowTitle':
        Utils.fetch(tvshow, 'name'),
        'title':
        title,
        'dbid':
        dbid,
        'imdb_id':
        imdb_id,
        'tmdb_id':
        tmdb_id,
        'tvdb_id':
        tvdb_id,
        'tvrage_id':
        tvrage_id,
        'year':
        year,
        'season':
        season_number,
        'path':
        'plugin://script.extendedinfo?info=seasoninfo&tvshow=%s&season=%s' %
        (Utils.fetch(tvshow, 'name'), season_number),
        'release_date':
        response['air_date'],
        'AirDate':
        response['air_date']
    }
    artwork = get_image_urls(poster=response.get('poster_path'))
    season.update(artwork)
    videos = handle_tmdb_videos(
        response['videos']['results']) if 'videos' in response else []
    listitems = {
        'actors': handle_tmdb_people(response['credits']['cast']),
        'crew': handle_tmdb_people(response['credits']['crew']),
        'videos': videos,
        'episodes': handle_tmdb_episodes(response['episodes']),
        'images': handle_tmdb_images(response['images']['posters'])
    }
    return (season, listitems)
def extended_tvshow_info(tvshow_id=None, cache_time=7, dbid=None):
    if not tvshow_id:
        return None
    session_str = ''
    response = get_tmdb_data(
        'tv/%s?append_to_response=alternative_titles,content_ratings,credits,external_ids,images,keywords,rating,similar,translations,videos&language=%s&include_image_language=en,null,%s&%s'
        % (tvshow_id, xbmcaddon.Addon().getSetting('LanguageID'),
           xbmcaddon.Addon().getSetting('LanguageID'), session_str),
        cache_time)
    if not response:
        return False
    videos = handle_tmdb_videos(
        response['videos']['results']) if 'videos' in response else []
    tmdb_id = Utils.fetch(response, 'id')
    external_ids = Utils.fetch(response, 'external_ids')
    if external_ids:
        imdb_id = Utils.fetch(external_ids, 'imdb_id')
        freebase_id = Utils.fetch(external_ids, 'freebase_id')
        tvdb_id = Utils.fetch(external_ids, 'tvdb_id')
        tvrage_id = Utils.fetch(external_ids, 'tvrage_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 = Utils.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': Utils.fetch(response, 'name'),
        'TVShowTitle': Utils.fetch(response, 'name'),
        'OriginalTitle': Utils.fetch(response, 'original_name'),
        'duration': duration,
        'duration(h)': Utils.format_time(duration, 'h'),
        'duration(m)': Utils.format_time(duration, 'm'),
        'id': tmdb_id,
        'tmdb_id': tmdb_id,
        'imdb_id': imdb_id,
        'freebase_id': freebase_id,
        'tvdb_id': tvdb_id,
        'tvrage_id': tvrage_id,
        'mpaa': mpaa,
        'genre': ' / '.join(genres),
        'credit_id': Utils.fetch(response, 'credit_id'),
        'Plot': Utils.clean_text(Utils.fetch(response, 'overview')),
        'year': Utils.get_year(Utils.fetch(response, 'first_air_date')),
        'media_type': 'tv',
        'Popularity': Utils.fetch(response, 'popularity'),
        'Rating': Utils.fetch(response, 'vote_average'),
        'country': Utils.fetch(response, 'original_language'),
        'User_Rating': str(Utils.fetch(response, 'rating')),
        'Votes': Utils.fetch(response, 'vote_count'),
        'Status': translate_status(Utils.fetch(response, 'status')),
        'path':
        'plugin://script.extendedinfo?info=extendedtvinfo&&id=%s' % tvshow_id,
        'trailer':
        'plugin://script.extendedinfo?info=playtvtrailer&&id=%s' % tvshow_id,
        'ShowType': Utils.fetch(response, 'type'),
        'homepage': Utils.fetch(response, 'homepage'),
        'last_air_date': Utils.fetch(response, 'last_air_date'),
        'first_air_date': Utils.fetch(response, 'first_air_date'),
        'TotalEpisodes': Utils.fetch(response, 'number_of_episodes'),
        'TotalSeasons': Utils.fetch(response, 'number_of_seasons'),
        'in_production': Utils.fetch(response, 'in_production'),
        'Release_Date': Utils.fetch(response, 'first_air_date'),
        'Premiered': Utils.fetch(response, 'first_air_date')
    }
    tvshow.update(artwork)
    if dbid:
        local_item = local_db.get_tvshow_from_db(dbid)
        tvshow.update(local_item)
    else:
        tvshow = local_db.merge_with_local_tvshow_info([tvshow])[0]
    tvshow['Rating'] = Utils.fetch(response, 'vote_average')
    listitems = {
        'actors': handle_tmdb_people(response['credits']['cast']),
        'similar': handle_tmdb_tvshows(response['similar']['results']),
        'studios': handle_tmdb_misc(response['production_companies']),
        'networks': handle_tmdb_misc(response['networks']),
        'certifications':
        handle_tmdb_misc(response['content_ratings']['results']),
        'crew': handle_tmdb_people(response['credits']['crew']),
        'genres': handle_tmdb_misc(response['genres']),
        'keywords': handle_tmdb_misc(response['keywords']['results']),
        'videos': videos,
        'seasons': handle_tmdb_seasons(response['seasons']),
        'images': handle_tmdb_images(response['images']['posters']),
        'backdrops': handle_tmdb_images(response['images']['backdrops'])
    }
    return (tvshow, listitems)
def extended_movie_info(movie_id=None, dbid=None, cache_time=14):
    if not movie_id:
        return None
    session_str = ''
    response = get_tmdb_data(
        'movie/%s?append_to_response=alternative_titles,credits,images,keywords,releases,videos,translations,similar,reviews,rating&include_image_language=en,null,%s&language=%s&%s'
        % (movie_id, xbmcaddon.Addon().getSetting('LanguageID'),
           xbmcaddon.Addon().getSetting('LanguageID'), session_str),
        cache_time)
    if not response:
        Utils.notify('Could not get movie information', sound=False)
        return {}
    mpaa = ''
    set_name = ''
    set_id = ''
    genres = [i['name'] for i in response['genres']]
    Studio = [i['name'] for i in response['production_companies']]
    authors = [
        i['name'] for i in response['credits']['crew']
        if i['department'] == 'Writing'
    ]
    directors = [
        i['name'] for i in response['credits']['crew']
        if i['department'] == 'Directing'
    ]
    us_cert = Utils.dictfind(response['releases']['countries'], 'iso_3166_1',
                             'US')
    if us_cert:
        mpaa = us_cert['certification']
    elif response['releases']['countries']:
        mpaa = response['releases']['countries'][0]['certification']
    movie_set = Utils.fetch(response, 'belongs_to_collection')
    if movie_set:
        set_name = Utils.fetch(movie_set, 'name')
        set_id = Utils.fetch(movie_set, 'id')
    artwork = get_image_urls(poster=response.get('poster_path'),
                             fanart=response.get('backdrop_path'))
    movie = {
        'title':
        Utils.fetch(response, 'title'),
        'Label':
        Utils.fetch(response, 'title'),
        'Tagline':
        Utils.fetch(response, 'tagline'),
        'duration':
        Utils.fetch(response, 'runtime'),
        'duration(h)':
        Utils.format_time(Utils.fetch(response, 'runtime'), 'h'),
        'duration(m)':
        Utils.format_time(Utils.fetch(response, 'runtime'), 'm'),
        'duration(hm)':
        Utils.format_time(Utils.fetch(response, 'runtime')),
        'mpaa':
        mpaa,
        'Director':
        ' / '.join(directors),
        'writer':
        ' / '.join(authors),
        'Budget':
        Utils.millify(Utils.fetch(response, 'budget')),
        'Revenue':
        Utils.millify(Utils.fetch(response, 'revenue')),
        'Homepage':
        Utils.fetch(response, 'homepage'),
        'Set':
        set_name,
        'SetId':
        set_id,
        'id':
        Utils.fetch(response, 'id'),
        'tmdb_id':
        Utils.fetch(response, 'id'),
        'imdb_id':
        Utils.fetch(response, 'imdb_id'),
        'Plot':
        Utils.clean_text(Utils.fetch(response, 'overview')),
        'OriginalTitle':
        Utils.fetch(response, 'original_title'),
        'Country':
        Utils.fetch(response, 'original_language'),
        'genre':
        ' / '.join(genres),
        'Rating':
        Utils.fetch(response, 'vote_average'),
        'Votes':
        Utils.fetch(response, 'vote_count'),
        'Adult':
        str(Utils.fetch(response, 'adult')),
        'Popularity':
        Utils.fetch(response, 'popularity'),
        'Status':
        translate_status(Utils.fetch(response, 'status')),
        'release_date':
        Utils.fetch(response, 'release_date'),
        'Premiered':
        Utils.fetch(response, 'release_date'),
        'Studio':
        ' / '.join(Studio),
        'year':
        Utils.get_year(Utils.fetch(response, 'release_date')),
        'path':
        'plugin://script.extendedinfo?info=extendedinfo&&id=%s' % movie_id,
        'trailer':
        'plugin://script.extendedinfo?info=playtrailer&&id=%s' % movie_id
    }
    movie.update(artwork)
    videos = handle_tmdb_videos(
        response['videos']['results']) if 'videos' in response else []
    if dbid:
        local_item = local_db.get_movie_from_db(dbid)
        movie.update(local_item)
    else:
        movie = local_db.merge_with_local_movie_info([movie])[0]
    movie['Rating'] = Utils.fetch(response, 'vote_average')
    listitems = {
        'actors': handle_tmdb_people(response['credits']['cast']),
        'similar': handle_tmdb_movies(response['similar']['results']),
        'studios': handle_tmdb_misc(response['production_companies']),
        'releases': handle_tmdb_misc(response['releases']['countries']),
        'crew': handle_tmdb_people(response['credits']['crew']),
        'genres': handle_tmdb_misc(response['genres']),
        'keywords': handle_tmdb_misc(response['keywords']['keywords']),
        'reviews': handle_tmdb_misc(response['reviews']['results']),
        'videos': videos,
        'images': handle_tmdb_images(response['images']['posters']),
        'backdrops': handle_tmdb_images(response['images']['backdrops'])
    }
    return (movie, listitems)