diff --git a/rwx/sw/ytdlp/__init__.py b/rwx/sw/ytdlp/__init__.py index b609019..5f6af1f 100644 --- a/rwx/sw/ytdlp/__init__.py +++ b/rwx/sw/ytdlp/__init__.py @@ -83,26 +83,42 @@ class Format(Object): :param d: format info :type d: dict """ - self.format_id = d["format_id"] - self.format_note = d.get("format_note") - self.quality = d.get("quality") + self.uid = d["format_id"] + self.extension = d["ext"] + self.filesize = d.get("filesize") + self.filesize_approx = d.get("filesize_approx") self.language = d.get("language") - self.ext = d["ext"] + self.quality = d.get("quality") # video self.video_codec = Format.get(d, "vcodec") if self.video_codec: + self.video_bit_rate = d["vbr"] self.video_dynamic_range = d["dynamic_range"] + self.video_extension = d["video_ext"] 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"]) + else: + del self.video_codec # audio self.audio_codec = Format.get(d, "acodec") if self.audio_codec: self.audio_bit_rate = d["abr"] + self.audio_channels = int(d["audio_channels"]) + self.audio_extension = d["audio_ext"] self.audio_sampling_rate = d["asr"] - self.audio_ext = d["audio_ext"] + else: + del self.audio_codec + + def audio(self) -> str: + return f"{self.uid} \ +→ {self.audio_sampling_rate} × {self.audio_channels} \ +@ {self.audio_bit_rate} × {self.audio_codec}" + + def video(self) -> str: + return f"{self.uid} \ +→ {self.video_width} × {self.video_height} × {self.video_fps} \ +@ {self.video_bit_rate} × {self.video_codec}" # TODO Playlist/extra @@ -144,10 +160,10 @@ class Video(Object): self.video_formats = [] for entry in d["formats"]: f = Format(entry) - if f.video_codec: + if hasattr(f, "video_codec"): self.video_format = f self.video_formats.append(f) - elif f.audio_codec: + elif hasattr(f, "audio_codec"): self.audio_format = f self.audio_formats.append(f) thumbnail = d["thumbnails"][-1]["url"] @@ -177,9 +193,7 @@ def download_video(video_id: str | None) -> None: if video_id: ytdl( { - "format": "+".join( - [f"best{av}[ext={EXT}]" for av in ["video", "audio"]] - ), + "format": "bestvideo[ext=webm]+bestaudio[ext=webm]", "outtmpl": "%(id)s.%(ext)s", "postprocessors": [ {