7 with
open(fname
, encoding
='utf-8') as f
:
11 def write_file(fname
, content
, mode
='w'):
12 with
open(fname
, mode
, encoding
='utf-8') as f
:
13 return f
.write(content
)
16 def read_version(fname
='yt_dlp/version.py', varname
='__version__'):
17 """Get the version without importing the package"""
19 exec(compile(read_file(fname
), fname
, 'exec'), items
)
23 def get_filename_args(has_infile
=False, default_outfile
=None):
24 parser
= argparse
.ArgumentParser()
26 parser
.add_argument('infile', help='Input file')
27 kwargs
= {'nargs': '?', 'default': default_outfile
} if default_outfile
else {}
28 parser
.add_argument('outfile', **kwargs
, help='Output file')
30 opts
= parser
.parse_args()
32 return opts
.infile
, opts
.outfile
36 def compose_functions(*functions
):
37 return lambda x
: functools
.reduce(lambda y
, f
: f(y
), functions
, x
)
40 def run_process(*args
, **kwargs
):
41 kwargs
.setdefault('text', True)
42 kwargs
.setdefault('check', True)
43 kwargs
.setdefault('capture_output', True)
45 kwargs
.setdefault('encoding', 'utf-8')
46 kwargs
.setdefault('errors', 'replace')
47 return subprocess
.run(args
, **kwargs
)