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_trending_movies():
trending = trending_movies()
assert isinstance(trending, list)
assert len(trending) == 2
assert isinstance(trending[0], Movie)
def test_utilities():
tron = Movie('Tron Legacy 2010')
functions = [tron.add_to_library, tron.add_to_collection,
tron.add_to_watchlist, tron.dismiss, tron.mark_as_unseen,
tron.remove_from_library, tron.remove_from_collection,
tron.remove_from_watchlist, tron.mark_as_seen]
for fn in functions:
r = fn()
assert r is None
def test_movie_str():
tron = Movie('Tron Legacy 2010')
assert str(tron) == ': {0}'.format(tron.title)
assert str(tron) == repr(tron)
def test_movie_to_json_singular():
tron = Movie('Tron Legacy', year=2010)
expected = {'movie': {'title': tron.title,
'year': 2010,
'ids': {'imdb': 'tt1104001',
'slug': 'tron-legacy-2010',
'tmdb': 20526,
'trakt': 343}}}
assert tron.to_json_singular() == expected
def test_movie_people():
tron = Movie('Tron Legacy', year=2010)
sub_groups = ['people', 'cast', 'crew']
for group in sub_groups:
persons = getattr(tron, group)
assert isinstance(persons, list)
assert len(persons) >= 1
assert isinstance(persons[0], Person)
assert all(isinstance(p, Person) for p in persons)
def movie_collection(self):
"""All :class:`Movie`'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._movie_collection is None:
ext = 'users/{username}/collection/movies?extended=metadata'
data = yield ext.format(username=self.username)
self._movie_collection = []
for movie in data:
mov = movie.pop('movie')
extract_ids(mov)
self._movie_collection.append(Movie(**mov))
yield self._movie_collection
if search_type is None:
search_type = ['movie', 'show', 'episode', 'person']
uri = 'search/{type}?query={query}'.format(
query=slugify(query), type=','.join(search_type))
data = yield uri
# Need to do imports here to prevent circular imports with modules that
# need to import Scrobblers
results = []
for media_item in data:
extract_ids(media_item)
result = SearchResult(media_item['type'], media_item['score'])
if media_item['type'] == 'movie':
from trakt.movies import Movie
result.media = Movie(**media_item.pop('movie'))
elif media_item['type'] == 'show':
from trakt.tv import TVShow
result.media = TVShow(**media_item.pop('show'))
elif media_item['type'] == 'episode':
from trakt.tv import TVEpisode
show = media_item.pop('show')
result.media = TVEpisode(show.get('title', None),
**media_item.pop('episode'))
elif media_item['type'] == 'person':
from trakt.people import Person
result.media = Person(**media_item.pop('person'))
results.append(result)
yield results
If media_type is set to shows and you enable extended. `?extended=noseasons` is
added to the URL, it won't return season or episode info.
"""
valids = ('movies', 'shows')
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 get_recommended_movies():
"""Get a list of :class:`Movie`'s recommended based on your watching
history and your friends. Results are returned with the top recommendation
first.
"""
data = yield 'recommendations/movies'
movies = []
for movie in data:
extract_ids(movie)
movies.append(Movie(**movie))
yield movies
def __movie_list(self, url):
"""Return a list of :class:`Movie` objects returned from the provided
url
"""
response = requests.get(url)
data = json.loads(response.content.decode('UTF-8'))
to_ret = None
if len(data) > 0:
to_ret = []
for movie_data in data:
title = movie_data.get('title', None)
to_ret.append(Movie(title, **movie_data))
return to_ret