diff --git a/youtube_dlc/YoutubeDL.py b/youtube_dlc/YoutubeDL.py index 1f03ac1e4..6029ca38d 100644 --- a/youtube_dlc/YoutubeDL.py +++ b/youtube_dlc/YoutubeDL.py @@ -2325,7 +2325,7 @@ class YoutubeDL(object): for f in formats if f.get('preference') is None or f['preference'] >= -1000] header_line = ['ID', 'EXT', 'RESOLUTION', 'FPS', '|', ' FILESIZE', ' TBR', 'PROTO', - '|', 'VIDEO CODEC', ' VBR', 'AUDIO CODEC', ' ABR', ' ASR', 'NOTE'] + '|', 'VCODEC', ' VBR', 'ACODEC', ' ABR', ' ASR', 'NOTE'] else: table = [ [ @@ -2340,8 +2340,12 @@ class YoutubeDL(object): 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, table, delim=new_format, extraGap=(0 if new_format else 1)))) + '[info] Available formats for %s:\n%s' % (info_dict['id'], render_table( + header_line, + table, + delim=new_format, + extraGap=(0 if new_format else 1), + hideEmpty=new_format))) def list_thumbnails(self, info_dict): thumbnails = info_dict.get('thumbnails') diff --git a/youtube_dlc/utils.py b/youtube_dlc/utils.py index d2e8d7cc1..f187dd2a8 100644 --- a/youtube_dlc/utils.py +++ b/youtube_dlc/utils.py @@ -4311,10 +4311,21 @@ def determine_protocol(info_dict): return compat_urllib_parse_urlparse(url).scheme -def render_table(header_row, data, delim=False, extraGap=0): +def render_table(header_row, data, delim=False, extraGap=0, hideEmpty=False): """ Render a list of rows, each as a list of values """ + + def get_max_lens(table): + return [max(len(compat_str(v)) for v in col) for col in zip(*table)] + def filter_using_list(row, filterArray): + return [col for (take, col) in zip(filterArray, row) if take] + + if hideEmpty: + max_lens = get_max_lens(data) + header_row = filter_using_list(header_row, max_lens) + data = [filter_using_list(row, max_lens) for row in data] + table = [header_row] + data - max_lens = [max(len(compat_str(v)) for v in col) for col in zip(*table)] + max_lens = get_max_lens(table) if delim: table = [header_row] + [['-' * ml for ml in max_lens]] + data format_str = ' '.join('%-' + compat_str(ml + extraGap) + 's' for ml in max_lens[:-1]) + ' %s' @@ -5721,4 +5732,4 @@ def format_field(obj, field, template='%s', ignore=(None,''), default='', func=N val = obj.get(field, default) if func and val not in ignore: val = func(val) - return template % val if val not in ignore else default \ No newline at end of file + return template % val if val not in ignore else default