diff --git a/moviepy/__init__.py b/moviepy/__init__.py index 2b9baa8d7..2d4d60c74 100644 --- a/moviepy/__init__.py +++ b/moviepy/__init__.py @@ -1,6 +1,7 @@ """Imports everything that you need from the MoviePy submodules so that every thing can be directly imported with ``from moviepy import *``. """ + from moviepy.audio import fx as afx from moviepy.audio.AudioClip import ( AudioArrayClip, diff --git a/moviepy/decorators.py b/moviepy/decorators.py index 9c7b9a211..3bdd13db3 100644 --- a/moviepy/decorators.py +++ b/moviepy/decorators.py @@ -78,22 +78,32 @@ def audio_video_effect(func, effect, clip, *args, **kwargs): return func(effect, clip, *args, **kwargs) -def preprocess_args(fun, varnames): - """Applies fun to variables in varnames before launching the function.""" +def preprocess_args(preprocess_func, varnames): + """Applies preprocess_func to variables in varnames before launching + the function. + """ - def wrapper(func, *args, **kwargs): - names = inspect.getfullargspec(func).args - new_args = [ - fun(arg) if (name in varnames) and (arg is not None) else arg - for (arg, name) in zip(args, names) - ] - new_kwargs = { - kwarg: fun(value) if kwarg in varnames else value - for (kwarg, value) in kwargs.items() - } - return func(*new_args, **new_kwargs) + def decor(func): + argnames = inspect.getfullargspec(func).args + + def wrapper(func, *args, **kwargs): + new_args = [ + ( + preprocess_func(arg) + if (name in varnames) and (arg is not None) + else arg + ) + for (arg, name) in zip(args, argnames) + ] + new_kwargs = { + kwarg: preprocess_func(value) if kwarg in varnames else value + for (kwarg, value) in kwargs.items() + } + return func(*new_args, **new_kwargs) - return decorator.decorator(wrapper) + return decorator.decorate(func, wrapper) + + return decor def convert_parameter_to_seconds(varnames): @@ -114,11 +124,11 @@ def add_mask_if_none(func, clip, *args, **kwargs): return func(clip, *args, **kwargs) -@decorator.decorator -def use_clip_fps_by_default(func, clip, *args, **kwargs): +def use_clip_fps_by_default(func): """Will use ``clip.fps`` if no ``fps=...`` is provided in **kwargs**.""" + argnames = inspect.getfullargspec(func).args[1:] - def find_fps(fps): + def find_fps(clip, fps): if fps is not None: return fps elif getattr(clip, "fps", None): @@ -130,14 +140,16 @@ def find_fps(fps): " the clip's fps with `clip.fps=24`" % func.__name__ ) - names = inspect.getfullargspec(func).args[1:] + def wrapper(func, clip, *args, **kwargs): + new_args = [ + find_fps(clip, arg) if name == "fps" else arg + for (arg, name) in zip(args, argnames) + ] + new_kwargs = { + kwarg: find_fps(clip, kwarg) if kwarg == "fps" else value + for (kwarg, value) in kwargs.items() + } - new_args = [ - find_fps(arg) if (name == "fps") else arg for (arg, name) in zip(args, names) - ] - new_kwargs = { - kwarg: find_fps(value) if kwarg == "fps" else value - for (kwarg, value) in kwargs.items() - } + return func(clip, *new_args, **new_kwargs) - return func(clip, *new_args, **new_kwargs) + return decorator.decorate(func, wrapper) diff --git a/moviepy/video/io/ffmpeg_reader.py b/moviepy/video/io/ffmpeg_reader.py index ea552f200..640263fcf 100644 --- a/moviepy/video/io/ffmpeg_reader.py +++ b/moviepy/video/io/ffmpeg_reader.py @@ -480,12 +480,12 @@ def parse(self): # for default streams, set their numbers globally, so it's # easy to get without iterating all if self._current_stream["default"]: - self.result[ - f"default_{stream_type_lower}_input_number" - ] = input_number - self.result[ - f"default_{stream_type_lower}_stream_number" - ] = stream_number + self.result[f"default_{stream_type_lower}_input_number"] = ( + input_number + ) + self.result[f"default_{stream_type_lower}_stream_number"] = ( + stream_number + ) # exit chapter if self._current_chapter: