]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/utils.py
Split video by chapters (#158)
[yt-dlp.git] / yt_dlp / utils.py
index 0dbb8546737c4a56dec382f33c23456f4e8d8637..a913b98149e22dfeaa5e949ed15ad68c0a6020c5 100644 (file)
@@ -4182,8 +4182,10 @@ def q(qid):
 
 DEFAULT_OUTTMPL = {
     'default': '%(title)s [%(id)s].%(ext)s',
+    'chapter': '%(title)s - %(section_number)03d %(section_title)s [%(id)s].%(ext)s',
 }
 OUTTMPL_TYPES = {
+    'chapter': None,
     'subtitle': None,
     'thumbnail': None,
     'description': 'description',
@@ -4692,36 +4694,26 @@ def cli_valueless_option(params, command_option, param, expected_value=True):
     return [command_option] if param == expected_value else []
 
 
-def cli_configuration_args(argdict, key, default=[], exe=None, use_default_arg=True):
-    # use_default_arg can be True, False, or 'no_compat'
+def cli_configuration_args(argdict, keys, default=[], use_compat=True):
     if isinstance(argdict, (list, tuple)):  # for backward compatibility
-        if use_default_arg is True:
+        if use_compat:
             return argdict
         else:
             argdict = None
-
     if argdict is None:
         return default
     assert isinstance(argdict, dict)
 
-    key = key.lower()
-    args = exe_args = None
-    if exe is not None:
-        assert isinstance(exe, compat_str)
-        exe = exe.lower()
-        args = argdict.get('%s+%s' % (key, exe))
-        if args is None:
-            exe_args = argdict.get(exe)
-
-    if args is None:
-        args = argdict.get(key) if key != exe else None
-    if args is None and exe_args is None:
-        args = argdict.get('default', default) if use_default_arg else default
-
-    args, exe_args = args or [], exe_args or []
-    assert isinstance(args, (list, tuple))
-    assert isinstance(exe_args, (list, tuple))
-    return args + exe_args
+    assert isinstance(keys, (list, tuple))
+    for key_list in keys:
+        if isinstance(key_list, compat_str):
+            key_list = (key_list,)
+        arg_list = list(filter(
+            lambda x: x is not None,
+            [argdict.get(key.lower()) for key in key_list]))
+        if arg_list:
+            return [arg for args in arg_list for arg in args]
+    return default
 
 
 class ISO639Utils(object):
@@ -5945,9 +5937,13 @@ def make_dir(path, to_screen=None):
 
 
 def get_executable_path():
-    path = os.path.dirname(sys.argv[0])
-    if os.path.basename(sys.argv[0]) == '__main__':  # Running from source
-        path = os.path.join(path, '..')
+    from zipimport import zipimporter
+    if hasattr(sys, 'frozen'):  # Running from PyInstaller
+        path = os.path.dirname(sys.executable)
+    elif isinstance(globals().get('__loader__'), zipimporter):  # Running from ZIP
+        path = os.path.join(os.path.dirname(__file__), '../..')
+    else:
+        path = os.path.join(os.path.dirname(__file__), '..')
     return os.path.abspath(path)