delarte_test/src/delarte/www.py
Barbagus 6b8f2232c4 Fix issue #13 - split code in multiple modules
Implemented modules:
 - api: deals with ArteTV JSON API
 - hls: deals with HLS protocol
 - muxing: deals with the stream multiplexing
 - naming: deals with output file naming
 - www: deals with ArteTV web interface
2022-12-13 07:29:59 +01:00

30 lines
819 B
Python

# Licence: GNU AGPL v3: http://www.gnu.org/licenses/
# This file is part of [`delarte`](https://git.afpy.org/fcode/delarte.git)
"""Provide ArteTV website utilities."""
from urllib.parse import urlparse
LANGUAGES = ["fr", "de", "en", "es", "pl", "it"]
def parse_url(program_page_url):
"""Parse ArteTV web URL into UI language and program ID."""
url = urlparse(program_page_url)
if url.hostname != "www.arte.tv":
raise ValueError("not an ArteTV url")
program_page_path = url.path.split("/")[1:]
lang = program_page_path.pop(0)
if lang not in LANGUAGES:
raise ValueError(f"invalid url language code: {lang}")
if program_page_path.pop(0) != "videos":
raise ValueError("invalid ArteTV url")
program_id = program_page_path.pop(0)
return lang, program_id