Skip to content

Commit

Permalink
make flake8 happier
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin Zulkower committed Nov 20, 2024
1 parent ee004b1 commit 0db382d
Show file tree
Hide file tree
Showing 39 changed files with 53 additions and 25 deletions.
7 changes: 5 additions & 2 deletions moviepy/Effect.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Defines the base class for all effects in MoviePy."""

import copy as _copy
from abc import ABCMeta, abstractmethod

from moviepy.Clip import Clip


class Effect(metaclass=ABCMeta):
"""Base abastract class for all effects in MoviePy.
"""Base abstract class for all effects in MoviePy.
Any new effect have to extend this base class.
"""

Expand All @@ -22,7 +24,8 @@ def copy(self):
By using copy, we ensure we can use the same effect object multiple times while
maintaining the same behavior/result.
In a way, copy make the effect himself beeing kind of indempotent."""
In a way, copy makes the effect himself being kind of idempotent.
"""
return _copy.copy(self)

@abstractmethod
Expand Down
25 changes: 7 additions & 18 deletions moviepy/video/VideoClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,7 @@ def write_gif(
@convert_masks_to_RGB
@convert_parameter_to_seconds(["t"])
def show(self, t=0, with_mask=True):
"""
Splashes the frame of clip corresponding to time ``t``.
"""Splashes the frame of clip corresponding to time ``t``.
Parameters
----------
Expand Down Expand Up @@ -565,9 +564,9 @@ def show(self, t=0, with_mask=True):
def preview(
self, fps=15, audio=True, audio_fps=22050, audio_buffersize=3000, audio_nbytes=2
):
"""
Displays the clip in a window, at the given frames per second (of movie)
rate. It will avoid that the clip be played faster than normal, but it
"""Displays the clip in a window, at the given frames per second.
It will avoid that the clip be played faster than normal, but it
cannot avoid the clip to be played slower than normal if the computations
are complex. In this case, try reducing the ``fps``.
Expand All @@ -594,11 +593,9 @@ def preview(
--------
>>> from moviepy import *
>>>
>>> clip = VideoFileClip("media/chaplin.mp4")
>>> clip.preview(fps=10, audio=False)
"""

audio = audio and (self.audio is not None)
audio_flag = None
video_flag = None
Expand Down Expand Up @@ -690,7 +687,6 @@ def fill_array(self, pre_array, shape=(0, 0)):
shape (tuple)
The desired shape of the resulting array.
"""
pre_shape = pre_array.shape
dx = shape[0] - pre_shape[0]
Expand Down Expand Up @@ -1463,9 +1459,7 @@ def __init__(
def break_text(
width, text, font, font_size, stroke_width, align, spacing
) -> List[str]:
"""
Break text to never overflow a width
"""
"""Break text to never overflow a width"""
img = Image.new("RGB", (1, 1))
font_pil = ImageFont.truetype(font, font_size)
draw = ImageDraw.Draw(img)
Expand Down Expand Up @@ -1506,10 +1500,7 @@ def find_text_size(
max_width=None,
allow_break=False,
) -> tuple[int, int]:
"""
Find dimensions a text will occupy
return a tuple (width, height)
"""
"""Find dimensions a text will occupy, return a tuple (width, height)"""
img = Image.new("RGB", (1, 1))
font_pil = ImageFont.truetype(font, font_size)
draw = ImageDraw.Draw(img)
Expand Down Expand Up @@ -1559,9 +1550,7 @@ def find_optimum_font_size(
height=None,
allow_break=False,
):
"""
Find the best font size to fit as optimally as possible
"""
"""Find the best font size to fit as optimally as possible"""
max_font_size = width
min_font_size = 1

Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/AccelDecel.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def f2(t):
return old_duration * _f((t / new_duration) ** soonness)

def apply(self, clip):
"""Apply the effect to the clip."""
if self.new_duration is None:
self.new_duration = clip.duration

Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/BlackAndWhite.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class BlackAndWhite(Effect):
preserve_luminosity: bool = True

def apply(self, clip):
"""Apply the effect to the clip."""
if self.RGB is None:
self.RGB = [1, 1, 1]

Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/Blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Blink(Effect):
duration_off: float

def apply(self, clip):
"""Apply the effect to the clip."""
if clip.mask is None:
clip = clip.with_add_mask()

Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/Crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Crop(Effect):
"""

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
if self.width and self.x1 is not None:
self.x2 = self.x1 + self.width
elif self.width and self.x2 is not None:
Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/CrossFadeIn.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class CrossFadeIn(Effect):
duration: float

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
if clip.duration is None:
raise ValueError("Attribute 'duration' not set")

Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/CrossFadeOut.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class CrossFadeOut(Effect):
duration: float

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
if clip.duration is None:
raise ValueError("Attribute 'duration' not set")

Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/EvenSize.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class EvenSize(Effect):
"""Crops the clip to make dimensions even."""

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
w, h = clip.size
w_even = w % 2 == 0
h_even = h % 2 == 0
Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/FadeIn.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class FadeIn(Effect):
initial_color: list = None

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
if self.initial_color is None:
self.initial_color = 0 if clip.is_mask else [0, 0, 0]

Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/FadeOut.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class FadeOut(Effect):
final_color: list = None

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
if clip.duration is None:
raise ValueError("Attribute 'duration' not set")

Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/Freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Freeze(Effect):
padding_end: float = 0

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
if clip.duration is None:
raise ValueError("Attribute 'duration' not set")

Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/FreezeRegion.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class FreezeRegion(Effect):
mask: Clip = None

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
if self.region is not None:
x1, y1, _x2, _y2 = self.region
freeze = (
Expand Down
2 changes: 2 additions & 0 deletions moviepy/video/fx/GammaCorrection.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class GammaCorrection(Effect):
gamma: float

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""

def filter(im):
corrected = 255 * (1.0 * im / 255) ** self.gamma
return corrected.astype("uint8")
Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/HeadBlur.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class HeadBlur(Effect):
intensity: float = None

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
if self.intensity is None:
self.intensity = int(2 * self.radius / 3)

Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/InvertColors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ class InvertColors(Effect):
"""

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
maxi = 1.0 if clip.is_mask else 255
return clip.image_transform(lambda f: maxi - f)
1 change: 1 addition & 0 deletions moviepy/video/fx/Loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Loop(Effect):
duration: float = None

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
if clip.duration is None:
raise ValueError("Attribute 'duration' not set")

Expand Down
2 changes: 2 additions & 0 deletions moviepy/video/fx/LumContrast.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class LumContrast(Effect):
contrast_threshold: float = 127

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""

def image_filter(im):
im = 1.0 * im # float conversion
corrected = (
Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/MakeLoopable.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class MakeLoopable(Effect):
overlap_duration: float

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
clip2 = clip.with_effects([CrossFadeIn(self.overlap_duration)]).with_start(
clip.duration - self.overlap_duration
)
Expand Down
2 changes: 2 additions & 0 deletions moviepy/video/fx/Margin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Margin(Effect):
opacity: float = 1.0

def add_margin(self, clip: Clip):
"""Add margins to the clip."""
if (self.opacity != 1.0) and (clip.mask is None) and not (clip.is_mask):
clip = clip.with_add_mask()

Expand Down Expand Up @@ -79,6 +80,7 @@ def filter(get_frame, t):
return clip.transform(filter)

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
# We apply once on clip and once on mask if we have one
clip = self.add_margin(clip=clip)

Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/MaskColor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class MaskColor(Effect):
stiffness: float = 1

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
color = np.array(self.color)

def hill(x):
Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/MasksAnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class MasksAnd(Effect):
other_clip: Union[Clip, np.ndarray]

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
# to ensure that 'and' of two ImageClips will be an ImageClip
if isinstance(self.other_clip, ImageClip):
self.other_clip = self.other_clip.img
Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/MasksOr.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class MasksOr(Effect):
other_clip: Union[Clip, np.ndarray]

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
# to ensure that 'or' of two ImageClips will be an ImageClip
if isinstance(self.other_clip, ImageClip):
self.other_clip = self.other_clip.img
Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/MirrorX.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ class MirrorX(Effect):
apply_to: Union[List, str] = "mask"

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
return clip.image_transform(lambda img: img[:, ::-1], apply_to=self.apply_to)
1 change: 1 addition & 0 deletions moviepy/video/fx/MirrorY.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ class MirrorY(Effect):
apply_to: Union[List, str] = "mask"

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
return clip.image_transform(lambda img: img[::-1], apply_to=self.apply_to)
1 change: 1 addition & 0 deletions moviepy/video/fx/MultiplyColor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class MultiplyColor(Effect):
factor: float

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
return clip.image_transform(
lambda frame: np.minimum(255, (self.factor * frame)).astype("uint8")
)
1 change: 1 addition & 0 deletions moviepy/video/fx/MultiplySpeed.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class MultiplySpeed(Effect):
final_duration: float = None

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
if self.final_duration:
self.factor = 1.0 * clip.duration / self.final_duration

Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/Painting.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def to_painting(self, np_image, saturation=1.4, black=0.006):
return painting

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
return clip.image_transform(
lambda im: self.to_painting(im, self.saturation, self.black)
)
1 change: 1 addition & 0 deletions moviepy/video/fx/Resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def resizer(self, pic, new_size):
return np.array(resized_pil)

def apply(self, clip):
"""Apply the effect to the clip."""
w, h = clip.size

if self.new_size is not None:
Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/Rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Rotate(Effect):
bg_color: tuple = None

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
try:
resample = {
"bilinear": Image.BILINEAR,
Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/Scroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(
self.apply_to = apply_to

def apply(self, clip):
"""Apply the effect to the clip."""
if self.h is None:
self.h = clip.h

Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/SlideIn.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class SlideIn(Effect):
side: str

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
w, h = clip.size
pos_dict = {
"left": lambda t: (min(0, w * (t / self.duration - 1)), "center"),
Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/SlideOut.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class SlideOut(Effect):
side: str

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
if clip.duration is None:
raise ValueError("Attribute 'duration' not set")

Expand Down
2 changes: 2 additions & 0 deletions moviepy/video/fx/SuperSample.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class SuperSample(Effect):
n_frames: int

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""

def filter(get_frame, t):
timings = np.linspace(t - self.d, t + self.d, self.n_frames)
frame_average = np.mean(
Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/TimeMirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class TimeMirror(Effect):
"""

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
if clip.duration is None:
raise ValueError("Attribute 'duration' not set")

Expand Down
1 change: 1 addition & 0 deletions moviepy/video/fx/TimeSymmetrize.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class TimeSymmetrize(Effect):
"""

def apply(self, clip: Clip) -> Clip:
"""Apply the effect to the clip."""
if clip.duration is None:
raise ValueError("Attribute 'duration' not set")

Expand Down
1 change: 0 additions & 1 deletion moviepy/video/io/ffplay_previewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ def ffplay_preview_video(
A thread event that video will set after first frame has been shown. If not
provided, we simply ignore
"""

with FFPLAY_VideoPreviewer(clip.size, fps, pixel_format) as previewer:
first_frame = True
for t, frame in clip.iter_frames(with_times=True, fps=fps, dtype="uint8"):
Expand Down
4 changes: 1 addition & 3 deletions moviepy/video/io/gif_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
@requires_duration
@use_clip_fps_by_default
def write_gif_with_imageio(clip, filename, fps=None, loop=0, logger="bar"):
"""
Writes the gif with the Python library ImageIO (calls FreeImage).
"""
"""Writes the gif with the Python library ImageIO (calls FreeImage)."""
logger = proglog.default_bar_logger(logger)

with iio.imopen(filename, "w", plugin="pillow") as writer:
Expand Down
Loading

0 comments on commit 0db382d

Please sign in to comment.