How to use the trakt.utils.extract_ids function in trakt

To help you get started, we’ve selected a few trakt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github moogar0880 / PyTrakt / tests / test_utils.py View on Github external
def test_extract_ids():
    """verify that id dicts can be correctly extracted"""
    ids = dict(trakt=443, tvdb=4851180, imdb='tt3500614', tmdb=988123,
               tvrage=None)
    input_dict = {'ids': ids}
    result = extract_ids(input_dict)
    assert result == ids
github moogar0880 / PyTrakt / trakt / people.py View on Github external
def _build(self, data):
        extract_ids(data)
        for key, val in data.items():
            try:
                setattr(self, key, val)
            except AttributeError as ae:
                if not hasattr(self, '_' + key):
                    raise ae
github pymedusa / Medusa / ext / trakt / tv.py View on Github external
def watched_shows():
    data = yield 'shows/watched'
    shows = []
    for show in data:
        data = show.get('ids', {})
        extract_ids(data)
        data['year'] = show['year']
        shows.append(TVShow(show['title'], **data))
    yield shows
github moogar0880 / PyTrakt / trakt / sync.py View on Github external
"""Perform a search query by using a Trakt.tv ID or other external ID

    :param query: Your search string
    :param id_type: The type of object you're looking for. Must be one of
        'trakt-movie', 'trakt-show', 'trakt-episode', 'imdb', 'tmdb', 'tvdb' or
        'tvrage'
    """
    valids = ('trakt-movie', 'trakt-show', 'trakt-episode', 'imdb', 'tmdb',
              'tvdb', 'tvrage')
    if id_type not in valids:
        raise ValueError('search_type must be one of {}'.format(valids))
    data = yield 'search?id={query}&id_type={id_type}'.format(
        query=slugify(query), id_type=id_type)

    for media_item in data:
        extract_ids(media_item)

    results = []
    for d in data:
        if 'episode' in d:
            from trakt.tv import TVEpisode
            show = d.pop('show')
            extract_ids(d['episode'])
            results.append(TVEpisode(show['title'], **d['episode']))
        elif 'movie' in d:
            from trakt.movies import Movie
            results.append(Movie(**d.pop('movie')))
        elif 'show' in d:
            from trakt.tv import TVShow
            results.append(TVShow(**d.pop('show')))
        elif 'person' in d:
            from trakt.people import Person
github moogar0880 / PyTrakt / trakt / users.py View on Github external
def show_collection(self):
        """All :class:`TVShow`'s in this :class:`User`'s library collection.
        Collection items might include blu-rays, dvds, and digital downloads.
        Protected users won't return any data unless you are friends.
        """
        if self._show_collection is None:
            ext = 'users/{username}/collection/shows?extended=metadata'
            data = yield ext.format(username=self.username)
            self._show_collection = []
            for show in data:
                s = show.pop('show')
                extract_ids(s)
                sh = TVShow(**s)
                sh._seasons = [TVSeason(show=sh.title, **sea)
                               for sea in show.pop('seasons')]
                self._show_collection.append(sh)
        yield self._show_collection
github moogar0880 / PyTrakt / trakt / sync.py View on Github external
valids = ('trakt-movie', 'trakt-show', 'trakt-episode', 'imdb', 'tmdb',
              'tvdb', 'tvrage')
    if id_type not in valids:
        raise ValueError('search_type must be one of {}'.format(valids))
    data = yield 'search?id={query}&id_type={id_type}'.format(
        query=slugify(query), id_type=id_type)

    for media_item in data:
        extract_ids(media_item)

    results = []
    for d in data:
        if 'episode' in d:
            from trakt.tv import TVEpisode
            show = d.pop('show')
            extract_ids(d['episode'])
            results.append(TVEpisode(show['title'], **d['episode']))
        elif 'movie' in d:
            from trakt.movies import Movie
            results.append(Movie(**d.pop('movie')))
        elif 'show' in d:
            from trakt.tv import TVShow
            results.append(TVShow(**d.pop('show')))
        elif 'person' in d:
            from trakt.people import Person
            results.append(Person(**d.pop('person')))
    yield results
github pymedusa / Medusa / ext / trakt / sync.py View on Github external
"""
    valids = ('movies', 'shows')
    if media_type not in valids:
        raise ValueError('search_type must be one of {}'.format(valids))
    data = yield 'sync/collection/{media_type}{extended}'.format(
        media_type=media_type, extended=('', '?extended=metadata')[extended]
    )
    to_ret = []
    for item in data:
        to_ret = []
        if media_type == 'movies':
            extract_ids(item)
            to_ret.append(Movie(**item))
        else:  # media_type == 'shows'
            data = item.get('ids', {})
            extract_ids(data)
            data['year'] = item['year']
            to_ret.append(TVShow(item['title'], **data))
    yield to_ret
github pymedusa / Medusa / ext / trakt / sync.py View on Github external
if media_type not in valids:
        raise ValueError('search_type must be one of {}'.format(valids))
    data = yield 'sync/watched/{media_type}{extended}'.format(
        media_type=media_type, extended=('', '?extended=noseasons')[extended and media_type == 'shows']
    )
    to_ret = []
    for item in data:
        to_ret = []
        if media_type == 'movies':
            from trakt.movies import Movie
            extract_ids(item)
            to_ret.append(Movie(**item))
        else:  # media_type == 'shows'
            from trakt.tv import TVShow
            data = item.get('ids', {})
            extract_ids(data)
            data['year'] = item['year']
            to_ret.append(TVShow(item['title'], **data))
    yield to_ret
github pymedusa / Medusa / ext / trakt / tv.py View on Github external
def _build(self, data):
        extract_ids(data)
        for key, val in data.items():
            if hasattr(self, '_' + key):
                setattr(self, '_' + key, val)
            else:
                setattr(self, key, val)
github moogar0880 / PyTrakt / trakt / users.py View on Github external
def _get(cls, title, creator):
        """Returns a single custom :class:`UserList`

        :param title: Name of the list.
        """
        data = yield 'users/{user}/lists/{id}'.format(user=creator,
                                                      id=slugify(title))
        extract_ids(data)
        ulist = UserList(creator=creator, **data)
        ulist.get_items()

        yield ulist