From 7ea1f10c8993846a390f193f9659460cf08019c4 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Wed, 19 Mar 2025 13:30:16 +0100 Subject: [PATCH] formats --- rwx/sw/ytdlp/__init__.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/rwx/sw/ytdlp/__init__.py b/rwx/sw/ytdlp/__init__.py index 41750aa..5c500b5 100644 --- a/rwx/sw/ytdlp/__init__.py +++ b/rwx/sw/ytdlp/__init__.py @@ -65,6 +65,32 @@ class Channel(Object): # TODO Format +class Format(Object): + """YouTube format.""" + + 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.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"] # TODO Playlist/extra @@ -102,8 +128,7 @@ class Video(Object): def load_extra(self): self.at = datetime.now().strftime(TIMESTAMP) d = extract_video(self.uid) - # TODO formats - self.formats = d["formats"] + self.formats = [Format(format) for format in d["formats"]] thumbnail = d["thumbnails"][-1]["url"] # TODO compare existing thumbnail self.description = d["description"]