--config-location - to provide options interactively

This commit is contained in:
pukkandan 2022-05-24 17:30:28 +05:30
parent d2ff2c91bb
commit 6b9e832db7
No known key found for this signature in database
GPG Key ID: 7EEE9E1E817D0A39
4 changed files with 19 additions and 13 deletions

View File

@ -358,8 +358,9 @@ ## General Options:
defined in the current file defined in the current file
--config-locations PATH Location of the main configuration file; --config-locations PATH Location of the main configuration file;
either the path to the config or its either the path to the config or its
containing directory. Can be used multiple containing directory ("-" for stdin). Can be
times and inside other configuration files used multiple times and inside other
configuration files
--flat-playlist Do not extract the videos of a playlist, --flat-playlist Do not extract the videos of a playlist,
only list them only list them
--no-flat-playlist Extract the videos of a playlist --no-flat-playlist Extract the videos of a playlist

View File

@ -9,7 +9,7 @@
import re import re
import sys import sys
from .compat import compat_getpass, compat_os_name, compat_shlex_quote from .compat import compat_getpass, compat_shlex_quote
from .cookies import SUPPORTED_BROWSERS, SUPPORTED_KEYRINGS from .cookies import SUPPORTED_BROWSERS, SUPPORTED_KEYRINGS
from .downloader import FileDownloader from .downloader import FileDownloader
from .extractor import GenericIE, list_extractor_classes from .extractor import GenericIE, list_extractor_classes
@ -42,6 +42,7 @@
parse_duration, parse_duration,
preferredencoding, preferredencoding,
read_batch_urls, read_batch_urls,
read_stdin,
render_table, render_table,
setproctitle, setproctitle,
std_headers, std_headers,
@ -63,14 +64,9 @@ def get_urls(urls, batchfile, verbose):
batch_urls = [] batch_urls = []
if batchfile is not None: if batchfile is not None:
try: try:
if batchfile == '-': batch_urls = read_batch_urls(
write_string('Reading URLs from stdin - EOF (%s) to end:\n' % ( read_stdin('URLs') if batchfile == '-'
'Ctrl+Z' if compat_os_name == 'nt' else 'Ctrl+D')) else open(expand_path(batchfile), encoding='utf-8', errors='ignore'))
batchfd = sys.stdin
else:
batchfd = open(
expand_path(batchfile), encoding='utf-8', errors='ignore')
batch_urls = read_batch_urls(batchfd)
if verbose: if verbose:
write_string('[debug] Batch file urls: ' + repr(batch_urls) + '\n') write_string('[debug] Batch file urls: ' + repr(batch_urls) + '\n')
except OSError: except OSError:

View File

@ -366,8 +366,8 @@ def _alias_callback(option, opt_str, value, parser, opts, nargs):
'--config-locations', '--config-locations',
dest='config_locations', metavar='PATH', action='append', dest='config_locations', metavar='PATH', action='append',
help=( help=(
'Location of the main configuration file; either the path to the config or its containing directory. ' 'Location of the main configuration file; either the path to the config or its containing directory '
'Can be used multiple times and inside other configuration files')) '("-" for stdin). Can be used multiple times and inside other configuration files'))
general.add_option( general.add_option(
'--flat-playlist', '--flat-playlist',
action='store_const', dest='extract_flat', const='in_playlist', default=False, action='store_const', dest='extract_flat', const='in_playlist', default=False,

View File

@ -5163,6 +5163,12 @@ def parse_http_range(range):
return int(crg.group(1)), int_or_none(crg.group(2)), int_or_none(crg.group(3)) return int(crg.group(1)), int_or_none(crg.group(2)), int_or_none(crg.group(3))
def read_stdin(what):
eof = 'Ctrl+Z' if compat_os_name == 'nt' else 'Ctrl+D'
write_string(f'Reading {what} from STDIN - EOF ({eof}) to end:\n')
return sys.stdin
class Config: class Config:
own_args = None own_args = None
parsed_args = None parsed_args = None
@ -5188,6 +5194,9 @@ def init(self, args=None, filename=None):
self.parsed_args, self.filename = args, filename self.parsed_args, self.filename = args, filename
for location in opts.config_locations or []: for location in opts.config_locations or []:
if location == '-':
self.append_config(shlex.split(read_stdin('options'), comments=True), label='stdin')
continue
location = os.path.join(directory, expand_path(location)) location = os.path.join(directory, expand_path(location))
if os.path.isdir(location): if os.path.isdir(location):
location = os.path.join(location, 'yt-dlp.conf') location = os.path.join(location, 'yt-dlp.conf')