Skip to content

Commit

Permalink
makes flake8 happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin Zulkower committed Nov 20, 2024
1 parent 82a5b34 commit 50e7e46
Show file tree
Hide file tree
Showing 20 changed files with 81 additions and 80 deletions.
13 changes: 6 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import os
import sys

import pydata_sphinx_theme
from pygments.styles import get_all_styles


# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down Expand Up @@ -116,15 +113,17 @@
"name": "GitHub",
# URL where the link will redirect
"url": "https://github.com/Zulko/moviepy/", # required
# Icon class (if "type": "fontawesome"), or path to local image (if "type": "local")
# Icon class (if "type": "fontawesome"), or path to local image (if
# "type": "local")
"icon": "fa-brands fa-square-github",
# The type of image to be used (see below for details)
"type": "fontawesome",
}
],
"announcement": '<p>MoviePy v2.0 have introduced breaking changes, see <a href="{}">"Updating from v1.X to v2.X"</a> for more info.</p>'.format(
v2_page
),
"announcement": f"""
<p>MoviePy v2.0 have introduced breaking changes,
see <a href="{v2_page}">Updating from v1.X to v2.X</a> for more info.</p>
""",
}

html_context = {
Expand Down
4 changes: 2 additions & 2 deletions moviepy/Clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ def with_cutout(self, start_time, end_time):
return new_clip

def with_multiply_speed(self, factor: float = None, final_duration: float = None):
"""Returns a clip playing the current clip but at a speed multiplied by ``factor``.
For info on the parameters, please see ``vfx.MultiplySpeed``
"""Returns a clip playing the current clip but at a speed multiplied
by ``factor``. For info on the parameters, please see ``vfx.MultiplySpeed``.
"""
from moviepy.video.fx.MultiplySpeed import MultiplySpeed

Expand Down
6 changes: 4 additions & 2 deletions moviepy/audio/fx/MultiplyStereoVolume.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ class MultiplyStereoVolume(Effect):
>>> from moviepy import AudioFileClip
>>> music = AudioFileClip('music.ogg')
>>> audio_r = music.with_effects([afx.MultiplyStereoVolume(left=0, right=1)]) # mute left channel/s
>>> audio_h = music.with_effects([afx.MultiplyStereoVolume(left=0.5, right=0.5)]) # half audio
>>> # mutes left channel
>>> audio_r = music.with_effects([afx.MultiplyStereoVolume(left=0, right=1)])
>>> # halves audio volume
>>> audio_h = music.with_effects([afx.MultiplyStereoVolume(left=0.5, right=0.5)])
"""

left: float = 1
Expand Down
14 changes: 8 additions & 6 deletions moviepy/audio/fx/MultiplyVolume.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ class MultiplyVolume(Effect):
>>> from moviepy import AudioFileClip
>>>
>>> music = AudioFileClip('music.ogg')
>>> doubled_audio_clip = clip.with_effects([afx.MultiplyVolume(2)]) # doubles audio volume
>>> half_audio_clip = clip.with_effects([afx.MultiplyVolume(0.5)]) # half audio
>>>
>>> # silenced clip during one second at third
>>> silenced_clip = clip.with_effects([afx.MultiplyVolume(0, start_time=2, end_time=3)])
>>> music = AudioFileClip("music.ogg")
>>> # doubles audio volume
>>> doubled_audio_clip = music.with_effects([afx.MultiplyVolume(2)])
>>> # halves audio volume
>>> half_audio_clip = music.with_effects([afx.MultiplyVolume(0.5)])
>>> # silences clip during one second at third
>>> effect = afx.MultiplyVolume(0, start_time=2, end_time=3)
>>> silenced_clip = clip.with_effects([effect])
"""

factor: float
Expand Down
24 changes: 15 additions & 9 deletions moviepy/audio/io/readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ def initialize(self, start_time=0):

def skip_chunk(self, chunksize):
"""
This method skips a chunk of audio data by reading and discarding the specified number of frames from the audio stream.
The audio stream is read from the `proc` stdout. After skipping the chunk, the `pos` attribute is updated accordingly.
This method skips a chunk of audio data by reading and discarding
the specified number of frames from the audio stream. The audio
stream is read from the `proc` stdout. After skipping the chunk, the
`pos` attribute is updated accordingly.
Parameters
-----------
Expand All @@ -140,10 +142,13 @@ def read_chunk(self, chunksize):
"""
Reads a chunk of audio data from the audio stream.
This method reads a chunk of audio data from the audio stream. The specified number of frames, given by `chunksize`,
is read from the `proc` stdout. The audio data is returned as a NumPy array, where each row corresponds to a frame and
each column corresponds to a channel. If there is not enough audio left to read, the remaining portion is padded with
zeros, ensuring that the returned array has the desired length. The `pos` attribute is updated accordingly.
This method reads a chunk of audio data from the audio stream. The
specified number of frames, given by `chunksize`, is read from the
`proc` stdout. The audio data is returned as a NumPy array, where
each row corresponds to a frame and each column corresponds to a
channel. If there is not enough audio left to read, the remaining
portion is padded with zeros, ensuring that the returned array has
the desired length. The `pos` attribute is updated accordingly.
Parameters:
------------
Expand Down Expand Up @@ -193,9 +198,10 @@ def get_frame(self, tt):
Parameters
-----------
tt (float or numpy.ndarray): The timestamp(s) at which to retrieve the audio frame(s).
If `tt` is a single float value, the frame corresponding to that timestamp is returned.
If `tt` is a NumPy array of timestamps, an array of frames corresponding to each timestamp is returned.
tt (float or numpy.ndarray): The timestamp(s) at which to retrieve the
audio frame(s). If `tt` is a single float value, the frame corresponding
to that timestamp is returned. If `tt` is a NumPy array of timestamps,
an array of frames corresponding to each timestamp is returned.
"""
if isinstance(tt, np.ndarray):
# lazy implementation, but should not cause problems in
Expand Down
4 changes: 0 additions & 4 deletions moviepy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@

from moviepy.tools import cross_platform_popen_params


if os.name == "nt":
import winreg as wr

try:
from dotenv import find_dotenv, load_dotenv

Expand Down
4 changes: 2 additions & 2 deletions moviepy/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ def no_display_available() -> bool:
"""
system = platform.system()
if system in ["Linux", "FreeBSD", "NetBSD", "OpenBSD", "SunOS", "AIX"]:
if not "DISPLAY" in os.environ and not "WAYLAND_DISPLAY" in os.environ:
if ("DISPLAY" not in os.environ) and ("WAYLAND_DISPLAY" not in os.environ):
return True

if "CYGWIN_NT" in system:
if not "DISPLAY" in os.environ and not "WAYLAND_DISPLAY" in os.environ:
if ("DISPLAY" not in os.environ) and ("WAYLAND_DISPLAY" not in os.environ):
return True

return False
57 changes: 30 additions & 27 deletions moviepy/video/VideoClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import os
import threading
from numbers import Real
from typing import TYPE_CHECKING, List, Union
from typing import TYPE_CHECKING, List

import numpy as np
import proglog
from imageio.v2 import imread as imread_v2
from imageio.v3 import imread, imwrite
from imageio.v3 import imwrite
from PIL import Image, ImageDraw, ImageFont

from moviepy.video.io.ffplay_previewer import ffplay_preview_video
Expand All @@ -22,7 +22,6 @@
if TYPE_CHECKING:
from moviepy.Effect import Effect

from moviepy.audio.fx.MultiplyVolume import MultiplyVolume
from moviepy.Clip import Clip
from moviepy.decorators import (
add_mask_if_none,
Expand All @@ -37,7 +36,6 @@
)
from moviepy.tools import extensions_dict, find_extension
from moviepy.video.fx.Crop import Crop
from moviepy.video.fx.MultiplySpeed import MultiplySpeed
from moviepy.video.fx.Resize import Resize
from moviepy.video.fx.Rotate import Rotate
from moviepy.video.io.ffmpeg_writer import ffmpeg_write_video
Expand Down Expand Up @@ -552,10 +550,10 @@ def show(self, t=0, with_mask=True):
# it broke compositevideoclip and it does nothing on normal clip with alpha

# if with_mask and (self.mask is not None):
# # Hate it, but cannot figure a better way with python awful circular dependency
# from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip

# clip = CompositeVideoClip([self.with_position((0, 0))])
# # Hate it, but cannot figure a better way with python awful circular
# # dependency
# from mpy.video.compositing.CompositeVideoClip import CompositeVideoClip
# clip = CompositeVideoClip([self.with_position((0, 0))])

frame = clip.get_frame(t)
pil_img = Image.fromarray(frame.astype("uint8"))
Expand Down Expand Up @@ -677,9 +675,11 @@ def image_transform(self, image_func, apply_to=None):
def fill_array(self, pre_array, shape=(0, 0)):
"""Fills an array to match the specified shape.
If the `pre_array` is smaller than the desired shape, the missing rows or columns are added with ones to the bottom or right,
respectively, until the shape matches. If the `pre_array` is larger than the desired shape, the excess rows or columns are cropped
from the bottom or right, respectively, until the shape matches.
If the `pre_array` is smaller than the desired shape, the missing rows
or columns are added with ones to the bottom or right, respectively,
until the shape matches. If the `pre_array` is larger than the desired
shape, the excess rows or columns are cropped from the bottom or right,
respectively, until the shape matches.
The resulting array with the filled shape is returned.
Expand Down Expand Up @@ -1387,10 +1387,11 @@ class TextClip(ImageClip):
it will then be auto-determined.
margin
Margin to be added arround the text as a tuple of two (symmetrical) or four (asymmetrical).
Either ``(horizontal, vertical)`` or ``(left, top, right, bottom)``.
By default no margin (None, None).
This is especially usefull for auto-compute size to give the text some extra room.
Margin to be added arround the text as a tuple of two (symmetrical) or
four (asymmetrical). Either ``(horizontal, vertical)`` or
``(left, top, right, bottom)``. By default no margin (None, None).
This is especially usefull for auto-compute size to give the text some
extra room.
bg_color
Color of the background. Default to None for no background. Can be
Expand Down Expand Up @@ -1703,19 +1704,19 @@ def find_optimum_font_size(

else:
raise ValueError("Method must be either `caption` or `label`.")

# Compute the margin and apply it
if len(margin) == 2 :
if len(margin) == 2:
left_margin = right_margin = int(margin[0] or 0)
top_margin = bottom_margin = int(margin[1] or 0)
elif len(margin) == 4 :
elif len(margin) == 4:
left_margin = int(margin[0] or 0)
top_margin = int(margin[1] or 0)
right_margin = int(margin[2] or 0)
bottom_margin = int(margin[3] or 0)
else :
raise ValueError('Margin must be a tuple of either 2 or 4 elements.')
else:
raise ValueError("Margin must be a tuple of either 2 or 4 elements.")

img_width += left_margin + right_margin
img_height += top_margin + bottom_margin

Expand Down Expand Up @@ -1756,12 +1757,14 @@ def find_optimum_font_size(

y += top_margin

# So, pillow multiline support is horrible, in particular multiline_text and multiline_textbbox
# are not intuitive at all. They cannot use left top (see https://pillow.readthedocs.io/en/stable/handbook/text-anchors.html)
# as anchor, so we always have to use left middle instead. Else we would always have a useless
# margin (the diff between ascender and top) on any text.
# That mean our Y is actually not from 0 for top, but need to be increment by half our text height,
# since we have to reference from middle line.
# So, pillow multiline support is horrible, in particular multiline_text
# and multiline_textbbox are not intuitive at all. They cannot use left
# top (see https://pillow.readthedocs.io/en/stable/handbook/text-anchors.html)
# as anchor, so we always have to use left middle instead. Else we would
# always have a useless margin (the diff between ascender and top) on any
# text. That mean our Y is actually not from 0 for top, but need to be
# increment by half our text height, since we have to reference from
# middle line.
y += text_height / 2
print(y)

Expand Down
3 changes: 1 addition & 2 deletions moviepy/video/fx/Crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class Crop(Effect):
Crop a rectangle centered in x,y=(300,400), width=50, height=150 :
>>> Crop(x_center=300 , y_center=400,
width=50, height=150)
>>> Crop(x_center=300, y_center=400, width=50, height=150)
Any combination of the above should work, like for this rectangle
centered in x=300, with explicit y-boundaries:
Expand Down
6 changes: 4 additions & 2 deletions moviepy/video/fx/FreezeRegion.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class FreezeRegion(Effect):

def apply(self, clip: Clip) -> Clip:
if self.region is not None:
x1, y1, x2, y2 = self.region
x1, y1, _x2, _y2 = self.region
freeze = (
clip.with_effects([Crop(*self.region)])
.to_ImageClip(t=self.t)
Expand All @@ -60,6 +60,8 @@ def apply(self, clip: Clip) -> Clip:

elif self.mask is not None:
freeze = (
clip.to_ImageClip(t=t).with_duration(clip.duration).with_mask(self.mask)
clip.to_ImageClip(t=self.t)
.with_duration(clip.duration)
.with_mask(self.mask)
)
return CompositeVideoClip([clip, freeze])
1 change: 0 additions & 1 deletion moviepy/video/fx/Margin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import numpy as np

from moviepy.Clip import Clip
from moviepy.decorators import apply_to_mask
from moviepy.Effect import Effect
from moviepy.video.VideoClip import ImageClip

Expand Down
2 changes: 1 addition & 1 deletion moviepy/video/fx/MasksOr.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MasksOr(Effect):
def apply(self, clip: Clip) -> Clip:
# to ensure that 'or' of two ImageClips will be an ImageClip
if isinstance(self.other_clip, ImageClip):
other_clip = self.other_clip.img
self.other_clip = self.other_clip.img

if isinstance(self.other_clip, np.ndarray):
return clip.image_transform(
Expand Down
2 changes: 1 addition & 1 deletion moviepy/video/fx/Resize.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Resize(Effect):
>>> myClip.with_effects([vfx.Resize((460,720))]) # New resolution: (460,720)
>>> myClip.with_effects([vfx.Resize(0.6)]) # width and height multiplied by 0.6
>>> myClip.with_effects([vfx.Resize(width=800)]) # height computed automatically.
>>> myClip.with_effects([vfx.Resize(lambda t : 1+0.02*t)]) # slow swelling of the clip
>>> myClip.with_effects([vfx.Resize(lambda t : 1+0.02*t)]) # slow clip swelling
"""

new_size: Union[tuple, float, callable] = None
Expand Down
1 change: 0 additions & 1 deletion moviepy/video/fx/Rotate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import math
import warnings
from dataclasses import dataclass

import numpy as np
Expand Down
8 changes: 3 additions & 5 deletions moviepy/video/io/ffplay_previewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@

import subprocess as sp

import numpy as np
from proglog import proglog

from moviepy.config import FFMPEG_BINARY, FFPLAY_BINARY
from moviepy.config import FFPLAY_BINARY
from moviepy.tools import cross_platform_popen_params


Expand Down Expand Up @@ -129,7 +126,8 @@ def ffplay_preview_video(
for t, frame in clip.iter_frames(with_times=True, fps=fps, dtype="uint8"):
previewer.show_frame(frame)

# After first frame is shown, if we have audio/video flag, set video ready and wait for audio
# After first frame is shown, if we have audio/video flag, set video ready
# and wait for audio
if first_frame:
first_frame = False

Expand Down
3 changes: 2 additions & 1 deletion moviepy/video/tools/cuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ def select_scenes(
>>> from moviepy.video.tools.cuts import FramesMatches
>>>
>>> ch_clip = VideoFileClip("media/chaplin.mp4").with_subclip(1, 4)
>>> clip = concatenate_videoclips([ch_clip.with_effects([vfx.TimeMirror()]), ch_clip])
>>> mirror_and_clip = [ch_clip.with_effects([vfx.TimeMirror()]), ch_clip]
>>> clip = concatenate_videoclips(mirror_and_clip)
>>>
>>> result = FramesMatches.from_clip(clip, 10, 3).select_scenes(
... 1, 2, nomatch_threshold=0,
Expand Down
2 changes: 0 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
import importlib
import inspect
import io
import pathlib
import pkgutil
import socketserver
import sys
import tempfile
import threading

Expand Down
3 changes: 2 additions & 1 deletion tests/test_doc_examples.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Try to run all the documentation examples with runpy and check they dont raise exception"""
"""Try to run all the documentation examples with runpy and check they dont raise
exception"""

import os
import pathlib
Expand Down
2 changes: 0 additions & 2 deletions tests/test_fx.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"""MoviePy video and audio effects tests."""

import decimal
import importlib
import math
import numbers
import os
import random
import sys

import numpy as np

Expand Down
Loading

0 comments on commit 50e7e46

Please sign in to comment.