diff --git a/src/delarte/model.py b/src/delarte/model.py new file mode 100644 index 0000000..2ce4f0c --- /dev/null +++ b/src/delarte/model.py @@ -0,0 +1,119 @@ +# 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 Metadata(NamedTuple): + """A program metadata.""" + + id: str + """The ID string.""" + + title: str + """The title.""" + + subtitle: str + """The subtitle or secondary title.""" + + description: str + """The description.""" + + duration: int + """The duration in seconds.""" + + +class RenditionAudio(NamedTuple): + """A rendition's audio part.""" + + lang: 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).""" + + provides_accessibility: bool + """Whether provides an audio description.""" + + +class RenditionSubtitles(NamedTuple): + """A rendition's subtitles part.""" + + lang: str + """ISO 639-1 two-letter language codes.""" + + provides_accessibility: bool + """Whether provides an readable description.""" + + +class Rendition(NamedTuple): + """A program's content version.""" + + audio: RenditionAudio + subtitles: Optional[RenditionSubtitles] + + @property + def code(self): + """Return a code string representation.""" + # This code string MUST be built in a way that every possible rendition + # object has its own code string. + # Also, it should be as concise as possible because it will be typed + # by the user in the command line. + code = self.audio.lang + + if self.audio.provides_accessibility: + # audio accessibility (audio description) + code += "-AD" + + if self.subtitles: + if self.subtitles.provides_accessibility: + # visual accessibility (text description) + code += "-TD" + + if self.subtitles.lang != self.audio.lang: + # specifies subtitles language only if different from audio language + return code + "-" + self.subtitles.lang + + return code + + +class Variant(NamedTuple): + """A program's quality version.""" + + width: int + """Horizontal part of the resolution.""" + height: int + """Vertical part of the resolution.""" + frame_rate: int + """Frame rate per seconds.""" + + @property + def code(self): + """Return a code string representation.""" + # This code string MUST be built in a way that every possible variant + # object has its own code string. + # Also, it should be as concise as possible because it will be typed + # by the user in the command line. + # + # So far, it seems variants differ on resolution only. + return f"{self.height}p" + + +class Source(NamedTuple): + """A program source.""" + + metadata: Metadata + rendition: Rendition + variant: Variant + + video: str + """Video track locator.""" + + audio: str + """Audio track locator.""" + + subtitles: Optional[str] + """Subtitles track locator."""