]> jfr.im git - yt-dlp.git/commitdiff
[formatsort] Remove forced priority of `quality`
authorpukkandan <redacted>
Thu, 18 Feb 2021 18:12:56 +0000 (23:42 +0530)
committerpukkandan <redacted>
Thu, 18 Feb 2021 18:42:21 +0000 (00:12 +0530)
When making `FormatSort`, I misinterpreted the purpose `quality`

README.md
youtube_dlc/YoutubeDL.py
youtube_dlc/extractor/arte.py
youtube_dlc/extractor/common.py
youtube_dlc/extractor/youtube.py

index 520a85d7e369fba57210caf91c4ce68a4596c5aa..17bd3b0b39367c29b198941f99ec7ecf70138a18 100644 (file)
--- a/README.md
+++ b/README.md
@@ -986,7 +986,7 @@ ## Sorting Formats
  - `hasaud`: Gives priority to formats that has a audio stream
  - `ie_pref`: The format preference as given by the extractor
  - `lang`: Language preference as given by the extractor
- - `quality`: The quality of the format. This is a metadata field available in some websites
+ - `quality`: The quality of the format as given by the extractor
  - `source`: Preference of the source as given by the extractor
  - `proto`: Protocol used for download (`https`/`ftps` > `http`/`ftp` > `m3u8-native` > `m3u8` > `http-dash-segments` > other > `mms`/`rtsp` > unknown > `f4f`/`f4m`)
  - `vcodec`: Video Codec (`av01` > `vp9.2` > `vp9` > `h265` > `h264` > `vp8` > `h263` > `theora` > other > unknown)
@@ -1010,7 +1010,7 @@ ## Sorting Formats
 
 Note that any other **numerical** field made available by the extractor can also be used. All fields, unless specified otherwise, are sorted in decending order. To reverse this, prefix the field with a `+`. Eg: `+res` prefers format with the smallest resolution. Additionally, you can suffix a prefered value for the fields, seperated by a `:`. Eg: `res:720` prefers larger videos, but no larger than 720p and the smallest video if there are no videos less than 720p. For `codec` and `ext`, you can provide two prefered values, the first for video and the second for audio. Eg: `+codec:avc:m4a` (equivalent to `+vcodec:avc,+acodec:m4a`) sets the video codec preference to `h264` > `h265` > `vp9` > `vp9.2` > `av01` > `vp8` > `h263` > `theora` and audio codec preference to `mp4a` > `aac` > `vorbis` > `opus` > `mp3` > `ac3` > `dts`. You can also make the sorting prefer the nearest values to the provided by using `~` as the delimiter. Eg: `filesize~1G` prefers the format with filesize closest to 1 GiB.
 
-The fields `hasvid`, `ie_pref`, `lang`, `quality` are always given highest priority in sorting, irrespective of the user-defined order. This behaviour can be changed by using `--force-format-sort`. Apart from these, the default order used is: `res,fps,codec:vp9,size,br,asr,proto,ext,hasaud,source,id`. Note that the extractors may override this default order, but they cannot override the user-provided order.
+The fields `hasvid`, `ie_pref`, `lang` are always given highest priority in sorting, irrespective of the user-defined order. This behaviour can be changed by using `--force-format-sort`. Apart from these, the default order used is: `quality,res,fps,codec:vp9.2,size,br,asr,proto,ext,hasaud,source,id`. Note that the extractors may override this default order, but they cannot override the user-provided order.
 
 If your format selector is `worst`, the last item is selected after sorting. This means it will select the format that is worst in all repects. Most of the time, what you actually want is the video with the smallest filesize instead. So it is generally better to use `-f best -S +size,+br,+res,+fps`.
 
index 125ce767cd8a0c50d6d8fcd4f7781155cb872b55..ac892b83778da27177c67a3dc870df4bb1ea7b14 100644 (file)
@@ -2716,8 +2716,6 @@ def list_formats(self, info_dict):
                 if f.get('preference') is None or f['preference'] >= -1000]
             header_line = ['format code', 'extension', 'resolution', 'note']
 
-        # if len(formats) > 1:
-        #     table[-1][-1] += (' ' if table[-1][-1] else '') + '(best)'
         self.to_screen(
             '[info] Available formats for %s:\n%s' % (info_dict['id'], render_table(
                 header_line,
index 03abdbfafa7cfb5c5aedf289cbe7ce0bb6d7ab35..ca41aaea99c7ac06bf2f23056b850bd1da8fc372 100644 (file)
@@ -168,7 +168,9 @@ def _real_extract(self, url):
 
             formats.append(format)
 
-        self._sort_formats(formats)
+        # For this extractor, quality only represents the relative quality
+        # with respect to other formats with the same resolution
+        self._sort_formats(formats, ('res', 'quality'))
 
         return {
             'id': player_info.get('VID') or video_id,
index 49df880d0bf1117eac351c6eec00201b742dd8d5..b8e84089b93ed4703c2c178ba3db9c5594673439 100644 (file)
@@ -1388,7 +1388,7 @@ class FormatSort:
             'hasvid': {'priority': True, 'field': 'vcodec', 'type': 'boolean', 'not_in_list': ('none',)},
             'hasaud': {'field': 'acodec', 'type': 'boolean', 'not_in_list': ('none',)},
             'lang': {'priority': True, 'convert': 'ignore', 'field': 'language_preference'},
-            'quality': {'priority': True, 'convert': 'float_none'},
+            'quality': {'convert': 'float_none'},
             'filesize': {'convert': 'bytes'},
             'fs_approx': {'convert': 'bytes', 'field': 'filesize_approx'},
             'id': {'convert': 'string', 'field': 'format_id'},
index 4a2f5f06b5574b020b2febd0c3d31cd69411e935..5ff4c42a2d309a34abc5a93c040c9ec978775626 100644 (file)
@@ -32,7 +32,7 @@
     mimetype2ext,
     parse_codecs,
     parse_duration,
-    # qualities,  # TODO: Enable this after fixing formatSort
+    qualities,
     remove_start,
     smuggle_url,
     str_or_none,
@@ -1528,8 +1528,7 @@ def feed_entry(name):
         itags = []
         itag_qualities = {}
         player_url = None
-        # TODO: Enable this after fixing formatSort
-        # q = qualities(['tiny', 'small', 'medium', 'large', 'hd720', 'hd1080', 'hd1440', 'hd2160', 'hd2880', 'highres'])
+        q = qualities(['tiny', 'small', 'medium', 'large', 'hd720', 'hd1080', 'hd1440', 'hd2160', 'hd2880', 'highres'])
         streaming_data = player_response.get('streamingData') or {}
         streaming_formats = streaming_data.get('formats') or []
         streaming_formats.extend(streaming_data.get('adaptiveFormats') or [])
@@ -1577,7 +1576,7 @@ def feed_entry(name):
                 'format_note': fmt.get('qualityLabel') or quality,
                 'fps': int_or_none(fmt.get('fps')),
                 'height': int_or_none(fmt.get('height')),
-                # 'quality': q(quality),    # TODO: Enable this after fixing formatSort
+                'quality': q(quality),
                 'tbr': tbr,
                 'url': fmt_url,
                 'width': fmt.get('width'),
@@ -1620,8 +1619,11 @@ def feed_entry(name):
                     itag = f['format_id']
                     if itag in itags:
                         continue
-                    # if itag in itag_qualities:  # TODO: Enable this after fixing formatSort
-                    #     f['quality'] = q(itag_qualities[itag])
+                    if itag in itag_qualities:
+                        # Not actually usefull since the sorting is already done with "quality,res,fps,codec"
+                        # but kept to maintain feature parity (and code similarity) with youtube-dl
+                        # Remove if this causes any issues with sorting in future
+                        f['quality'] = q(itag_qualities[itag])
                     filesize = int_or_none(self._search_regex(
                         r'/clen/(\d+)', f.get('fragment_base_url')
                         or f['url'], 'file size', default=None))