Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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
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
"""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
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
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
"""
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
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
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)
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