Skip to content

Commit

Permalink
Fixed: Determine the 'New on SVT'-ID.
Browse files Browse the repository at this point in the history
Fixed: NPO tests.
  • Loading branch information
basrieter committed Dec 25, 2023
1 parent 58dc7c4 commit b47dc00
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
27 changes: 22 additions & 5 deletions channels/channel.se/svt/chn_svt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later

import datetime
from typing import Optional
from typing import Optional, List, Tuple

import pytz

Expand Down Expand Up @@ -115,6 +115,10 @@ def __init__(self, channel_info):
parser=["videos"],
creator=self.create_api_typed_item)

self._add_data_parser("https://www.svtplay.se", match_type=ParserData.MatchExact,
name="SVTPlay data retriever for New on SVT",
preprocessor=self.extract_new_on_svt_id)

# Setup channel listing based on JSON data in the HTML
self._add_data_parser(
"https://api.svt.se/contento/graphql?operationName=BroadcastSchedule",
Expand Down Expand Up @@ -222,11 +226,13 @@ def add_live_items_and_genres(self, data):
),

# The selection ID might change over time.
# We need to determine the `selectionId`
LanguageHelper.get_localized_string(LanguageHelper.NewOnChannel) % self.channelName: (
self.__get_api_url(
"FionaPage",
"b4e65a8f4cedc6bd9981e3539690908443f625c6854ea65f18c4b3b3be66b5dc",
variables={"includeFullOppetArkiv": True, "selectionId": "svtId_jGVZ7AL"}),
# self.__get_api_url(
# "FionaPage",
# "b4e65a8f4cedc6bd9981e3539690908443f625c6854ea65f18c4b3b3be66b5dc",
# variables={"includeFullOppetArkiv": True, "selectionId": "svtId_jGVZ7AL"}),
"https://www.svtplay.se",
False)
}
# https://api.svt.se/contento/graphql?operationName=FionaPage&variables={"includeFullOppetArkiv":true,"selectionId":"svtId_egWQ3y7","userIsAbroad":true}&extensions={"persistedQuery":{"sha256Hash":"dc8f85e195903fe6227a76ec1e1d300d470ee8ea123bea6bee26215cc6e4959d","version":1}}&ua=svtplaywebb-render-low-prio-client
Expand Down Expand Up @@ -875,6 +881,17 @@ def create_api_search_hit(self, result_set):
else:
return self.create_api_genre_type(result_set)

def extract_new_on_svt_id(self, data: str) -> Tuple[str, List[MediaItem]]:
new_id = Regexer.do_regex(r'href="/lista/(svtId_8YqXpEz)/nytt-pa-play"', data)[0]
url = self.__get_api_url(
"FionaPage",
"b4e65a8f4cedc6bd9981e3539690908443f625c6854ea65f18c4b3b3be66b5dc",
variables={"includeFullOppetArkiv": True, "selectionId": new_id})

self.parentItem.url = url
items = self.process_folder_list(self.parentItem)
return data, items

# noinspection PyUnusedLocal
def fetch_program_api_data(self, data):
""" Loaded the data that contains the main episodes for a show.
Expand Down
2 changes: 1 addition & 1 deletion tests/channel_tests/test_chn_svt.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_genre_recent_news(self):

def test_new_on_svt(self):
# url = "https://contento.svt.se/graphql?operationName=FionaPage&variables=%7B%22includeFullOppetArkiv%22%3Atrue%2C%22selectionId%22%3A%22svtId_jGVZ7AL%22%2C%22userIsAbroad%22%3Atrue%7D&extensions=%7B%22persistedQuery%22%3A%7B%22sha256Hash%22%3A%22b4e65a8f4cedc6bd9981e3539690908443f625c6854ea65f18c4b3b3be66b5dc%22%2C%22version%22%3A1%7D%7D&ua=svtplaywebb-render-prod-low-prio-client"
url = "https://api.svt.se/contento/graphql?operationName=FionaPage&variables=%7B%22includeFullOppetArkiv%22%3Atrue%2C%22selectionId%22%3A%22svtId_jGVZ7AL%22%2C%22userIsAbroad%22%3Atrue%7D&extensions=%7B%22persistedQuery%22%3A%7B%22sha256Hash%22%3A%22b4e65a8f4cedc6bd9981e3539690908443f625c6854ea65f18c4b3b3be66b5dc%22%2C%22version%22%3A1%7D%7D&ua=svtplaywebb-render-low-prio-client"
url = "https://www.svtplay.se"
self._test_folder_url(url, expected_results=4)

def test_latest_news(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_listfilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ def tearDown(self):

def __get_items(self):
items = self._test_folder_url(
"https://npo.nl/start/api/domain/programs-by-season?guid=43eb0443-7ac8-4629-a7ed-b39ab65574b5",
expected_results=1, retry=0)
"https://npo.nl/start/api/domain/programs-by-season?guid=992a901f-54b9-445f-b548-c182f27e532e",
expected_results=0, retry=0)
return items

0 comments on commit b47dc00

Please sign in to comment.