wip
This commit is contained in:
parent
59ee8ed161
commit
b4dfb3e597
1 changed files with 26 additions and 12 deletions
|
@ -83,26 +83,42 @@ class Format(Object):
|
||||||
:param d: format info
|
:param d: format info
|
||||||
:type d: dict
|
:type d: dict
|
||||||
"""
|
"""
|
||||||
self.format_id = d["format_id"]
|
self.uid = d["format_id"]
|
||||||
self.format_note = d.get("format_note")
|
self.extension = d["ext"]
|
||||||
self.quality = d.get("quality")
|
self.filesize = d.get("filesize")
|
||||||
|
self.filesize_approx = d.get("filesize_approx")
|
||||||
self.language = d.get("language")
|
self.language = d.get("language")
|
||||||
self.ext = d["ext"]
|
self.quality = d.get("quality")
|
||||||
# video
|
# video
|
||||||
self.video_codec = Format.get(d, "vcodec")
|
self.video_codec = Format.get(d, "vcodec")
|
||||||
if self.video_codec:
|
if self.video_codec:
|
||||||
|
self.video_bit_rate = d["vbr"]
|
||||||
self.video_dynamic_range = d["dynamic_range"]
|
self.video_dynamic_range = d["dynamic_range"]
|
||||||
|
self.video_extension = d["video_ext"]
|
||||||
self.video_fps = d["fps"]
|
self.video_fps = d["fps"]
|
||||||
self.video_height = int(d["height"])
|
self.video_height = int(d["height"])
|
||||||
self.video_bit_rate = d["vbr"]
|
|
||||||
self.video_ext = d["video_ext"]
|
|
||||||
self.video_width = int(d["width"])
|
self.video_width = int(d["width"])
|
||||||
|
else:
|
||||||
|
del self.video_codec
|
||||||
# audio
|
# audio
|
||||||
self.audio_codec = Format.get(d, "acodec")
|
self.audio_codec = Format.get(d, "acodec")
|
||||||
if self.audio_codec:
|
if self.audio_codec:
|
||||||
self.audio_bit_rate = d["abr"]
|
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_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
|
# TODO Playlist/extra
|
||||||
|
@ -144,10 +160,10 @@ class Video(Object):
|
||||||
self.video_formats = []
|
self.video_formats = []
|
||||||
for entry in d["formats"]:
|
for entry in d["formats"]:
|
||||||
f = Format(entry)
|
f = Format(entry)
|
||||||
if f.video_codec:
|
if hasattr(f, "video_codec"):
|
||||||
self.video_format = f
|
self.video_format = f
|
||||||
self.video_formats.append(f)
|
self.video_formats.append(f)
|
||||||
elif f.audio_codec:
|
elif hasattr(f, "audio_codec"):
|
||||||
self.audio_format = f
|
self.audio_format = f
|
||||||
self.audio_formats.append(f)
|
self.audio_formats.append(f)
|
||||||
thumbnail = d["thumbnails"][-1]["url"]
|
thumbnail = d["thumbnails"][-1]["url"]
|
||||||
|
@ -177,9 +193,7 @@ def download_video(video_id: str | None) -> None:
|
||||||
if video_id:
|
if video_id:
|
||||||
ytdl(
|
ytdl(
|
||||||
{
|
{
|
||||||
"format": "+".join(
|
"format": "bestvideo[ext=webm]+bestaudio[ext=webm]",
|
||||||
[f"best{av}[ext={EXT}]" for av in ["video", "audio"]]
|
|
||||||
),
|
|
||||||
"outtmpl": "%(id)s.%(ext)s",
|
"outtmpl": "%(id)s.%(ext)s",
|
||||||
"postprocessors": [
|
"postprocessors": [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue