delarte/src/delarte/model.py
Barbagus 639a8063a5 Get program information from page content
Changes the way the program information is figured out. From URL parsing
to page content parsing.
A massive JSON object is shipped within the HTML of the page, that's
were we get what we need from.

Side effects:
 - drop `slug` from the program's info
 - drop `slug` naming option
 - no `Program` / `ProgramMeta` distinction

Includes some JSON samples.
2023-01-14 19:51:02 +01:00

113 lines
2.1 KiB
Python

# License: GNU AGPL v3: http://www.gnu.org/licenses/
# This file is part of `delarte` (https://git.afpy.org/fcode/delarte.git)
"""Provide data model types."""
from typing import NamedTuple, Optional
class ProgramMeta(NamedTuple):
"""A program metadata."""
site: str
"""The site where it is hosted (fr, de, etc...)."""
id: str
"""The ID."""
title: str
"""The title."""
subtitle: str
"""The subtitle or secondary title."""
class VideoMeta(NamedTuple):
"""A video track metadata."""
width: int
"""Horizontal part of the resolution."""
height: int
"""Vertical part of the resolution."""
frame_rate: float
"""Frame rate per seconds."""
class SubtitlesMeta(NamedTuple):
"""A subtitles track metadata."""
language: str
"""ISO 639-1 two-letter language codes."""
is_descriptive: bool
"""Whether provides a textual description (closed captions)."""
class AudioMeta(NamedTuple):
"""A audio track metadata."""
language: str
"""ISO 639-1 two-letter language codes, or "mul" for multiple languages."""
is_original: bool
"""Whether audio track is original (no audio description or dubbing)."""
is_descriptive: bool
"""Whether provides an audio description."""
class VideoTrack(NamedTuple):
"""A video track."""
meta: VideoMeta
url: str
class SubtitlesTrack(NamedTuple):
"""A subtitles track."""
meta: SubtitlesMeta
url: str
class AudioTrack(NamedTuple):
"""A audio track."""
meta: AudioMeta
url: str
class Variant(NamedTuple):
"""A program variant."""
key: VideoMeta
source: str
class Rendition(NamedTuple):
"""A program rendition."""
key: tuple[AudioMeta, Optional[SubtitlesMeta]]
source: tuple[str, Optional[str]]
class Sources(NamedTuple):
"""A program's sources."""
program: ProgramMeta
variants: list[Variant]
renditions: list[Rendition]
class Target(NamedTuple):
"""A download target."""
program: ProgramMeta
video_track: VideoTrack
audio_track: AudioTrack
subtitles_track: Optional[SubtitlesTrack]
file_name: str