示例#1
0
def get_trakt_externals(externals):
    """Small trakt api wrapper, to request trakt externals using multiple external id's.

    :param externals: Dictionary of key/value pairs with external id's.
    """
    trakt_mapping = {
        'tvdb_id': 'tvdb',
        'imdb_id': 'imdb',
        'tmdb_id': 'tmdb',
        'trakt_id': 'trakt'
    }
    trakt_mapping_rev = {v: k for k, v in viewitems(trakt_mapping)}

    for external_key in externals:
        if not trakt_mapping.get(external_key) or not externals[external_key]:
            continue

        log.debug(
            u'Looking for externals using Trakt and {indexer} id {number}', {
                'indexer': trakt_mapping[external_key],
                'number': externals[external_key],
            })

        try:
            result = sync.search_by_id(externals[external_key],
                                       id_type=trakt_mapping[external_key],
                                       media_type='show')
        except TraktException as error:
            log.warning(
                'Error getting external key {external}, error: {error!r}', {
                    'external': trakt_mapping[external_key],
                    'error': error
                })
            return {}

        if result and len(result) and result[0].ids.get('ids'):
            ids = {
                trakt_mapping_rev[k]: v
                for k, v in result[0].ids.get('ids').items()
                if v and trakt_mapping_rev.get(k)
            }
            return ids
    return {}
示例#2
0
def test_search_by_id_with_multiple_results():
    """test that searching by id search results are successfully returned when
    there are multiple types"""
    results = search_by_id('78845', id_type='tvdb', media_type='show')
    assert isinstance(results, list)
示例#3
0
def test_search_person_by_id():
    """test that person by id search results are successfully returned"""
    results = search_by_id('nm0186505', id_type='imdb')
    assert isinstance(results, list)
    assert all(isinstance(p, Person) for p in results)
示例#4
0
def test_search_show_by_id_with_explicit_type():
    """test that tv show by id search results are successfully returned when
    explicitly adding the media type"""
    results = search_by_id('78845', id_type='tvdb', media_type='show')
    assert isinstance(results, list)
示例#5
0
def test_search_show_by_id():
    """test that tv show by id search results are successfully returned"""
    results = search_by_id('tt0372784', id_type='imdb')
    assert isinstance(results, list)
示例#6
0
def test_search_episode_by_id():
    """test that tv episode by id search results are successfully returned"""
    results = search_by_id('28585', id_type='tmdb')
    assert isinstance(results, list)
    assert len(results) == 3
示例#7
0
def test_search_movie_by_id():
    """test that movie by id search results are successfully returned"""
    results = search_by_id('tt0372784', id_type='imdb')
    assert isinstance(results, list)
    assert all(isinstance(m, Movie) for m in results)
示例#8
0
def test_search_person_by_id():
    """test that person by id search results are successfully returned"""
    results = search_by_id('nm0186505', id_type='imdb')
    assert isinstance(results, list)
    assert all(isinstance(p, Person) for p in results)
示例#9
0
def test_search_episode_by_id():
    """test that tv episode by id search results are successfully returned"""
    results = search_by_id('28585', id_type='tmdb')
    assert isinstance(results, list)
    assert len(results) == 3
示例#10
0
def test_search_show_by_id():
    """test that tv show by id search results are successfully returned"""
    results = search_by_id('tt0372784', id_type='imdb')
    assert isinstance(results, list)
示例#11
0
def test_search_movie_by_id():
    """test that movie by id search results are successfully returned"""
    results = search_by_id('tt0372784', id_type='imdb')
    assert isinstance(results, list)
    assert all(isinstance(m, Movie) for m in results)