[formatsort] Remove forced priority of quality

When making `FormatSort`, I misinterpreted the purpose `quality`
This commit is contained in:
pukkandan 2021-02-18 23:42:56 +05:30
parent da9be05edf
commit dca3ff4a5e
5 changed files with 14 additions and 12 deletions

View file

@ -986,7 +986,7 @@ ## Sorting Formats
- `hasaud`: Gives priority to formats that has a audio stream - `hasaud`: Gives priority to formats that has a audio stream
- `ie_pref`: The format preference as given by the extractor - `ie_pref`: The format preference as given by the extractor
- `lang`: Language 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 - `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`) - `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) - `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. 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`. 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`.

View file

@ -2716,8 +2716,6 @@ def list_formats(self, info_dict):
if f.get('preference') is None or f['preference'] >= -1000] if f.get('preference') is None or f['preference'] >= -1000]
header_line = ['format code', 'extension', 'resolution', 'note'] header_line = ['format code', 'extension', 'resolution', 'note']
# if len(formats) > 1:
# table[-1][-1] += (' ' if table[-1][-1] else '') + '(best)'
self.to_screen( self.to_screen(
'[info] Available formats for %s:\n%s' % (info_dict['id'], render_table( '[info] Available formats for %s:\n%s' % (info_dict['id'], render_table(
header_line, header_line,

View file

@ -168,7 +168,9 @@ def _real_extract(self, url):
formats.append(format) 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 { return {
'id': player_info.get('VID') or video_id, 'id': player_info.get('VID') or video_id,

View file

@ -1388,7 +1388,7 @@ class FormatSort:
'hasvid': {'priority': True, 'field': 'vcodec', 'type': 'boolean', 'not_in_list': ('none',)}, 'hasvid': {'priority': True, 'field': 'vcodec', 'type': 'boolean', 'not_in_list': ('none',)},
'hasaud': {'field': 'acodec', 'type': 'boolean', 'not_in_list': ('none',)}, 'hasaud': {'field': 'acodec', 'type': 'boolean', 'not_in_list': ('none',)},
'lang': {'priority': True, 'convert': 'ignore', 'field': 'language_preference'}, 'lang': {'priority': True, 'convert': 'ignore', 'field': 'language_preference'},
'quality': {'priority': True, 'convert': 'float_none'}, 'quality': {'convert': 'float_none'},
'filesize': {'convert': 'bytes'}, 'filesize': {'convert': 'bytes'},
'fs_approx': {'convert': 'bytes', 'field': 'filesize_approx'}, 'fs_approx': {'convert': 'bytes', 'field': 'filesize_approx'},
'id': {'convert': 'string', 'field': 'format_id'}, 'id': {'convert': 'string', 'field': 'format_id'},

View file

@ -32,7 +32,7 @@
mimetype2ext, mimetype2ext,
parse_codecs, parse_codecs,
parse_duration, parse_duration,
# qualities, # TODO: Enable this after fixing formatSort qualities,
remove_start, remove_start,
smuggle_url, smuggle_url,
str_or_none, str_or_none,
@ -1528,8 +1528,7 @@ def feed_entry(name):
itags = [] itags = []
itag_qualities = {} itag_qualities = {}
player_url = None 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_data = player_response.get('streamingData') or {}
streaming_formats = streaming_data.get('formats') or [] streaming_formats = streaming_data.get('formats') or []
streaming_formats.extend(streaming_data.get('adaptiveFormats') or []) streaming_formats.extend(streaming_data.get('adaptiveFormats') or [])
@ -1577,7 +1576,7 @@ def feed_entry(name):
'format_note': fmt.get('qualityLabel') or quality, 'format_note': fmt.get('qualityLabel') or quality,
'fps': int_or_none(fmt.get('fps')), 'fps': int_or_none(fmt.get('fps')),
'height': int_or_none(fmt.get('height')), 'height': int_or_none(fmt.get('height')),
# 'quality': q(quality), # TODO: Enable this after fixing formatSort 'quality': q(quality),
'tbr': tbr, 'tbr': tbr,
'url': fmt_url, 'url': fmt_url,
'width': fmt.get('width'), 'width': fmt.get('width'),
@ -1620,8 +1619,11 @@ def feed_entry(name):
itag = f['format_id'] itag = f['format_id']
if itag in itags: if itag in itags:
continue continue
# if itag in itag_qualities: # TODO: Enable this after fixing formatSort if itag in itag_qualities:
# f['quality'] = q(itag_qualities[itag]) # 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( filesize = int_or_none(self._search_regex(
r'/clen/(\d+)', f.get('fragment_base_url') r'/clen/(\d+)', f.get('fragment_base_url')
or f['url'], 'file size', default=None)) or f['url'], 'file size', default=None))