This commit is contained in:
Marc Beninca 2025-03-19 17:50:15 +01:00
parent 7ea1f10c89
commit c3fad738b3
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -68,29 +68,41 @@ class Channel(Object):
class Format(Object):
"""YouTube format."""
@staticmethod
def get(d: dict, key: str) -> str | None:
value = d.get(key)
match value:
case "none":
return None
case _:
return value
def __init__(self, d: dict) -> None:
"""Set format info.
:param d: format info
:type d: dict
"""
self.asr = d["asr"]
self.filesize = int(d["filesize"])
self.format_id = d["format_id"]
self.format_note = d["format_id"]
self.fps = d["fps"]
self.height = int(d["height"])
self.quality = int(d["quality"])
self.width = int(d["width"])
self.language = d["language"]
self.format_note = d.get("format_note")
self.quality = d.get("quality")
self.language = d.get("language")
self.ext = d["ext"]
self.vcodec = d["vcodec"]
self.acodec = d["acodec"]
self.dynamic_range = d["dynamic_range"]
self.video_ext = d["video_ext"]
self.audio_ext = d["audio_ext"]
self.abr = d["abr"]
self.vbr = d["vbr"]
# video
self.video_codec = Format.get(d, "vcodec")
if self.video_codec:
self.video_dynamic_range = d["dynamic_range"]
self.video_fps = d["fps"]
self.video_height = int(d["height"])
self.video_bit_rate = d["vbr"]
self.video_ext = d["video_ext"]
self.video_width = int(d["width"])
# audio
self.audio_codec = Format.get(d, "acodec")
if self.audio_codec:
self.audio_bit_rate = d["abr"]
self.audio_sampling_rate = d["asr"]
self.audio_ext = d["audio_ext"]
# TODO Playlist/extra
@ -128,7 +140,16 @@ class Video(Object):
def load_extra(self):
self.at = datetime.now().strftime(TIMESTAMP)
d = extract_video(self.uid)
self.formats = [Format(format) for format in d["formats"]]
self.audio_formats = []
self.video_formats = []
for entry in d["formats"]:
f = Format(entry)
if f.video_codec:
self.video_format = f
self.video_formats.append(f)
elif f.audio_codec:
self.audio_format = f
self.audio_formats.append(f)
thumbnail = d["thumbnails"][-1]["url"]
# TODO compare existing thumbnail
self.description = d["description"]