wip
This commit is contained in:
parent
7ea1f10c89
commit
c3fad738b3
1 changed files with 37 additions and 16 deletions
|
@ -68,29 +68,41 @@ class Channel(Object):
|
||||||
class Format(Object):
|
class Format(Object):
|
||||||
"""YouTube format."""
|
"""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:
|
def __init__(self, d: dict) -> None:
|
||||||
"""Set format info.
|
"""Set format info.
|
||||||
|
|
||||||
:param d: format info
|
:param d: format info
|
||||||
:type d: dict
|
:type d: dict
|
||||||
"""
|
"""
|
||||||
self.asr = d["asr"]
|
|
||||||
self.filesize = int(d["filesize"])
|
|
||||||
self.format_id = d["format_id"]
|
self.format_id = d["format_id"]
|
||||||
self.format_note = d["format_id"]
|
self.format_note = d.get("format_note")
|
||||||
self.fps = d["fps"]
|
self.quality = d.get("quality")
|
||||||
self.height = int(d["height"])
|
self.language = d.get("language")
|
||||||
self.quality = int(d["quality"])
|
|
||||||
self.width = int(d["width"])
|
|
||||||
self.language = d["language"]
|
|
||||||
self.ext = d["ext"]
|
self.ext = d["ext"]
|
||||||
self.vcodec = d["vcodec"]
|
# video
|
||||||
self.acodec = d["acodec"]
|
self.video_codec = Format.get(d, "vcodec")
|
||||||
self.dynamic_range = d["dynamic_range"]
|
if self.video_codec:
|
||||||
self.video_ext = d["video_ext"]
|
self.video_dynamic_range = d["dynamic_range"]
|
||||||
self.audio_ext = d["audio_ext"]
|
self.video_fps = d["fps"]
|
||||||
self.abr = d["abr"]
|
self.video_height = int(d["height"])
|
||||||
self.vbr = d["vbr"]
|
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
|
# TODO Playlist/extra
|
||||||
|
@ -128,7 +140,16 @@ class Video(Object):
|
||||||
def load_extra(self):
|
def load_extra(self):
|
||||||
self.at = datetime.now().strftime(TIMESTAMP)
|
self.at = datetime.now().strftime(TIMESTAMP)
|
||||||
d = extract_video(self.uid)
|
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"]
|
thumbnail = d["thumbnails"][-1]["url"]
|
||||||
# TODO compare existing thumbnail
|
# TODO compare existing thumbnail
|
||||||
self.description = d["description"]
|
self.description = d["description"]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue