Unofficial Python API for the Movielens unpublished API, using the requests
module. Tested with Python 2.7 and 3.6, but should be compatible with more.
You can either clone the repository and install the package with pip:
$ git clone git://github.com/Mello-Yello/movielens-private-api.git
$ cd movielens-private-api
$ python -m pip install .
Or directly from PyPI:
$ python -m pip install movielens-private-api
Since operations are performed on a specific account, you need to either log in or provide the HTTP cookie containing a valid session.
from movielens_private_api import Movielens
m = Movielens()
cookie = m.login(username, password)
The variable cookie from above can be saved to a file to be reused later during class initialization
from movielens_private_api import Movielens
m = Movielens(cookie)
If the class wasn't initiated with a cookie, calling any method before login()
will raise a MovielensException
. This class encapsulates any API error received in the response, and is raised after an improper request. To access the original error message you have to catch the exception and use str()
on it.
from movielens_private_api import Movielens, MovielensException
m = Movielens()
try:
m.getMe()
except MovielensException as e:
msg = str(e)
print(msg)
--------------------------------------
Output: "authenticated user required"
Movielens(cookie=None, timeoutSececonds=30, api_endpoint='https://movielens.org/api/', verifySSL=True)
cookie
: The HTTP cookie for movielens with a valid sessiontimeoutSececonds
: An exception is raised if the server has not issued a response for timeoutSececonds secondsapi_endpoint
: The api endpoint to connect toverifySSL
: Whether or not to verify SSL
Logs into the provided account, and returns the HTTP cookie
Obtain information about the user: number of movies rated, email, username, time of account creation, time of last login, preferences, recommender used, ...
Statistics on movie related tags the user has left on different films. E.g. desert, black comedy, zombie
History of ratings, rating distribution, list of movies rated much more or much less that the average.
All of the methods here have the params parameter, a dictionary with parameters to pass to the request. Possible parameters are listed in the documentation for explore(). params is optional for all the methods, and if provided is forwarded to explore()
Used to query Movielens, it can perform searches with various parameters.
q
: string --> Is used to specify the title searchsortBy
: string --> Possible values include: prediction, releaseDate, avgRating, dateAdded, userRatedDate, userListedDatehasWishlisted
: string in ['yes', 'no', 'ignore'] --> Show wishlisted movies onlyhasRated
: string in ['yes', 'no'', 'ignore'] --> Show rated movies onlyhasHidden
: string in ['yes', 'no'', 'ignore'] --> Show hidden movies only
m.explore({'q': 'Dune'})
Returns suggested movies based on the given ratings and the chosen recommender
Returns recently released movies
Returns a selection of higly rated movies from the previous year
Returns movies recently added to Movielens
Returns movies rated by the user
Returns movies added to the whishlist by the user
getMyHiddenMovies(params)
Returns movies hidden by the user
Rate a movie on a scale from 0 to 5, with half values (like 3.5) accepted.
Add a movie to the user whishlist
Hide a movie from the user. Equivalent to rating the movie -1
Remove a movie from the user whishlist
Delete the rating for the given movie.
Unhide a hidden movie. Calls resetRating()
Returns both the movie info and the interaction the user had with the movie (rating, hidden, wishlisted, predicted score, ....)
Statistics on how many movies are in Movielens, divided by genre. Also the most frequent tags for each genre