Last active
January 12, 2020 19:31
-
-
Save henryjfry/db44bb9a47170eb556599a0ea32ca85b to your computer and use it in GitHub Desktop.
TMDB Helper - Trakt return more than 5 results ~/.kodi/addons/plugin.video.themoviedb.helper/resources/lib/traktapi.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_recentlywatched(self, userslug, tmdbtype, limit=None, islistitem=True, months=360): | |
| start_at = datetime.date.today() - datetime.timedelta(months * 365 / 12) | |
| history = self.get_response_json('users', userslug, 'history', utils.type_convert(tmdbtype, 'trakt') + 's', page=1, limit=10000, start_at=start_at.strftime("%Y-%m-%d")) | |
| return self.get_limitedlist(history, tmdbtype, limit, islistitem) | |
| def get_inprogress(self, userslug, limit=None, episodes=False): | |
| """ | |
| Looks at user's most recently watched 200 episodes in last 3 years | |
| Adds each unique show to list in order then checks if show has an upnext episode | |
| Returns list of tmdb_ids representing shows with upnext episodes in recently watched order | |
| """ | |
| items = [] | |
| if not self.tmdb or not self.authorize(): | |
| return items | |
| n = 0 | |
| utils.kodi_log('Getting In-Progress For Trakt User {0}'.format(userslug), 2) | |
| for i in self.get_recentlywatched(userslug, 'tv', islistitem=False, months=360): | |
| if limit and n >= limit: | |
| break | |
| utils.kodi_log('In-Progress -- Searching Next Episode For:\n{0}'.format(i), 2) | |
| progress = self.get_upnext(i[0], True) | |
| if progress and progress.get('next_episode'): | |
| utils.kodi_log('In-Progress -- Found Next Episode:\n{0}'.format(progress.get('next_episode')), 2) | |
| season = progress.get('next_episode', {}).get('season') if episodes else None | |
| episode = progress.get('next_episode', {}).get('number') if episodes else None | |
| item = self.tmdb.get_detailed_item('tv', i[1], season=season, episode=episode) | |
| item['tmdb_id'] = i[1] | |
| utils.kodi_log('In-Progress -- Got Next Episode Details:\n{0}'.format(item), 2) | |
| items.append(ListItem(library=self.library, **item)) | |
| n += 1 | |
| return items |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment