fuzeman / trakt.py Goto Github PK
View Code? Open in Web Editor NEWPython interface for the Trakt.tv API
Home Page: http://traktpy.readthedocs.org
License: MIT License
Python interface for the Trakt.tv API
Home Page: http://traktpy.readthedocs.org
License: MIT License
Hey fuzeman, do you mind adding the methods named here to your module? They are needed for the official kodi trakt addon to make manual ratings to work. For more info see my comment in the script.trakt repository: trakt/script.trakt#183 (comment)
Hey there,
seems to me like there are some calls missing from documentation, can't firgure out how to get a movie or show by id.
Rating examples would be apreciated too.
Thanks
File "/home/vagrant/tvrenamer/.tox/cover34/lib/python3.4/site-packages/trakt/interfaces/shows/__init__.py", line 56, in episode
self.get_data(response)
File "/home/vagrant/tvrenamer/.tox/cover34/lib/python3.4/site-packages/trakt/mapper/summary.py", line 101, in episode
if 'episode' in item:
TypeError: argument of type 'NoneType' is not iterable
requests.packages.urllib3.connectionpool: DEBUG: "GET /search?query=Firefly&type=show HTTP/1.1" 200 None
requests.packages.urllib3.connectionpool: DEBUG: "GET /shows/1428/seasons/5/episodes/1 HTTP/1.1" 404 None
trakt.interfaces.base: DEBUG: response returned content-type: 'text/html', falling back to raw data
trakt.interfaces.base: WARNING: request failed: Not Found - "method exists, but no record found" (code: 404)
Because the status code is 404, and exceptions are turned off it seems, it will return None
# Return `None` if we encountered an error, return response data
if error:
return None
@classmethod
def episode(cls, client, item, **kwargs):
if 'episode' in item:
i_episode = item['episode']
else:
i_episode = item
Because the check for the string episode
in item, and because it is None
, the TypeError
is being raised.
Looks like the Trakt.tv API spec allows for extended info for list items: https://trakt.docs.apiary.io/#reference/users/list-items/get-items-on-a-custom-list
I imagine this is a similar enhancement to #57
The dates seem to be datetime objects, would be nice if these could be strings.
Here is an example:
{
'plays': None,
'collected_at': datetime.datetime(2014,
5,
18,
23,
12,
10),
'collected': 1,
'watched': 0,
'number': 19,
'ids': {
}
},
Sorry for the horrible title I didn't know how to phrase it . Basically unless I missed something currently with this library it's impossible to get the last watched history ( http://docs.trakt.apiary.io/#reference/sync/get-history/get-watched-history ).
Hey Dean,
I thought you mentioned somewhere that the sync endpoint should be completely integrated, what about the progress endpoint? http://docs.trakt.apiary.io/#reference/sync/playback/get-playback-progress
If it's already there, can you give me an example call, as my suspected code did not work.
Thanks
Hey,
I can't seem to find a way to get extended information from Trakt['sync/watchlist'].movies(extended='full')
.
On Trakt.tv's API 'Get watchlist' is said to have the extended info option.
http://docs.trakt.apiary.io/reference/sync/get-watchlist/get-watchlist
It also states that you can have the API sort the items for you, then send them to you, but I can't seem find the way to do that in trakt.py.
It appears the API doesn't handle that (tried testing using Apiary)
Posted in the Trakt API G+ community
Sorting for watchlist isn't an option, I misread the API docs, see https://plus.google.com/u/0/106638395660757564216/posts/THrT7croDVQ
Am I missing something here, or is it just not implemented?
Traceback (most recent call last):
File "C:\Project\.venv\lib\site-packages\tornado\web.py", line 1509, in _execute
result = method(*self.path_args, **self.path_kwargs)
File "main.py", line 102, in get
return dispatcher()
File "main.py", line 125, in watchlist
watchlist = TraktAPI.get_movies_watchlist()
File "C:\Project\trakt_api.py", line 57, in get_movies_watchlist
watchlist = Trakt['sync/watchlist'].movies(extended='full', pagination=True, per_page=100)
File "C:\Project\.venv\lib\site-packages\trakt\interfaces\base\__init__.py", line 22, in wrap
return func(*args, **kwargs)
File "C:\Project\.venv\lib\site-packages\trakt\interfaces\sync\core\mixins.py", line 61, in movies
**kwargs
File "C:\Project\.venv\lib\site-packages\trakt\interfaces\sync\watchlist.py", line 26, in get
**kwargs
File "C:\Project\.venv\lib\site-packages\trakt\interfaces\base\__init__.py", line 22, in wrap
return func(*args, **kwargs)
File "C:\Project\.venv\lib\site-packages\trakt\interfaces\sync\core\mixins.py", line 32, in get
items = self.get_data(response, **kwargs)
TypeError: get_data() got an unexpected keyword argument 'extended'
It is possible to retrieve the friends and following of a give user? The methods from trakt API: /users/id/friends /users/id/following
I would like to implement list of friends I follow to be able to see their lists and watched history.
Thanks
So I'm not using oAuth for kodi, but I get these messages in the log file here and there.
19:38:56 T:11220 DEBUG: [script.trakt] requests.packages.urllib3.connectionpool: "POST /scrobble/start HTTP/1.1" 520 None
19:38:56 T:11220 WARNING: [script.trakt] trakt.core.http: Continue retry since status is 520, waiting 5 seconds
19:39:01 T:11220 WARNING: [script.trakt] trakt.core.http: Retry # 1
19:39:01 T:11220 DEBUG: [script.trakt] requests.packages.urllib3.connectionpool: "POST /scrobble/start HTTP/1.1" 401 None
19:39:01 T:11220 DEBUG: [script.trakt] trakt.interfaces.base: response returned content-type: 'text/html', falling back to raw data
19:39:01 T:11220 WARNING: [script.trakt] trakt.interfaces.base: request failed: Unauthorized - "OAuth must be provided" (code: 401)
Token auth will soon be deprecated
See:
https://plus.google.com/u/0/109991097847241028373/posts/dCvyQnUJ5Ea?cfem=1
There seems to be a problem for some clients with the SSL certificate.
See this log: http://xbmclogs.com/pjkndtvww#line-1599
This seems to be a solution, but only you will know for sure
https://lukasa.co.uk/2013/01/Choosing_SSL_Version_In_Requests/
http://stackoverflow.com/a/14146031/2859813
Hi,
I want to know if a given episode has already been watched. Even with extended='full', the Episode.is_watched is always None or 0 (but I can confirm that the episode is marked as watched in the trakt web interface).
I tried with both Trakt['search'].lookup(trakt_id, service='trakt', extended='full')
and Trakt['shows'].episode(slug, seasonnumber, episodenumber, extended='full')
Am I doing something wrong there ?
thanks
Had a user report this:
trakt/script.trakt#333 (comment)
Seems that's a certificate issue.
I fix it changing your 3.1.8 version file "~/.kodi/addons/script.module.trakt/lib/trakt/core/http.py"
The actual line:
self.session.mount('https://', HTTPSAdapter(ssl_version=ssl.PROTOCOL_TLSv1, **self.adapter_kwargs))
by this one:
self.session.mount('https://', HTTPSAdapter(ssl_version=ssl.PROTOCOL_TLSv1_2, **self.adapter_kwargs))
And works. Certificate on the autorization page acepts TLS v 1.2 and fails (at least for me) with TLS v 1.0
Feel free to double check it and add it to yor version if you like.
Regards
I was wondering if [email protected] in setup.py
is still a way to contact you. Going to dgardiner.net leads to a page that makes it appear to have been expired/taken.
Would be nice if we were able to use https://trakt.docs.apiary.io/#reference/movies/ratings/get-movie-ratings and the episode / show counterparts
I'm getting errors in the logfile which should not be errors
17:44:20 T:5692 ERROR: [script.trakt] "POST /scrobble/stop HTTP/1.1" 201 None
Might be happening for all Success states other than 200?
Hi,
First, love your work.
The implementation is really easy to use, and the code in itself is very neat ! :)
Would it be possible to implement, in the show interface, the functionnality to get the watched progress ?
The function in itself wouldn't be difficult to code, I think, the part I'm not confortable with is the description of the object.
Now there isn't any object usable for this that I've found.
The response object of the API look like the seasons object in your code, but not quite it...
I'm trying to auth and haven't set exceptions to true.
When I'm offline and try to auth I still get an error:
00:43:26 T:3964 ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <class 'requests.exceptions.ConnectionError'>
Error Contents: ('Connection aborted.', gaierror(11001, 'getaddrinfo failed'))
Traceback (most recent call last):
File "C:\Users\razze\AppData\Roaming\Kodi\addons\script.trakt\default.py", line 15, in <module>
traktService().run()
File "C:\Users\razze\AppData\Roaming\Kodi\addons\script.trakt\service.py", line 104, in run
globals.traktapi = traktAPI()
File "C:\Users\razze\AppData\Roaming\Kodi\addons\script.trakt\traktapi.py", line 35, in __init__
self.getToken()
File "C:\Users\razze\AppData\Roaming\Kodi\addons\script.trakt\traktapi.py", line 60, in getToken
auth = Trakt['auth'].login(getSetting('username'), getSetting('password'))
File "C:\Users\razze\AppData\Roaming\Kodi\addons\script.trakt\trakt\interfaces\auth.py", line 10, in login
'password': password
File "C:\Users\razze\AppData\Roaming\Kodi\addons\script.trakt\trakt\core\http.py", line 89, in post
return self.request('POST', path, params, data, **kwargs)
File "C:\Users\razze\AppData\Roaming\Kodi\addons\script.trakt\trakt\core\http.py", line 66, in request
response = self.session.send(prepared, timeout=timeout)
File "C:\Users\razze\AppData\Roaming\Kodi\addons\script.module.requests\lib\requests\sessions.py", line 569, in send
r = adapter.send(request, **kwargs)
File "C:\Users\razze\AppData\Roaming\Kodi\addons\script.module.requests\lib\requests\adapters.py", line 407, in send
raise ConnectionError(err, request=request)
ConnectionError: ('Connection aborted.', gaierror(11001, 'getaddrinfo failed'))
-->End of Python script error report<--
could you add a possibility for transparent trakt calls for functions that are not supported?
e.g. collection=Trakt['shows/'+showID+'/progress/collection']
maybe it is already possible but your interface-machine is too complicated for me to understand properly! :-/
from trakt import Trakt
Traceback (most recent call last):
File "", line 1, in
File "build/bdist.linux-x86_64/egg/trakt/init.py", line 1, in
File "build/bdist.linux-x86_64/egg/trakt/client.py", line 1, in
ImportError: No module named core.configuration
Hey everybody,
is there a way we can get the error from the library? As far as I've seen it only adds it to the logfile, no luck with try etc.
Cheers
It would be fine, if there will be implemented more methods from /users/ API. I am not sure, if every endpoint should have its own issue, or it is possible to merge them into one issue. I would like to replace my custom trakt library with trakt.py and I am still missing some functions:
users/*/watchlist - now there is only sync/watchlist that is for authenticated users only. It will be fine if anyone (friends&following) will be able to see watch on my/their watchlist
more useful methods: users//collection, users//watched, users//history, users//ratings
Can't seem to figured out what's going on, has put me through hell and back trying to work out what the issues are, had to delete me entire data base and start fresh thinking it would fix it but still having issues.
Can't get the addon to work at the end of any show or movie, won't let me rate an item, will only pop up and allow Kodi to mark as watched when going to the very end of the file.
Talked with Razee and he believes the issue is with this side of things. Is there something going on with the plugin right now ??
I could be wrong, but it seems like there is a case when retries are not working correctly. Might be when exceptions are thrown.
I'm struggling to decipher how to use this library from the API docs.
I had to dig into the examples module just to find out how to authenticate, and copy/paste the examples.helpers.authenticate
function somewhere locally to do it. Not sure why this helper isn't included in the main package, and mentioned in the README which only configures the client?
But that's a side issue. Now that I'm authenticated, I'm looking for a way to "add" a "play" to my trakt history, specifically with watched_at='released'
. I don't see any examples for Trakt['sync/history'].add()
in the examples package.
After getting an episode that I want to add (as e
), I tried the following:
In [25]: Trakt['sync/history'].add({'shows': [{'ids': {'trakt': e.id}}]})
Out[25]:
{'added': {'movies': 0, 'episodes': 0},
'not_found': {'movies': [],
'shows': [{'ids': {'trakt': 5885625430}}],
'seasons': [],
'episodes': [],
'people': []}}
It says zero episodes added. So I tried:
In [31]: Trakt['sync/history'].add({'shows': [e.to_dict()]})
Out[31]:
{'added': {'movies': 0, 'episodes': 24},
'not_found': {'movies': [],
'shows': [],
'seasons': [],
'episodes': [],
'people': []}}
This says 24 epsodes added, but no corresponding play for the single episode I tried to add is showing up at trakt.tv.
Ideally, what I want to do is loop over my existing history and replace all duplicate and non-release plays with a single play at release.
Thanks.
from trakt import Trakt
/usr/local/lib/python2.7/dist-packages/arrow/arrow.py:28: DeprecationWarning: Arrow will drop support for Python 2.7 and 3.5 in the upcoming v1.0.0 release. Please upgrade to Python 3.6+ to continue receiving updates for Arrow.
DeprecationWarning,
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/trakt/init.py", line 3, in
from trakt.client import TraktClient
File "/usr/local/lib/python2.7/dist-packages/trakt/client.py", line 5, in
from trakt.core.http import HttpClient
File "/usr/local/lib/python2.7/dist-packages/trakt/core/http.py", line 13, in
from requests.packages.urllib3.exceptions import ReadTimeoutError
ImportError: cannot import name ReadTimeoutError
What am I missing here???
thanks!!
Been testing out trakt.py and came across this scenario.
Trakt.configuration.defaults.app(id="xxxx")
Trakt.configuration.defaults.client(
id="xxxx",
secret="xxxx",
)
for show in Trakt["movies"].trending(extended="full"):
pprint(vars(show))
Seems like images
is always populated with None
on this endpoint. Is this expected?
Hello, thanks for merging and improving my previous commits.
I almost forgot about these useful methods that I used in my kodi plugin - to allow user to browse through trending and popular lists.
The usage sholud be like
Trakt['lists'].popular()
Trakt['lists'].trending()
I tried to implement it, but I cannot figure out, how to attach user to List object, because I lost in some circular import of UserMapper in List class.
Another issue with List is that interface Users
Trakt['users'].likes('lists') is returning CustomLists, but lists in users/*/like are "public" lists. The returned CustomList contains only "username" field but to retrieve the lists it is necessary to use users's slug id and also List id/slug. And I think it is not a good idea to have .add delete methods on lists that do not belong to the current authenticated user. And actions like likelist or unlike should be available on List rather than CusomList.
Thanks
Is it already possible to use a proxy?
Like documented for requests here?
http://docs.python-requests.org/en/latest/user/advanced/#proxies
So there is an watchlist method, but nothing to add to it?
Also what about getting all custom lists and getting the items of them?
The failure is because of coverage.py==4.0 and associated coveralls==1.0 dropping support for python3.2.
Any chance, to get this fixed? Or do I need to do something to the requests package?
22:47:12 T:11192 ERROR: C:\Users\razze\AppData\Roaming\Kodi\addons\script.module.requests\lib\requests\packages\urllib3\util\ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
File "/home/vagrant/tvrenamer/.tox/cover34/lib/python3.4/site-packages/trakt/interfaces/shows/__init__.py", line 56, in episode
self.get_data(response, **kwargs)
File "/home/vagrant/tvrenamer/.tox/cover34/lib/python3.4/site-packages/trakt/mapper/summary.py", line 120, in episode
pk, keys = cls.get_ids('episode', i_episode)
File "/home/vagrant/tvrenamer/.tox/cover34/lib/python3.4/site-packages/trakt/mapper/core/base.py", line 63, in get_ids
item.get('season') or parent.pk,
AttributeError: 'NoneType' object has no attribute 'pk'
The existing code:
if media == 'episode':
keys.insert(0, (
item.get('season') or parent.pk,
item.get('number')
))
The value returned from item.get('season')
is 0, but parent is None
.
Hey there,
haven't really had the time to look into it, but thought I would quickly open up an issue to let you know.
There seems to be some problem trakt/script.trakt#503 (comment)
Not sure if that just a problem with constructing the movie ratings api endpoint or if more is affected.
https://forum.kodi.tv/showthread.php?tid=220547&pid=2955335#pid2955335
Can requirements be updated? I'm wondering if a recent arrow version would be good for e.g.
I see in the trakt API that you can do a lookup for all episodes of a show using the "seasons" method if you include "?extended=episodes" in the URL.
http://docs.trakt.apiary.io/#reference/seasons/summary/get-all-seasons-for-a-show
I've looked in the code here but I wasn't able to find a way to make this happen. Is there an option to one of the methods that would allow this to happen? If not, can it be added?
I'm still using multiple custom calls outside of trakt.py to make my script work. Would be nice to get them over to the new one.
It starts here https://github.com/Razzeee/script.trakt/blob/dev/traktapi.py#L361
$ pip --no-cache-dir install 'trakt.py>=2.5.0'
Collecting trakt.py>=2.5.0
Downloading trakt.py-2.5.0.zip (51kB)
100% |████████████████████████████████| 53kB 1.2MB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "/tmp/pip-build-0BRffG/trakt.py/setup.py", line 1, in <module>
from trakt import __version__
File "trakt/__init__.py", line 3, in <module>
from trakt.client import TraktClient, __version__
File "trakt/client.py", line 1, in <module>
from trakt.core.configuration import ConfigurationManager
File "trakt/core/configuration.py", line 1, in <module>
from trakt.core.context_collection import ContextCollection
File "trakt/core/context_collection.py", line 4, in <module>
from six.moves import _thread as thread
ImportError: No module named six.moves
When using a virtualenv or an environment that does not already include the required libraries will fail because setup.py has to import trakt which will fail to find the dependency.
This is just a theoretical problem that bothers me.
As far as I know you are only using tvdb and imdb for the identifier tuples (for e.g. ratings)
https://github.com/Razzeee/script.trakt/blob/dev/utilities.py#L284
But we might need the trakt id as it's the only one that is always, reliably there. Other ids might be not set.
Would it be possible to get an implementation of https://api-v2launch.trakt.tv/users/settings
or more suited for me https://api-v2launch.trakt.tv/me/settings
I find it very confusing at the moment, that you enter your pin in the settings but might forget from which user this is. So I would like to display that, basically just the name. Because as far as I know the auth process doesn't return the username.
Should this be done in our apps? Might be nice to have this centrally, might also be overkill.
Would have to save timestamps to our sync/collection sync/watched calls and compare them with the result of last activity for that task http://docs.trakt.apiary.io/#reference/sync/last-activities/get-last-activity which we would call before doing anything else.
FYI, just got the following email from Trakt
As of October 27, 2020, we’re enforcing rate limiting for all API apps. You’ve created a Trakt API app, and we wanted to let you know directly. If you have any questions, please continue the discussion in the GitHub API project.
WHY ARE RATE LIMITS BEING ENFORCED?
Over the past several months, Trakt performance has been negatively impacted by a huge increase in API traffic and poorly coded apps. In order to stabilize the API and increase performance for everyone, we’re turning on rate limiting. The Trakt API is free to use, and rate limiting will help us keep it that way.WHAT UPDATES DOES MY APP NEED?
Your app will need to handle the 429 HTTP status code and headers that are sent when the rate limit is exceeded. This might be built into your API library, or you might need to customize your code to handle it. The API docs have more details.WHAT ARE THE LIMITS?
/sync/history/* 2 calls every second
All API methods 1,000 calls every 5 minutesAll limits are per user.
MOVING FORWARD
We plan on adjusting limits until we find a balance of good performance with minimal app impact. The goal is to prevent API abuse, but allow users to use apps normally. We’ll keep the API docs updated with the current rate limits.
If you have any questions, please continue the discussion in the GitHub API project.
It would be awesome if this client helped throttle API calls when a 429
response is received
Add support for
Probably similar to .trending()
support added in 4.2.0.
Trakt.tv API spec allows for an optional type
parameter for list items:
https://trakt.docs.apiary.io/#reference/users/list-items/get-items-on-a-custom-list
This allows for something like,
Trakt['users/me/lists/mylist'].items(item_type='movie')
-or-
Trakt['users/me/lists/mylist'].items(item_type='show')
to return only the requested type of item.
it appears to me that watchlist unlike watched & collection has paging
watchlist = Trakt['sync/watchlist'].movies()
is there a way to get all watchlist items without paging?
Hello,
Is it possible to continue from a previously authorized session?
I'm currently doing an oauth authentication, but I can't really figure out how I would save and reuse the token the next time I run my script so I don't have to go through the whole auth process again.
Is this even possible with this library?
It looks like Trakt['movies'].trending()
will only return the first page of 10 results or all results with the pagination=True
argument. Could you add the ability to return a specific number of results? Or at least implement page
and limit
arguments as described in https://trakt.docs.apiary.io/#introduction/pagination
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.