moogar0880 / PyTrakt

A Pythonic interface to the Trakt.tv REST API
Other
66 stars 51 forks source link

TvShow.seasons returns same season for each object #98

Closed iantrich closed 5 years ago

iantrich commented 5 years ago

image

The bug is not obvious to me, but calling the same query, manually, gives both individual seasons:

image

Should this line be explicit about the season number? My Python is limited and I would actually think this should be fine, as "number" looks to be returned first and would therefore be the 2nd parameter passed to init of the TvSeason as expected...I'm not sure

iantrich commented 5 years ago

I'll try to play around with the code to see if I can better pin-point where the issue is

iantrich commented 5 years ago

image

Number is getting passed in, the season value is not being set it looks like.

So should that line just be

self._seasons.append(TVSeason(self.title, season.number, **season))
StoneMonarch commented 5 years ago

@iantrich

your fix doesnt work. i get this error when i add your fix self._seasons.append(TVSeason(self.title, season.number, **season)) AttributeError: 'dict' object has no attribute 'number'

iantrich commented 5 years ago

@StoneMonarch yeah, that's why I didn't finish the PR. Haven't had a chance to look into it further

StoneMonarch commented 5 years ago

Fixed, see PR #100

StoneMonarch commented 5 years ago

@iantrich please mark as closed

moogar0880 commented 5 years ago

Closing this issue since, as @StoneMonarch said, this was closed in #100.

If you run into any other issues feel free to open a new issue.

iantrich commented 5 years ago

Works here. I planned to use this for an "Up Next" sensor in Home Assistant, which I do have working but unfortunately it is just too slow to get all the episodes for the most recently watched and find the next. Ends up taking ~5 minutes :( There's not an "up next" api call that I'm missing, is there?

moogar0880 commented 5 years ago

Yeah, the trakt api isn't super quick.

Have you tried lowering the number of days when you get the calendar? By default it gets the next weeks worth of episodes, you could try setting days=2. The response may come back faster.

iantrich commented 5 years ago

I have a calendar sensor working perfectly, but the way I'm doing "Up Next" is by getting watched_shows for the users, which has the most recently watched shows. I then iterate through those and do a TvShow.search on each show to get all episodes, and use that to get the next show after the most recently watched. The search is where the bottleneck is.

dhjw commented 7 months ago

The apparent correct way to obtain Up Next according to a note here is to "Use a combination of the /sync/watched and /shows/:id/progress methods to get what the user is actively watching." The progress endpoints are accessible with this fork (pip uninstall trakt; git clone https://github.com/glensc/python-pytrakt; cd python-pytrakt; pip install . then import trakt as usual) and is called similar to the example in these docs with the additional function, like User(user).watched_shows[0].watched_progress()