From 0b27c2fbb067ce6c14a83b5a99626f86962eb7ec Mon Sep 17 00:00:00 2001 From: Bas Rieter Date: Wed, 25 Oct 2023 22:22:05 +0200 Subject: [PATCH] Fixed: Paging for mainlist. --- channels/channel.se/tv4se/chn_tv4se.py | 36 ++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/channels/channel.se/tv4se/chn_tv4se.py b/channels/channel.se/tv4se/chn_tv4se.py index bfbf85c8..526da3b9 100644 --- a/channels/channel.se/tv4se/chn_tv4se.py +++ b/channels/channel.se/tv4se/chn_tv4se.py @@ -39,7 +39,7 @@ def __init__(self, channel_info): chn_class.Channel.__init__(self, channel_info) # ============== Actual channel setup STARTS here and should be overwritten from derived classes =============== - self.__max_page_size = 2500 + self.__max_page_size = 500 self.__access_token = None if self.channelCode == "tv4segroup": @@ -51,7 +51,7 @@ def __init__(self, channel_info): self.mainListUri = self.__get_api_url( "MediaIndex", - "dba092c9af0e54e4e3e68dd84b16bb913a9e0e5fe83ff01cf59b6b453d0c75d4", + "423ba183684c9ea464c94e200696c8f6ec190fe9837f542a672623fa87ef0f4e", {"input": {"letterFilters": list("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), "limit": self.__max_page_size + randrange(25) * 0, "offset": 0} @@ -88,6 +88,7 @@ def __init__(self, channel_info): self._add_data_parser("https://client-gateway.tv4.a2d.tv/graphql?operationName=MediaIndex&", name="Main show/movie list", json=True, + preprocessor=self.fetch_mainlist_pages, parser=["data", "mediaIndex", "contentList", "items"], creator=self.create_api_typed_item) @@ -233,6 +234,33 @@ def log_on(self): self.parentItem.HttpHeaders.update(self.httpHeaders) return bool(self.__access_token) + def fetch_mainlist_pages(self, data): + items = [] + data = JsonHelper(data) + page_data = data + + while True: + next_offset = page_data.get_value("data", "mediaIndex", "contentList", "pageInfo", "nextPageOffset") + if not next_offset or next_offset <= 0: + break + + url = self.__get_api_url( + "MediaIndex", + "423ba183684c9ea464c94e200696c8f6ec190fe9837f542a672623fa87ef0f4e", + {"input": {"letterFilters": list("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), + "limit": self.__max_page_size + randrange(25) * 0, + "offset": next_offset} + } + ) + page_data = UriHandler.open(url, additional_headers=self.httpHeaders) + page_data = JsonHelper(page_data) + data_items = page_data.get_value(*self.currentParser.Parser) + list_items = data.get_value(*self.currentParser.Parser) + list_items += data_items + + Logger.debug("Pre-Processing finished") + return data, items + # def create_api_tag(self, result_set): # """ Creates a new MediaItem for tag listing items # @@ -256,6 +284,8 @@ def log_on(self): # item = MediaItem(result_set, url) # return item + + def create_api_typed_item(self, result_set): """ Creates a new MediaItem based on the __typename attribute. @@ -306,6 +336,7 @@ def create_api_movie(self, result_set: dict) -> Optional[MediaItem]: return None item = MediaItem(title, url, media_type=mediatype.MOVIE) + item.isGeoLocked = True item = self.__update_base_typed_item(item, result_set) return item @@ -318,6 +349,7 @@ def create_api_episode(self, result_set: dict) -> Optional[MediaItem]: item = MediaItem(title, url, media_type=mediatype.MOVIE) item = self.__update_base_typed_item(item, result_set) + item.isGeoLocked = True item.isPaid = not JsonHelper.get_from( result_set, "video", "access", "hasAccess", fallback=True) item.isLive = result_set.get("isLiveContent", False)