diff --git a/resources/lib/youtube_plugin/kodion/context/abstract_context.py b/resources/lib/youtube_plugin/kodion/context/abstract_context.py index 755501e8e..0756eb097 100644 --- a/resources/lib/youtube_plugin/kodion/context/abstract_context.py +++ b/resources/lib/youtube_plugin/kodion/context/abstract_context.py @@ -65,6 +65,7 @@ class AbstractContext(object): } _INT_PARAMS = { 'fanart_type', + 'items_per_page', 'live', 'next_page_token', 'offset', diff --git a/resources/lib/youtube_plugin/youtube/client/youtube.py b/resources/lib/youtube_plugin/youtube/client/youtube.py index a004e15b4..98a4a9154 100644 --- a/resources/lib/youtube_plugin/youtube/client/youtube.py +++ b/resources/lib/youtube_plugin/youtube/client/youtube.py @@ -127,8 +127,8 @@ def __init__(self, context, **kwargs): super(YouTube, self).__init__(context=context, **kwargs) - def get_max_results(self): - return self._max_results + def max_results(self): + return self._context.get_param('items_per_page') or self._max_results def get_language(self): return self._language @@ -348,7 +348,7 @@ def get_subscription(self, :return: """ params = {'part': 'snippet', - 'maxResults': str(self._max_results), + 'maxResults': str(self.max_results()), 'order': order} if channel_id == 'mine': params['mine'] = 'true' @@ -364,7 +364,7 @@ def get_subscription(self, def get_guide_category(self, guide_category_id, page_token='', **kwargs): params = {'part': 'snippet,contentDetails,brandingSettings', - 'maxResults': str(self._max_results), + 'maxResults': str(self.max_results()), 'categoryId': guide_category_id, 'regionCode': self._region, 'hl': self._language} @@ -377,7 +377,7 @@ def get_guide_category(self, guide_category_id, page_token='', **kwargs): def get_guide_categories(self, page_token='', **kwargs): params = {'part': 'snippet', - 'maxResults': str(self._max_results), + 'maxResults': str(self.max_results()), 'regionCode': self._region, 'hl': self._language} if page_token: @@ -390,7 +390,7 @@ def get_guide_categories(self, page_token='', **kwargs): def get_trending_videos(self, page_token='', **kwargs): params = {'part': 'snippet,status', - 'maxResults': str(self._max_results), + 'maxResults': str(self.max_results()), 'regionCode': self._region, 'hl': self._language, 'chart': 'mostPopular'} @@ -403,7 +403,7 @@ def get_trending_videos(self, page_token='', **kwargs): def get_video_category(self, video_category_id, page_token='', **kwargs): params = {'part': 'snippet,contentDetails,status', - 'maxResults': str(self._max_results), + 'maxResults': str(self.max_results()), 'videoCategoryId': video_category_id, 'chart': 'mostPopular', 'regionCode': self._region, @@ -417,7 +417,7 @@ def get_video_category(self, video_category_id, page_token='', **kwargs): def get_video_categories(self, page_token='', **kwargs): params = {'part': 'snippet', - 'maxResults': str(self._max_results), + 'maxResults': str(self.max_results()), 'regionCode': self._region, 'hl': self._language} if page_token: @@ -604,7 +604,7 @@ def get_related_for_home(self, page_token='', refresh=False): # Increase value to recursively retrieve recommendations for the first # recommended video, up to the set maximum recursion depth max_depth = 2 - items_per_page = self._max_results + items_per_page = self.max_results() diversity_limits = items_per_page // (num_items * max_depth) items = [[] for _ in range(max_depth * len(video_ids))] counts = { @@ -811,7 +811,7 @@ def rank_and_sort(item): def get_activities(self, channel_id, page_token='', **kwargs): params = {'part': 'snippet,contentDetails', - 'maxResults': str(self._max_results), + 'maxResults': str(self.max_results()), 'regionCode': self._region, 'hl': self._language} @@ -844,7 +844,7 @@ def get_channel_sections(self, channel_id, **kwargs): def get_playlists_of_channel(self, channel_id, page_token='', **kwargs): params = {'part': 'snippet', - 'maxResults': str(self._max_results)} + 'maxResults': str(self.max_results())} if channel_id != 'mine': params['channelId'] = channel_id else: @@ -864,7 +864,7 @@ def get_playlist_item_id_of_video_id(self, json_data = self.get_playlist_items( playlist_id=playlist_id, page_token=page_token, - max_results=50, + max_results=self.max_results(), ) if not json_data: return None @@ -890,7 +890,7 @@ def get_playlist_items(self, **kwargs): # prepare params if max_results is None: - max_results = self._max_results + max_results = self.max_results() params = {'part': 'snippet', 'maxResults': str(max_results), 'playlistId': playlist_id} @@ -954,7 +954,7 @@ def get_disliked_videos(self, page_token='', **kwargs): # prepare params params = {'part': 'snippet,status', 'myRating': 'dislike', - 'maxResults': str(self._max_results)} + 'maxResults': str(self.max_results())} if page_token: params['pageToken'] = page_token @@ -1022,7 +1022,7 @@ def get_live_events(self, 'regionCode': self._region, 'hl': self._language, 'relevanceLanguage': self._language, - 'maxResults': str(self._max_results)} + 'maxResults': str(self.max_results())} if location: settings = self._context.get_settings() @@ -1049,7 +1049,7 @@ def get_related_videos(self, offset=0, retry=0, **kwargs): - max_results = self._max_results if max_results <= 0 else max_results + max_results = self.max_results() if max_results <= 0 else max_results post_data = {'videoId': video_id} if page_token: @@ -1248,7 +1248,7 @@ def get_parent_comments(self, page_token='', max_results=0, **kwargs): - max_results = self._max_results if max_results <= 0 else max_results + max_results = self.max_results() if max_results <= 0 else max_results # prepare params params = {'part': 'snippet', @@ -1270,7 +1270,7 @@ def get_child_comments(self, page_token='', max_results=0, **kwargs): - max_results = self._max_results if max_results <= 0 else max_results + max_results = self.max_results() if max_results <= 0 else max_results # prepare params params = {'part': 'snippet', @@ -1293,7 +1293,7 @@ def get_channel_videos(self, channel_id, page_token='', **kwargs): params = {'part': 'snippet', 'hl': self._language, - 'maxResults': str(self._max_results), + 'maxResults': str(self.max_results()), 'type': 'video', 'safeSearch': 'none', 'order': 'date'} @@ -1355,7 +1355,7 @@ def search(self, 'regionCode': self._region, 'hl': self._language, 'relevanceLanguage': self._language, - 'maxResults': str(self._max_results)} + 'maxResults': str(self.max_results())} if event_type and event_type in {'live', 'upcoming', 'completed'}: params['eventType'] = event_type @@ -1405,7 +1405,7 @@ def get_my_subscriptions(self, 'items': [], 'pageInfo': { 'totalResults': 0, - 'resultsPerPage': self._max_results, + 'resultsPerPage': self.max_results(), }, } @@ -1430,8 +1430,8 @@ def get_my_subscriptions(self, page = page_token or 1 totals = { 'num': 0, - 'start': -self._max_results, - 'end': page * self._max_results, + 'start': -self.max_results(), + 'end': page * self.max_results(), 'video_ids': set(), } totals['start'] += totals['end'] @@ -1837,7 +1837,7 @@ def _perform(_playlist_idx, _page_token, _offset, _result): if not _result: _result = {'items': []} - _new_offset = self._max_results - len(_result['items']) + _offset + _new_offset = self.max_results() - len(_result['items']) + _offset if _offset > 0: _items = _items[_offset:] _result['offset'] = _new_offset @@ -1867,23 +1867,23 @@ def _perform(_playlist_idx, _page_token, _offset, _result): _continuations = (_data.get('continuations', [{}])[0] .get('nextContinuationData', {}) .get('continuation', '')) - if _continuations and len(_result['items']) <= self._max_results: + if _continuations and len(_result['items']) <= self.max_results(): _result['next_page_token'] = _continuations - if len(_result['items']) < self._max_results: + if len(_result['items']) < self.max_results(): _result = _perform(_playlist_idx=playlist_index, _page_token=_continuations, _offset=0, _result=_result) # trim result - if len(_result['items']) > self._max_results: + if len(_result['items']) > self.max_results(): _items = _result['items'] - _items = _items[:self._max_results] + _items = _items[:self.max_results()] _result['items'] = _items _result['continue'] = True - if len(_result['items']) < self._max_results: + if len(_result['items']) < self.max_results(): if 'continue' in _result: del _result['continue']