]> jfr.im git - yt-dlp.git/commitdiff
Add new field `aspect_ratio`
authorpukkandan <redacted>
Wed, 16 Nov 2022 01:22:57 +0000 (06:52 +0530)
committerpukkandan <redacted>
Wed, 16 Nov 2022 01:27:09 +0000 (06:57 +0530)
Closes #5402

README.md
yt_dlp/YoutubeDL.py
yt_dlp/extractor/common.py

index 13a2c17c7f94c3415346012439960541b4ec5061..367c6e0364a09e71714919b0e6a92827b6189ae8 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1442,6 +1442,7 @@ ## Filtering Formats
  - `filesize_approx`: An estimate for the number of bytes
  - `width`: Width of the video, if known
  - `height`: Height of the video, if known
+ - `aspect_ratio`: Aspect ratio of the video, if known
  - `tbr`: Average bitrate of audio and video in KBit/s
  - `abr`: Average audio bitrate in KBit/s
  - `vbr`: Average video bitrate in KBit/s
index 20940085e843b7144164fe8853a6e923de105a88..25c35dc532cb01849a87a5855aeedc16ba8447c2 100644 (file)
@@ -547,7 +547,7 @@ class YoutubeDL:
     _format_fields = {
         # NB: Keep in sync with the docstring of extractor/common.py
         'url', 'manifest_url', 'manifest_stream_number', 'ext', 'format', 'format_id', 'format_note',
-        'width', 'height', 'resolution', 'dynamic_range', 'tbr', 'abr', 'acodec', 'asr', 'audio_channels',
+        'width', 'height', 'aspect_ratio', 'resolution', 'dynamic_range', 'tbr', 'abr', 'acodec', 'asr', 'audio_channels',
         'vbr', 'fps', 'vcodec', 'container', 'filesize', 'filesize_approx', 'rows', 'columns',
         'player_url', 'protocol', 'fragment_base_url', 'fragments', 'is_from_start',
         'preference', 'language', 'language_preference', 'quality', 'source_preference',
@@ -2186,6 +2186,7 @@ def _merge(formats_pair):
                     'vcodec': the_only_video.get('vcodec'),
                     'vbr': the_only_video.get('vbr'),
                     'stretched_ratio': the_only_video.get('stretched_ratio'),
+                    'aspect_ratio': the_only_video.get('aspect_ratio'),
                 })
 
             if the_only_audio:
@@ -2628,6 +2629,8 @@ def is_wellformed(f):
                 format['resolution'] = self.format_resolution(format, default=None)
             if format.get('dynamic_range') is None and format.get('vcodec') != 'none':
                 format['dynamic_range'] = 'SDR'
+            if format.get('aspect_ratio') is None:
+                format['aspect_ratio'] = try_call(lambda: round(format['width'] / format['height'], 2))
             if (info_dict.get('duration') and format.get('tbr')
                     and not format.get('filesize') and not format.get('filesize_approx')):
                 format['filesize_approx'] = int(info_dict['duration'] * format['tbr'] * (1024 / 8))
index 3a1af329011e3b72b7b68801702635a9b0bc6d17..94128bd84125ddd7708c6173608453efaa352826 100644 (file)
@@ -150,7 +150,10 @@ class InfoExtractor:
                                  ("3D" or "DASH video")
                     * width      Width of the video, if known
                     * height     Height of the video, if known
+                    * aspect_ratio  Aspect ratio of the video, if known
+                                 Automatically calculated from width and height
                     * resolution Textual description of width and height
+                                 Automatically calculated from width and height
                     * dynamic_range The dynamic range of the video. One of:
                                  "SDR" (None), "HDR10", "HDR10+, "HDR12", "HLG, "DV"
                     * tbr        Average bitrate of audio and video in KBit/s