Implement collections

This commit is contained in:
Barbagus 2023-01-24 19:59:39 +01:00
parent 3ca02e8e42
commit e23cd73664
1 changed files with 65 additions and 9 deletions

View File

@ -15,13 +15,24 @@ def _process_programs_page(page_value):
language = page_value["language"]
zone_found = False
program_found = False
for zone in page_value["zones"]:
if not zone["code"].startswith("program_content_"):
if zone["code"].startswith("program_content_"):
if zone_found:
raise InvalidPage("PROGRAMS_CONTENT_ZONES_COUNT")
zone_found = True
else:
continue
for data_item in zone["content"]["data"]:
if (_ := data_item["type"]) != "program":
raise InvalidPage("PROGRAMS_INVALID_CONTENT_DATA_ITEM", _)
if data_item["type"] == "program":
if program_found:
raise InvalidPage("PROGRAMS_CONTENT_PROGRAM_COUNT")
program_found = True
else:
raise InvalidPage("PROGRAMS_CONTENT_PROGRAM_TYPE")
yield (
Program(
@ -33,14 +44,57 @@ def _process_programs_page(page_value):
data_item["player"]["config"],
)
break
else:
raise InvalidPage("PROGRAMS_PROGRAMS_COUNT")
break
else:
if not zone_found:
raise InvalidPage("PROGRAMS_CONTENT_ZONES_COUNT")
if not program_found:
raise InvalidPage("PROGRAMS_CONTENT_PROGRAM_COUNT")
def _process_collections_page(page_value):
language = page_value["language"]
main_zone_found = False
sub_zone_found = False
program_found = False
for zone in page_value["zones"]:
if zone["code"].startswith("collection_videos_"):
if main_zone_found:
raise InvalidPage("COLLECTIONS_MAIN_ZONE_COUNT")
if program_found:
raise InvalidPage("COLLECTIONS_MIXED_ZONES")
main_zone_found = True
elif zone["code"].startswith("collection_subcollection_"):
if program_found and not sub_zone_found:
raise InvalidPage("COLLECTIONS_MIXED_ZONES")
sub_zone_found = True
else:
continue
for data_item in zone["content"]["data"]:
if (_ := data_item["type"]) == "teaser":
program_found = True
else:
raise InvalidPage("COLLECTIONS_INVALID_CONTENT_DATA_ITEM", _)
yield (
Program(
data_item["programId"],
language,
data_item["title"],
data_item["subtitle"],
),
f"https://api.arte.tv/api/player/v2/config/{language}/{data_item['programId']}",
)
if not main_zone_found:
raise InvalidPage("COLLECTIONS_MAIN_ZONE_COUNT")
if not program_found:
raise InvalidPage("COLLECTIONS_PROGRAMS_COUNT")
def iter_programs(page_url, http_session):
"""Iterate over programs listed on given ArteTV page."""
@ -71,6 +125,8 @@ def iter_programs(page_url, http_session):
match initial_type:
case "programs":
yield from _process_programs_page(initial_page_value)
case "collections":
yield from _process_collections_page(initial_page_value)
case _:
raise PageNotSupported(page_url, initial_type)