def get_custom_list(self, list_slug, user_slug=None, page=1, limit=20, params=None, authorize=False, sort_by=None, sort_how=None, extended=None): if authorize and not self.authorize(): return path = 'users/{}/lists/{}/items'.format(user_slug or 'me', list_slug) # Refresh cache on first page for user list because it might've changed cache_refresh = True if try_int(page, fallback=1) == 1 else False sorted_items = self.get_sorted_list( path, sort_by, sort_how, extended, permitted_types=['movie', 'show', 'person'], cache_refresh=cache_refresh) or {} paginated_items = PaginatedItems(items=sorted_items.get('items', []), page=page, limit=limit) return { 'items': paginated_items.items, 'movies': sorted_items.get('movies', []), 'shows': sorted_items.get('shows', []), 'persons': sorted_items.get('persons', []), 'next_page': paginated_items.next_page }
def get_upnext_episodes_list(self, page=1, sort_by_premiered=False): """ Gets a list of episodes for in-progress shows that user should watch next """ response = self._get_upnext_episodes_list(sort_by_premiered=sort_by_premiered) response = TraktItems(response, trakt_type='episode').configure_items(params_def={ 'info': 'details', 'tmdb_type': '{tmdb_type}', 'tmdb_id': '{tmdb_id}', 'season': '{season}', 'episode': '{number}'}) response = PaginatedItems(response['items'], page=page, limit=10) return response.items + response.next_page
def get_inprogress_shows_list(self, page=1, limit=20, params=None, next_page=True, sort_by=None, sort_how=None): response = self._get_upnext_episodes_list(sort_by_premiered=True) if sort_by == 'year' else self._get_inprogress_shows() response = TraktItems(response, trakt_type='show').build_items( params_def=params, sort_by=sort_by if sort_by != 'year' else 'unsorted', sort_how=sort_how) response = PaginatedItems(response['items'], page=page, limit=limit) if not next_page: return response.items return response.items + response.next_page
def get_inprogress_shows_list(self, page=1, limit=20, params=None, next_page=True): response = TraktItems(self._get_inprogress_shows(), trakt_type='show').build_items(params_def=params) response = PaginatedItems(response['items'], page=page, limit=limit) if not next_page: return response.items return response.items + response.next_page
def get_upnext_list(self, unique_id, id_type=None, page=1): """ Gets the next episodes for a show that user should watch next """ if id_type != 'slug': unique_id = self.get_id(unique_id, id_type, 'show', output_type='slug') if unique_id: showitem = self.get_details('show', unique_id) response = self.get_upnext_episodes(unique_id, showitem) response = TraktItems(response, trakt_type='episode').configure_items(params_def={ 'info': 'details', 'tmdb_type': '{tmdb_type}', 'tmdb_id': '{tmdb_id}', 'season': '{season}', 'episode': '{number}'}) response = PaginatedItems(response['items'], page=page, limit=10) return response.items + response.next_page
def get_calendar_episodes_list(self, startdate=0, days=1, user=True, kodi_db=None, page=1, limit=20): response_items = self._get_calendar_episodes_list( startdate, days, user, kodi_db) response = PaginatedItems(response_items, page=page, limit=limit) if response and response.items: return response.items + response.next_page
def get_calendar_episodes_list(self, startdate=0, days=1, user=True, kodi_db=None, page=1, limit=20): # cache_name = 'trakt.calendar.episodes.{}.{}.{}.{}'.format(startdate, days, user, kodi_db is not None) # response_items = cache.use_cache( # self._get_calendar_episodes_list, startdate, days, user, kodi_db, # cache_name=cache_name, # cache_days=1) response_items = self._get_calendar_episodes_list( startdate, days, user, kodi_db) response = PaginatedItems(response_items, page=page, limit=limit) if response and response.items: return response.items + response.next_page
def get_basic_list(self, path, trakt_type, page=1, limit=20, params=None, sort_by=None, sort_how=None, extended=None, authorize=False, randomise=False): # TODO: Add argument to check whether to refresh on first page (e.g. for user lists) # Also: Think about whether need to do it for standard respons cache_refresh = True if try_int(page, fallback=1) == 1 else False if randomise: response = self.get_simple_list( path, extended=extended, page=1, limit=50, trakt_type=trakt_type) elif sort_by is not None: # Sorted list manually paginated because need to sort first response = self.get_sorted_list(path, sort_by, sort_how, extended, cache_refresh=cache_refresh) response = PaginatedItems(items=response['items'], page=page, limit=limit).get_dict() else: # Unsorted lists can be paginated by the API response = self.get_simple_list( path, extended=extended, page=page, limit=limit, trakt_type=trakt_type) if response: if randomise and len(response['items']) > limit: items = random.sample(response['items'], limit) return items return response['items'] + pages.get_next_page(response['headers'])
def get_sync_list(self, sync_type, trakt_type, page=1, limit=20, params=None, sort_by=None, sort_how=None, next_page=True): response = self._get_sync_list(sync_type, trakt_type, sort_by=sort_by, sort_how=sort_how) if not response: return response = PaginatedItems(items=response['items'], page=page, limit=limit) return response.items if not next_page else response.items + response.next_page