Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@ def test_watched():
assert all([isinstance(s, TVShow) for s in sean.watched_shows])


def test_get_watched_movies():
sean = User('sean')
watched_movies = sean.get_watched_movies()
assert isinstance(watched_movies, list)
assert all([isinstance(m, Movie) for m in watched_movies])
Comment thread
Copilot marked this conversation as resolved.

Comment thread
glensc marked this conversation as resolved.

def test_stats():
sean = User('sean')
assert isinstance(sean.get_stats(), dict)
Expand Down
37 changes: 27 additions & 10 deletions trakt/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,22 +509,39 @@ def show_collection(self):
self._show_collection.append(show)
yield self._show_collection

@property
def _build_watched_movies(self, data):
"""Parse raw API response data into a list of :class:`Movie` objects.

:param data: List of raw movie dicts from the Trakt API
:return: List of :class:`Movie` instances
"""
watched_movies = []
for movie in data:
movie_data = movie.pop('movie')
movie_data.update(movie)
watched_movies.append(Movie(**movie_data))
return watched_movies
Comment thread
glensc marked this conversation as resolved.

@get
def get_watched_movies(self):
"""Watched progress for all :class:`Movie` objects for this
:class:`User`.

Comment thread
glensc marked this conversation as resolved.
:return: List of :class:`Movie` instances
"""
data = yield 'users/{user}/watched/movies'.format(
user=slugify(self.username)
)
yield self._build_watched_movies(data)

@property
def watched_movies(self):
"""Watched progress for all :class:`Movie`'s in this :class:`User`'s
collection.
"""
if self._watched_movies is None:
data = yield 'users/{user}/watched/movies'.format(
user=slugify(self.username)
)
self._watched_movies = []
for movie in data:
movie_data = movie.pop('movie')
movie_data.update(movie)
self._watched_movies.append(Movie(**movie_data))
yield self._watched_movies
self._watched_movies = self.get_watched_movies()
return self._watched_movies

@property
@get
Expand Down