]>
jfr.im git - yt-dlp.git/blob - devscripts/prepare_manpage.py
2 from __future__
import unicode_literals
9 ROOT_DIR
= os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
)))
10 README_FILE
= os
.path
.join(ROOT_DIR
, 'README.md')
12 PREFIX
= r
'''%yt-dlp(1)
16 youtube\-dl \- download videos from youtube.com or other video platforms
20 **yt-dlp** \[OPTIONS\] URL [URL...]
26 parser
= optparse
.OptionParser(usage
='%prog OUTFILE.md')
27 options
, args
= parser
.parse_args()
29 parser
.error('Expected an output filename')
33 with io
.open(README_FILE
, encoding
='utf-8') as f
:
36 readme
= re
.sub(r
'(?s)^.*?(?=# DESCRIPTION)', '', readme
)
37 readme
= re
.sub(r
'\s+yt-dlp \[OPTIONS\] URL \[URL\.\.\.\]', '', readme
)
38 readme
= PREFIX
+ readme
40 readme
= filter_options(readme
)
42 with io
.open(outfile
, 'w', encoding
='utf-8') as outf
:
46 def filter_options(readme
):
49 for line
in readme
.split('\n'):
50 if line
.startswith('# '):
51 if line
[2:].startswith('OPTIONS'):
57 if line
.lstrip().startswith('-'):
58 split
= re
.split(r
'\s{2,}', line
.lstrip())
59 # Description string may start with `-` as well. If there is
60 # only one piece then it's a description bit not an option.
62 option
, description
= split
63 split_option
= option
.split(' ')
65 if not split_option
[-1].startswith('-'): # metavar
66 option
= ' '.join(split_option
[:-1] + ['*%s*' % split_option
[-1]])
68 # Pandoc's definition_lists. See http://pandoc.org/README.html
69 # for more information.
70 ret
+= '\n%s\n: %s\n' % (option
, description
)
72 ret
+= line
.lstrip() + '\n'
79 if __name__
== '__main__':