From db9e5f8681e682d3f26cef6702153aabfa4e54c7 Mon Sep 17 00:00:00 2001 From: Tom Burrows <22625968+tburrows13@users.noreply.github.com> Date: Mon, 12 Feb 2018 14:57:14 +0000 Subject: [PATCH] More PEP8 compliance (#712) PEP 8 --- moviepy/Clip.py | 48 ++++++++++++++----------------- moviepy/video/io/VideoFileClip.py | 19 ++++++------ 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/moviepy/Clip.py b/moviepy/Clip.py index 015ecf513..4e72f5d70 100644 --- a/moviepy/Clip.py +++ b/moviepy/Clip.py @@ -7,14 +7,15 @@ from copy import copy import numpy as np -from moviepy.decorators import ( apply_to_mask, - apply_to_audio, - requires_duration, - outplace, - convert_to_seconds, - use_clip_fps_by_default) +from moviepy.decorators import (apply_to_mask, + apply_to_audio, + requires_duration, + outplace, + convert_to_seconds, + use_clip_fps_by_default) from tqdm import tqdm + class Clip: """ @@ -53,9 +54,7 @@ def __init__(self): self.memoize = False self.memoized_t = None - self.memoize_frame = None - - + self.memoize_frame = None def copy(self): """ Shallow copy of the clip. @@ -148,13 +147,11 @@ def fl(self, fun, apply_to=None, keep_duration=True): if hasattr(newclip, attr): a = getattr(newclip, attr) if a is not None: - new_a = a.fl(fun, keep_duration=keep_duration) + new_a = a.fl(fun, keep_duration=keep_duration) setattr(newclip, attr, new_a) return newclip - - def fl_time(self, t_func, apply_to=None, keep_duration=False): """ Returns a Clip instance playing the content of the current clip @@ -190,9 +187,7 @@ def fl_time(self, t_func, apply_to=None, keep_duration=False): apply_to = [] return self.fl(lambda gf, t: gf(t_func(t)), apply_to, - keep_duration=keep_duration) - - + keep_duration=keep_duration) def fx(self, func, *args, **kwargs): """ @@ -246,7 +241,7 @@ def set_start(self, t, change_end=True): self.start = t if (self.duration is not None) and change_end: self.end = t + self.duration - elif (self.end is not None): + elif self.end is not None: self.duration = self.end - self.start @@ -348,7 +343,7 @@ def is_playing(self, t): # If we arrive here, a part of t falls in the clip result = 1 * (t >= self.start) - if (self.end is not None): + if self.end is not None: result *= (t <= self.end) return result @@ -384,14 +379,15 @@ def subclip(self, t_start=0, t_end=None): they exist. """ - if t_start < 0: #make this more python like a negative value - #means to move backward from the end of the clip - t_start = self.duration + t_start #remeber t_start is negative + if t_start < 0: + # Make this more Python-like, a negative value means to move + # backward from the end of the clip + t_start = self.duration + t_start # Remember t_start is negative - if (self.duration is not None) and (t_start>self.duration): - raise ValueError("t_start (%.02f) "%t_start + + if (self.duration is not None) and (t_start > self.duration): + raise ValueError("t_start (%.02f) "% t_start + "should be smaller than the clip's "+ - "duration (%.02f)."%self.duration) + "duration (%.02f)."% self.duration) newclip = self.fl_time(lambda t: t + t_start, apply_to=[]) @@ -403,14 +399,14 @@ def subclip(self, t_start=0, t_end=None): if self.duration is None: - print ("Error: subclip with negative times (here %s)"%(str((t_start, t_end))) - +" can only be extracted from clips with a ``duration``") + print("Error: subclip with negative times (here %s)" % (str((t_start, t_end))) + + " can only be extracted from clips with a ``duration``") else: t_end = self.duration + t_end - if (t_end is not None): + if t_end is not None: newclip.duration = t_end - t_start newclip.end = newclip.start + newclip.duration diff --git a/moviepy/video/io/VideoFileClip.py b/moviepy/video/io/VideoFileClip.py index a5e300c40..cd5534e1d 100644 --- a/moviepy/video/io/VideoFileClip.py +++ b/moviepy/video/io/VideoFileClip.py @@ -5,6 +5,7 @@ from moviepy.Clip import Clip from moviepy.video.io.ffmpeg_reader import FFMPEG_VideoReader + class VideoFileClip(VideoClip): """ @@ -14,7 +15,7 @@ class VideoFileClip(VideoClip): >>> clip = VideoFileClip("myHolidays.mp4") >>> clip.close() >>> with VideoFileClip("myMaskVideo.avi") as clip2: - >>> pass # Implicit close called by contex manager. + >>> pass # Implicit close called by context manager. Parameters @@ -75,7 +76,7 @@ class VideoFileClip(VideoClip): """ def __init__(self, filename, has_mask=False, - audio=True, audio_buffersize = 200000, + audio=True, audio_buffersize=200000, target_resolution=None, resize_algorithm='bicubic', audio_fps=44100, audio_nbytes=2, verbose=False, fps_source='tbr'): @@ -83,7 +84,7 @@ def __init__(self, filename, has_mask=False, VideoClip.__init__(self) # Make a reader - pix_fmt= "rgba" if has_mask else "rgb24" + pix_fmt = "rgba" if has_mask else "rgb24" self.reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt, target_resolution=target_resolution, resize_algo=resize_algorithm, @@ -102,9 +103,9 @@ def __init__(self, filename, has_mask=False, if has_mask: self.make_frame = lambda t: self.reader.get_frame(t)[:,:,:3] - mask_mf = lambda t: self.reader.get_frame(t)[:,:,3]/255.0 - self.mask = (VideoClip(ismask = True, make_frame = mask_mf) - .set_duration(self.duration)) + mask_mf = lambda t: self.reader.get_frame(t)[:,:,3]/255.0 + self.mask = (VideoClip(ismask=True, make_frame=mask_mf) + .set_duration(self.duration)) self.mask.fps = self.fps else: @@ -115,9 +116,9 @@ def __init__(self, filename, has_mask=False, if audio and self.reader.infos['audio_found']: self.audio = AudioFileClip(filename, - buffersize= audio_buffersize, - fps = audio_fps, - nbytes = audio_nbytes) + buffersize=audio_buffersize, + fps=audio_fps, + nbytes=audio_nbytes) def close(self): """ Close the internal reader. """