Skip to content

Commit

Permalink
Added: Categories for TV4 Play.
Browse files Browse the repository at this point in the history
  • Loading branch information
basrieter committed Oct 28, 2023
1 parent ea35dbc commit 9d6b9dc
Showing 1 changed file with 45 additions and 17 deletions.
62 changes: 45 additions & 17 deletions channels/channel.se/tv4se/chn_tv4se.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,21 @@ def __init__(self, channel_info):
}
)

# Use the categories from TV4: TODO: How to get from slug to A-Z id?
# self.mainListUri = self.__get_api_url(
# "PageList",
# "58da321b8e31df2b746f1d1f374151a450a4c24bda6415182fe81551c90e7d25",
# {"pageListId": "categories"})
#
# self._add_data_parser("https://client-gateway.tv4.a2d.tv/graphql?operationName=PageList&",
# name="Main TV4 page", json=True, requires_logon=True,
# parser=["data", "pageList", "content"],
# creator=self.create_api_typed_item)
self._add_data_parser("https://client-gateway.tv4.a2d.tv/graphql?operationName=PageList&",
name="Main TV4 pages", json=True, requires_logon=True,
parser=["data", "pageList", "content"],
creator=self.create_api_typed_item)

# Use the TV4 main page panels.
# self.mainListUri = self.__get_api_url(
# "Page",
# "0745022edc5d8e886617f6e27c89792fa74d073ee29e4dab7ae3067218148b0a",
# {"pageId": "start", "input": {"limit": 10, "offset": 0}})
#
# self._add_data_parser("https://client-gateway.tv4.a2d.tv/graphql?operationName=Page&",
# name="Main TV4 page", json=True, requires_logon=True,
# preprocessor=self.list_main_content,
# parser=["data", "page", "content", "panels"],
# creator=self.create_api_typed_item)

self._add_data_parser("https://client-gateway.tv4.a2d.tv/graphql?operationName=Page&",
name="Main TV4 page", json=True, requires_logon=True,
parser=["data", "page", "content", "panels"],
creator=self.create_api_typed_item)

self.mainListUri = "#mainlist"
self._add_data_parser("#mainlist",
Expand Down Expand Up @@ -268,6 +261,15 @@ def __create_item(lang_id: int, url: str):
{"panelId": "5Rqb0w0SN16A6YHt5Mx8BU", "limit": self.__max_page_size, "offset": 0}
)
items.append(__create_item(LanguageHelper.LatestNews, latest_news_url))

# Categories
# PageList
# variables: {"pageListId":"categories"}
# extensions: {"persistedQuery":{"version":1,"sha256Hash":"58da321b8e31df2b746f1d1f374151a450a4c24bda6415182fe81551c90e7d25"}}
category_url = self.__get_api_url(
"PageList", "58da321b8e31df2b746f1d1f374151a450a4c24bda6415182fe81551c90e7d25",
{"pageListId": "categories"})
items.append(__create_item(LanguageHelper.Categories, category_url))
return data, items

def fetch_mainlist_pages(self, data: str) -> Tuple[str, List[MediaItem]]:
Expand Down Expand Up @@ -366,6 +368,9 @@ def create_api_typed_item(self, result_set):
elif api_type == "StaticPageItem":
item = self.create_api_static_page(result_set)

elif api_type == "MediaPanel" or api_type == "ClipsPanel":
item = self.create_api_panel(result_set)

else:
Logger.warning("Missing type: %s", api_type)
return None
Expand Down Expand Up @@ -468,10 +473,33 @@ def create_api_page_ref(self, result_set: dict) -> Optional[MediaItem]:
result_set = result_set["pageReference"]
title = result_set["title"]
page_id = result_set["id"]
item = FolderItem(title, "", content_type=contenttype.VIDEOS, media_type=mediatype.FOLDER)

# Link goes to a page
# operationName: Page
# variables: {"pageId":"underhållning","input":{"limit":4,"offset":4}}
# extensions: {"persistedQuery":{"version":1,"sha256Hash":"a30fb04a7dbabeaf3b08f66134c6ac1f1e4980de1f21024fa755d752608e6ad9"}}

url = self.__get_api_url(
"Page", "a30fb04a7dbabeaf3b08f66134c6ac1f1e4980de1f21024fa755d752608e6ad9",
{"pageId": page_id, "input": {"limit": 100, "offset": 0}}
)
item = FolderItem(title, url, content_type=contenttype.TVSHOWS, media_type=mediatype.FOLDER)
self.__set_art(item, result_set.get("images"))
return item

def create_api_panel(self, result_set: dict) -> Optional[MediaItem]:
# operationName: Panel
# variables: {"panelId":"AHFLXHgesJeX8Mx2lahyU","limit":12,"offset":6}
# extensions: {"persistedQuery":{"version":1,"sha256Hash":"3ef650feea500555e560903fee7fc06f8276d046ea880c5540282a5341b65985"}}
panel_id = result_set["id"]
title = result_set["title"]
url = self.__get_api_url(
"Panel", "3ef650feea500555e560903fee7fc06f8276d046ea880c5540282a5341b65985", {
"panelId": panel_id, "limit": self.__max_page_size, "offset": 0 }
)
item = FolderItem(title, url, content_type=contenttype.TVSHOWS)
return item

def create_api_static_page(self, result_set: dict) -> Optional[MediaItem]:
result_set = result_set["staticPage"]
page_id = result_set["id"]
Expand Down

0 comments on commit 9d6b9dc

Please sign in to comment.