]> jfr.im git - yt-dlp.git/commitdiff
`--config-location -` to provide options interactively
authorpukkandan <redacted>
Tue, 24 May 2022 12:00:28 +0000 (17:30 +0530)
committerpukkandan <redacted>
Thu, 26 May 2022 23:02:54 +0000 (04:32 +0530)
README.md
yt_dlp/__init__.py
yt_dlp/options.py
yt_dlp/utils.py

index e71a150fd45eb7081ebee1f24b2eaccfe24e9f12..fbbd6f3abaf76e53d2bbb1e8f31edeff40d4d409 100644 (file)
--- a/README.md
+++ b/README.md
@@ -358,8 +358,9 @@ ## General Options:
                                     defined in the current file
     --config-locations PATH         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
+                                    containing directory ("-" for stdin). Can be
+                                    used multiple times and inside other
+                                    configuration files
     --flat-playlist                 Do not extract the videos of a playlist,
                                     only list them
     --no-flat-playlist              Extract the videos of a playlist
index 66fee95cddee1d2e4dce698e5c7aac44e12c02d9..12751b0092e027fdce9b7bb2d9b1b82b5ed413bc 100644 (file)
@@ -9,7 +9,7 @@
 import re
 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 .downloader import FileDownloader
 from .extractor import GenericIE, list_extractor_classes
@@ -42,6 +42,7 @@
     parse_duration,
     preferredencoding,
     read_batch_urls,
+    read_stdin,
     render_table,
     setproctitle,
     std_headers,
@@ -63,14 +64,9 @@ def get_urls(urls, batchfile, verbose):
     batch_urls = []
     if batchfile is not None:
         try:
-            if batchfile == '-':
-                write_string('Reading URLs from stdin - EOF (%s) to end:\n' % (
-                    'Ctrl+Z' if compat_os_name == 'nt' else 'Ctrl+D'))
-                batchfd = sys.stdin
-            else:
-                batchfd = open(
-                    expand_path(batchfile), encoding='utf-8', errors='ignore')
-            batch_urls = read_batch_urls(batchfd)
+            batch_urls = read_batch_urls(
+                read_stdin('URLs') if batchfile == '-'
+                else open(expand_path(batchfile), encoding='utf-8', errors='ignore'))
             if verbose:
                 write_string('[debug] Batch file urls: ' + repr(batch_urls) + '\n')
         except OSError:
index c0718e0073089e833cf05eec646aa4c3154b025e..65391410f12cc12a3c74bf4558a6415ebf8e4fd0 100644 (file)
@@ -366,8 +366,8 @@ def _alias_callback(option, opt_str, value, parser, opts, nargs):
         '--config-locations',
         dest='config_locations', metavar='PATH', action='append',
         help=(
-            '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'))
+            'Location of the main configuration file; either the path to the config or its containing directory '
+            '("-" for stdin). Can be used multiple times and inside other configuration files'))
     general.add_option(
         '--flat-playlist',
         action='store_const', dest='extract_flat', const='in_playlist', default=False,
index 2e3c51562ae294c2ebed6eb28b0204d49e3b4b45..6701492f22a4ddec27b4ae607508da611a8ee0fe 100644 (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))
 
 
+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:
     own_args = None
     parsed_args = None
@@ -5188,6 +5194,9 @@ def init(self, args=None, filename=None):
         self.parsed_args, self.filename = args, filename
 
         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))
             if os.path.isdir(location):
                 location = os.path.join(location, 'yt-dlp.conf')