From ae2ca42857ab911c16b03518eef61a41282451ef Mon Sep 17 00:00:00 2001 From: Yen Chi Hsuan Date: Sun, 13 Sep 2015 20:00:10 +0800 Subject: [PATCH 1/6] [options] Cleanup double spaces in help texts --- youtube_dl/options.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/youtube_dl/options.py b/youtube_dl/options.py index 5eccc0a70..3dd6d290b 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -276,7 +276,7 @@ def parseOpts(overrideArguments=None): 'For example, to only match videos that have been liked more than ' '100 times and disliked less than 50 times (or the dislike ' 'functionality is not available at the given service), but who ' - 'also have a description, use --match-filter ' + 'also have a description, use --match-filter ' '"like_count > 100 & dislike_count Date: Sun, 13 Sep 2015 20:04:27 +0800 Subject: [PATCH 2/6] [compat] Allow overriding by only COLUMNS or LINES in compat_get_terminal_size Now the semantic of this function is identical to shutil.get_terminal_size() in Python 3.3+. The new behavior also corresponds to the old get_term_width(), which is removed in 003c69a84b68cadb46aeb8e03115848a722fd675 --- youtube_dl/compat.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/youtube_dl/compat.py b/youtube_dl/compat.py index e32bef279..2dc1e965b 100644 --- a/youtube_dl/compat.py +++ b/youtube_dl/compat.py @@ -416,7 +416,7 @@ if hasattr(shutil, 'get_terminal_size'): # Python >= 3.3 else: _terminal_size = collections.namedtuple('terminal_size', ['columns', 'lines']) - def compat_get_terminal_size(): + def compat_get_terminal_size(fallback=(80, 24)): columns = compat_getenv('COLUMNS', None) if columns: columns = int(columns) @@ -428,14 +428,20 @@ else: else: lines = None - try: - sp = subprocess.Popen( - ['stty', 'size'], - stdout=subprocess.PIPE, stderr=subprocess.PIPE) - out, err = sp.communicate() - lines, columns = map(int, out.split()) - except Exception: - pass + if columns <= 0 or lines <= 0: + try: + sp = subprocess.Popen( + ['stty', 'size'], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out, err = sp.communicate() + _columns, _lines = map(int, out.split()) + except Exception: + _columns, _lines = _terminal_size(fallback) + + if columns <= 0: + columns = _columns + if lines <= 0: + lines = _lines return _terminal_size(columns, lines) try: From a97d2ade98418aec72e56f445d71bb697ba1b973 Mon Sep 17 00:00:00 2001 From: Yen Chi Hsuan Date: Sun, 13 Sep 2015 20:10:23 +0800 Subject: [PATCH 3/6] [doc] Better formatting of youtube-dl.1 (closes #6510) --- Makefile | 12 +++++++----- devscripts/make_readme.py | 4 ++-- devscripts/prepare_manpage.py | 30 +++++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index fdb1abb60..428aaf225 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ all: youtube-dl README.md CONTRIBUTING.md README.txt youtube-dl.1 youtube-dl.bash-completion youtube-dl.zsh youtube-dl.fish supportedsites clean: - rm -rf youtube-dl.1.temp.md youtube-dl.1 youtube-dl.bash-completion README.txt MANIFEST build/ dist/ .coverage cover/ youtube-dl.tar.gz youtube-dl.zsh youtube-dl.fish *.dump *.part *.info.json *.mp4 *.flv *.mp3 *.avi CONTRIBUTING.md.tmp youtube-dl youtube-dl.exe + rm -rf README-wide.md youtube-dl.1.temp.md youtube-dl.1 youtube-dl.bash-completion README.txt MANIFEST build/ dist/ .coverage cover/ youtube-dl.tar.gz youtube-dl.zsh youtube-dl.fish *.dump *.part *.info.json *.mp4 *.flv *.mp3 *.avi CONTRIBUTING.md.tmp youtube-dl youtube-dl.exe find . -name "*.pyc" -delete PREFIX ?= /usr/local @@ -61,7 +61,8 @@ youtube-dl: youtube_dl/*.py youtube_dl/*/*.py chmod a+x youtube-dl README.md: youtube_dl/*.py youtube_dl/*/*.py - COLUMNS=80 python youtube_dl/__main__.py --help | python devscripts/make_readme.py + COLUMNS=80 python youtube_dl/__main__.py --help | python devscripts/make_readme.py README.md > README.new.md + mv -f README.new.md README.md CONTRIBUTING.md: README.md python devscripts/make_contributing.py README.md CONTRIBUTING.md @@ -72,10 +73,11 @@ supportedsites: README.txt: README.md pandoc -f markdown -t plain README.md -o README.txt -youtube-dl.1: README.md - python devscripts/prepare_manpage.py >youtube-dl.1.temp.md +youtube-dl.1: youtube_dl/*.py youtube_dl/*/*.py + COLUMNS=65536 python youtube_dl/__main__.py --help | python devscripts/make_readme.py README.md > README-wide.md + python devscripts/prepare_manpage.py README-wide.md > youtube-dl.1.temp.md pandoc -s -f markdown -t man youtube-dl.1.temp.md -o youtube-dl.1 - rm -f youtube-dl.1.temp.md + rm -f youtube-dl.1.temp.md README-wide.md youtube-dl.bash-completion: youtube_dl/*.py youtube_dl/*/*.py devscripts/bash-completion.in python devscripts/bash-completion.py diff --git a/devscripts/make_readme.py b/devscripts/make_readme.py index 8fbce0796..c9dd35aa1 100755 --- a/devscripts/make_readme.py +++ b/devscripts/make_readme.py @@ -4,7 +4,7 @@ import io import sys import re -README_FILE = 'README.md' +README_FILE = sys.argv[1] helptext = sys.stdin.read() if isinstance(helptext, bytes): @@ -20,7 +20,7 @@ options = helptext[helptext.index(' General Options:') + 19:] options = re.sub(r'(?m)^ (\w.+)$', r'## \1', options) options = '# OPTIONS\n' + options + '\n' -with io.open(README_FILE, 'w', encoding='utf-8') as f: +with io.open(sys.stdout.fileno(), 'w', encoding='utf-8') as f: f.write(header) f.write(options) f.write(footer) diff --git a/devscripts/prepare_manpage.py b/devscripts/prepare_manpage.py index 7ece37754..cc7215257 100644 --- a/devscripts/prepare_manpage.py +++ b/devscripts/prepare_manpage.py @@ -6,7 +6,33 @@ import sys import re ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -README_FILE = os.path.join(ROOT_DIR, 'README.md') +README_FILE = os.path.join(ROOT_DIR, sys.argv[1]) + + +def filter_options(readme): + ret = '' + in_options = False + for line in readme.split('\n'): + if line.startswith('# '): + if line[2:].startswith('OPTIONS'): + in_options = True + else: + in_options = False + + if in_options and line.lstrip().startswith('-'): + option, description = re.split(r'\s{2,}', line.lstrip()) + split_option = option.split(' ') + + if not split_option[-1].startswith('-'): # metavar + option = ' '.join(split_option[:-1] + ['*%s*' % split_option[-1]]) + + # Pandoc's definition_lists. See http://pandoc.org/README.html + # for more information. + ret += '%s\n: %s\n\n' % (option, description) + else: + ret += line + '\n' + + return ret with io.open(README_FILE, encoding='utf-8') as f: readme = f.read() @@ -26,6 +52,8 @@ readme = re.sub(r'(?s)^.*?(?=# DESCRIPTION)', '', readme) readme = re.sub(r'\s+youtube-dl \[OPTIONS\] URL \[URL\.\.\.\]', '', readme) readme = PREFIX + readme +readme = filter_options(readme) + if sys.version_info < (3, 0): print(readme.encode('utf-8')) else: From dc17eea4adb2f787de9f6dd0f866c9328ea4adb3 Mon Sep 17 00:00:00 2001 From: Yen Chi Hsuan Date: Mon, 14 Sep 2015 18:27:39 +0800 Subject: [PATCH 4/6] [compat] Fix compat_get_terminal_size() The arguments for os.terminal_size and _terminal_size is different. --- youtube_dl/compat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/youtube_dl/compat.py b/youtube_dl/compat.py index 2dc1e965b..34bd7efa3 100644 --- a/youtube_dl/compat.py +++ b/youtube_dl/compat.py @@ -436,7 +436,7 @@ else: out, err = sp.communicate() _columns, _lines = map(int, out.split()) except Exception: - _columns, _lines = _terminal_size(fallback) + _columns, _lines = _terminal_size(*fallback) if columns <= 0: columns = _columns From 0f0a3764c3079de1cfb780f7d32300596180d147 Mon Sep 17 00:00:00 2001 From: Yen Chi Hsuan Date: Thu, 1 Oct 2015 23:02:08 +0800 Subject: [PATCH 5/6] [doc] Eliminate README-wide.md --- Makefile | 9 ++++----- devscripts/prepare_manpage.py | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 428aaf225..d48485567 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ all: youtube-dl README.md CONTRIBUTING.md README.txt youtube-dl.1 youtube-dl.bash-completion youtube-dl.zsh youtube-dl.fish supportedsites clean: - rm -rf README-wide.md youtube-dl.1.temp.md youtube-dl.1 youtube-dl.bash-completion README.txt MANIFEST build/ dist/ .coverage cover/ youtube-dl.tar.gz youtube-dl.zsh youtube-dl.fish *.dump *.part *.info.json *.mp4 *.flv *.mp3 *.avi CONTRIBUTING.md.tmp youtube-dl youtube-dl.exe + rm -rf youtube-dl.1.temp.md youtube-dl.1 youtube-dl.bash-completion README.txt MANIFEST build/ dist/ .coverage cover/ youtube-dl.tar.gz youtube-dl.zsh youtube-dl.fish *.dump *.part *.info.json *.mp4 *.flv *.mp3 *.avi CONTRIBUTING.md.tmp youtube-dl youtube-dl.exe find . -name "*.pyc" -delete PREFIX ?= /usr/local @@ -73,11 +73,10 @@ supportedsites: README.txt: README.md pandoc -f markdown -t plain README.md -o README.txt -youtube-dl.1: youtube_dl/*.py youtube_dl/*/*.py - COLUMNS=65536 python youtube_dl/__main__.py --help | python devscripts/make_readme.py README.md > README-wide.md - python devscripts/prepare_manpage.py README-wide.md > youtube-dl.1.temp.md +youtube-dl.1: README.md + python devscripts/prepare_manpage.py README.md > youtube-dl.1.temp.md pandoc -s -f markdown -t man youtube-dl.1.temp.md -o youtube-dl.1 - rm -f youtube-dl.1.temp.md README-wide.md + rm -f youtube-dl.1.temp.md youtube-dl.bash-completion: youtube_dl/*.py youtube_dl/*/*.py devscripts/bash-completion.in python devscripts/bash-completion.py diff --git a/devscripts/prepare_manpage.py b/devscripts/prepare_manpage.py index cc7215257..06cea7e54 100644 --- a/devscripts/prepare_manpage.py +++ b/devscripts/prepare_manpage.py @@ -19,16 +19,19 @@ def filter_options(readme): else: in_options = False - if in_options and line.lstrip().startswith('-'): - option, description = re.split(r'\s{2,}', line.lstrip()) - split_option = option.split(' ') + if in_options: + if line.lstrip().startswith('-'): + option, description = re.split(r'\s{2,}', line.lstrip()) + split_option = option.split(' ') - if not split_option[-1].startswith('-'): # metavar - option = ' '.join(split_option[:-1] + ['*%s*' % split_option[-1]]) + if not split_option[-1].startswith('-'): # metavar + option = ' '.join(split_option[:-1] + ['*%s*' % split_option[-1]]) - # Pandoc's definition_lists. See http://pandoc.org/README.html - # for more information. - ret += '%s\n: %s\n\n' % (option, description) + # Pandoc's definition_lists. See http://pandoc.org/README.html + # for more information. + ret += '\n%s\n: %s\n' % (option, description) + else: + ret += line.lstrip() + '\n' else: ret += line + '\n' From c1668ca07d161c635fa5fea5c3db15e36a030b71 Mon Sep 17 00:00:00 2001 From: Yen Chi Hsuan Date: Thu, 1 Oct 2015 23:14:18 +0800 Subject: [PATCH 6/6] [doc] Using hardcoded README.md again --- Makefile | 5 ++--- devscripts/make_readme.py | 4 ++-- devscripts/prepare_manpage.py | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index d48485567..fdb1abb60 100644 --- a/Makefile +++ b/Makefile @@ -61,8 +61,7 @@ youtube-dl: youtube_dl/*.py youtube_dl/*/*.py chmod a+x youtube-dl README.md: youtube_dl/*.py youtube_dl/*/*.py - COLUMNS=80 python youtube_dl/__main__.py --help | python devscripts/make_readme.py README.md > README.new.md - mv -f README.new.md README.md + COLUMNS=80 python youtube_dl/__main__.py --help | python devscripts/make_readme.py CONTRIBUTING.md: README.md python devscripts/make_contributing.py README.md CONTRIBUTING.md @@ -74,7 +73,7 @@ README.txt: README.md pandoc -f markdown -t plain README.md -o README.txt youtube-dl.1: README.md - python devscripts/prepare_manpage.py README.md > youtube-dl.1.temp.md + python devscripts/prepare_manpage.py >youtube-dl.1.temp.md pandoc -s -f markdown -t man youtube-dl.1.temp.md -o youtube-dl.1 rm -f youtube-dl.1.temp.md diff --git a/devscripts/make_readme.py b/devscripts/make_readme.py index c9dd35aa1..8fbce0796 100755 --- a/devscripts/make_readme.py +++ b/devscripts/make_readme.py @@ -4,7 +4,7 @@ import io import sys import re -README_FILE = sys.argv[1] +README_FILE = 'README.md' helptext = sys.stdin.read() if isinstance(helptext, bytes): @@ -20,7 +20,7 @@ options = helptext[helptext.index(' General Options:') + 19:] options = re.sub(r'(?m)^ (\w.+)$', r'## \1', options) options = '# OPTIONS\n' + options + '\n' -with io.open(sys.stdout.fileno(), 'w', encoding='utf-8') as f: +with io.open(README_FILE, 'w', encoding='utf-8') as f: f.write(header) f.write(options) f.write(footer) diff --git a/devscripts/prepare_manpage.py b/devscripts/prepare_manpage.py index 06cea7e54..776e6556e 100644 --- a/devscripts/prepare_manpage.py +++ b/devscripts/prepare_manpage.py @@ -6,7 +6,7 @@ import sys import re ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -README_FILE = os.path.join(ROOT_DIR, sys.argv[1]) +README_FILE = os.path.join(ROOT_DIR, 'README.md') def filter_options(readme):