]> jfr.im git - yt-dlp.git/blame - devscripts/prepare_manpage.py
Merge pull request #6963 from remitamine/appledaily
[yt-dlp.git] / devscripts / prepare_manpage.py
CommitLineData
dcddc10a 1from __future__ import unicode_literals
1800eeef
PH
2
3import io
4import os.path
5import sys
6import re
7
8ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
9README_FILE = os.path.join(ROOT_DIR, 'README.md')
10
bad84757
YCH
11
12def filter_options(readme):
13 ret = ''
14 in_options = False
15 for line in readme.split('\n'):
16 if line.startswith('# '):
17 if line[2:].startswith('OPTIONS'):
18 in_options = True
19 else:
20 in_options = False
21
22 if in_options:
23 if line.lstrip().startswith('-'):
24 option, description = re.split(r'\s{2,}', line.lstrip())
25 split_option = option.split(' ')
26
27 if not split_option[-1].startswith('-'): # metavar
28 option = ' '.join(split_option[:-1] + ['*%s*' % split_option[-1]])
29
30 # Pandoc's definition_lists. See http://pandoc.org/README.html
31 # for more information.
32 ret += '\n%s\n: %s\n' % (option, description)
33 else:
34 ret += line.lstrip() + '\n'
35 else:
36 ret += line + '\n'
37
38 return ret
39
1800eeef
PH
40with io.open(README_FILE, encoding='utf-8') as f:
41 readme = f.read()
42
b50e3bc6
PH
43PREFIX = '''%YOUTUBE-DL(1)
44
45# NAME
46
47youtube\-dl \- download videos from youtube.com or other video platforms
48
49# SYNOPSIS
50
51**youtube-dl** \[OPTIONS\] URL [URL...]
52
53'''
54readme = re.sub(r'(?s)^.*?(?=# DESCRIPTION)', '', readme)
55readme = re.sub(r'\s+youtube-dl \[OPTIONS\] URL \[URL\.\.\.\]', '', readme)
1800eeef
PH
56readme = PREFIX + readme
57
bad84757
YCH
58readme = filter_options(readme)
59
1800eeef
PH
60if sys.version_info < (3, 0):
61 print(readme.encode('utf-8'))
62else:
63 print(readme)