diff --git a/src/ytdl_sub/entries/script/function_scripts.py b/src/ytdl_sub/entries/script/function_scripts.py index 8d0702c1..696bef35 100644 --- a/src/ytdl_sub/entries/script/function_scripts.py +++ b/src/ytdl_sub/entries/script/function_scripts.py @@ -50,19 +50,20 @@ CUSTOM_FUNCTION_SCRIPTS: Dict[str, str] = { %regex_capture_groups ), %array_size($2), - %eq + %lte ), %and ), - %array_first( + %array_overlay( %array_apply_fixed( %array($1), %string($0), %regex_search ), - %array_extend( ['dummy'], $2 ) + %array_extend( ['using all defaults'], $2 ), + True ), - 'Number of regex capture groups must be the same for every input regex' + 'Number of regex capture groups must be less than or equal to the number of defaults' ) }""", } diff --git a/src/ytdl_sub/script/functions/array_functions.py b/src/ytdl_sub/script/functions/array_functions.py index 1e6a6ca8..9dbbe4cf 100644 --- a/src/ytdl_sub/script/functions/array_functions.py +++ b/src/ytdl_sub/script/functions/array_functions.py @@ -50,6 +50,25 @@ class ArrayFunctions: return Array(output) + @staticmethod + def array_overlay( + array: Array, overlap: Array, only_missing: Optional[Boolean] = None + ) -> Array: + """ + Overlaps ``overlap`` onto ``array``. Can optionally only overlay missing indices. + """ + output: List[Resolvable] = [] + output.extend(array.value) + + overlap_only_missing = only_missing and only_missing.value + + for idx, overlap_value in enumerate(overlap.value): + if overlap_only_missing and idx < len(array.value): + continue + output.insert(idx, overlap_value) + + return Array(output) + @staticmethod def array_at(array: Array, idx: Integer) -> AnyArgument: """