Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More PEP8 compliance #711

Merged
merged 3 commits into from
Feb 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 43 additions & 41 deletions moviepy/video/VideoClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ def write_videofile(self, filename, fps=None, codec=None,
codec = extensions_dict[ext]['codec'][0]
except KeyError:
raise ValueError("MoviePy couldn't find the codec associated "
"with the filename. Provide the 'codec' parameter in "
"write_videofile.")
"with the filename. Provide the 'codec' "
"parameter in write_videofile.")

if audio_codec is None:
if (ext in ['ogv', 'webm']):
if ext in ['ogv', 'webm']:
audio_codec = 'libvorbis'
else:
audio_codec = 'libmp3lame'
Expand Down Expand Up @@ -297,8 +297,9 @@ def write_videofile(self, filename, fps=None, codec=None,

raise ValueError(
"The audio_codec you chose is unknown by MoviePy. "
"You should report this. In the meantime, you can specify a "
"temp_audiofile with the right extension in write_videofile.")
"You should report this. In the meantime, you can "
"specify a temp_audiofile with the right extension "
"in write_videofile.")

audiofile = (name + Clip._TEMP_FILES_PREFIX +
"wvf_snd.%s" % audio_ext)
Expand All @@ -319,7 +320,7 @@ def write_videofile(self, filename, fps=None, codec=None,
bitrate=bitrate,
preset=preset,
write_logfile=write_logfile,
audiofile = audiofile,
audiofile=audiofile,
verbose=verbose, threads=threads,
ffmpeg_params=ffmpeg_params,
progress_bar=progress_bar)
Expand Down Expand Up @@ -354,7 +355,7 @@ def write_images_sequence(self, nameformat, fps=None, verbose=True,
will save the clip's mask (if any) as an alpha canal (PNGs only).

verbose
Boolean indicating whether to print infomation.
Boolean indicating whether to print information.

progress_bar
Boolean indicating whether to show the progress bar.
Expand Down Expand Up @@ -443,13 +444,13 @@ def write_gif(self, filename, fps=None, program='imageio',
write_gif_with_image_io(self, filename, fps=fps, opt=opt, loop=loop,
verbose=verbose, colors=colors)
elif tempfiles:
#convert imageio opt variable to something that can be used with
#ImageMagick
opt1=opt
# convert imageio opt variable to something that can be used with
# ImageMagick
opt1 = opt
if opt1 == 'nq':
opt1='optimizeplus'
opt1 ='optimizeplus'
else:
opt1='OptimizeTransparency'
opt1 ='OptimizeTransparency'
write_gif_with_tempfiles(self, filename, fps=fps,
program=program, opt=opt1, fuzz=fuzz,
verbose=verbose,
Expand Down Expand Up @@ -636,7 +637,7 @@ def on_color(self, size=None, color=(0, 0, 0), pos=None,
bg_color=color)

if (isinstance(self, ImageClip) and (not hasattr(pos, "__call__"))
and ((self.mask is None) or isinstance(self.mask, ImageClip))):
and ((self.mask is None) or isinstance(self.mask, ImageClip))):
new_result = result.to_ImageClip()
if result.mask is not None:
new_result.mask = result.mask.to_ImageClip()
Expand Down Expand Up @@ -682,7 +683,6 @@ def set_opacity(self, op):
"""
self.mask = self.mask.fl_image(lambda pic: op * pic)


@apply_to_mask
@outplace
def set_position(self, pos, relative=False):
Expand Down Expand Up @@ -715,7 +715,7 @@ def set_position(self, pos, relative=False):
else:
self.pos = lambda t: pos

#--------------------------------------------------------------
# --------------------------------------------------------------
# CONVERSIONS TO OTHER TYPES

@convert_to_seconds(['t'])
Expand All @@ -730,7 +730,6 @@ def to_ImageClip(self, t=0, with_mask=True):
newclip.mask = self.mask.to_ImageClip(t)
return newclip


def to_mask(self, canal=0):
"""Return a mask a video clip made from the clip."""
if self.ismask:
Expand All @@ -751,7 +750,7 @@ def to_RGB(self):
else:
return self

#----------------------------------------------------------------
# ----------------------------------------------------------------
# Audio

@outplace
Expand Down Expand Up @@ -797,10 +796,11 @@ def __init__(self, data, data_to_frame, fps, ismask=False,
has_constant_size=True):
self.data = data
self.data_to_frame = data_to_frame
self.fps=fps
make_frame = lambda t: self.data_to_frame( self.data[int(self.fps*t)])
self.fps = fps
make_frame = lambda t: self.data_to_frame(self.data[int(self.fps*t)])
VideoClip.__init__(self, make_frame, ismask=ismask,
duration=1.0*len(data)/fps, has_constant_size=has_constant_size)
duration=1.0*len(data)/fps,
has_constant_size=has_constant_size)


class UpdatedVideoClip(VideoClip):
Expand Down Expand Up @@ -838,12 +838,14 @@ class UpdatedVideoClip(VideoClip):

def __init__(self, world, ismask=False, duration=None):
self.world = world

def make_frame(t):
while self.world.clip_t < t:
world.update()
return world.to_frame()
VideoClip.__init__(self, make_frame= make_frame,
ismask=ismask, duration=duration)

VideoClip.__init__(self, make_frame=make_frame,
ismask=ismask, duration=duration)


"""---------------------------------------------------------------------
Expand Down Expand Up @@ -895,11 +897,11 @@ def __init__(self, img, ismask=False, transparent=True,
VideoClip.__init__(self, ismask=ismask, duration=duration)

if PY3:
if isinstance(img, str):
img = imread(img)
if isinstance(img, str):
img = imread(img)
else:
if isinstance(img, (str, unicode)):
img = imread(img)
if isinstance(img, (str, unicode)):
img = imread(img)

if len(img.shape) == 3: # img is (now) a RGB(a) numpy array

Expand Down Expand Up @@ -985,12 +987,12 @@ def fl_time(self, time_func, apply_to=None,
# replaced by the more explicite write_videofile, write_gif, etc.

VideoClip.set_pos = deprecated_version_of(VideoClip.set_position,
'set_pos')
'set_pos')
VideoClip.to_videofile = deprecated_version_of(VideoClip.write_videofile,
'to_videofile')
VideoClip.to_gif = deprecated_version_of(VideoClip.write_gif, 'to_gif')
VideoClip.to_images_sequence = deprecated_version_of(VideoClip.write_images_sequence,
'to_images_sequence')
'to_images_sequence')


class ColorClip(ImageClip):
Expand Down Expand Up @@ -1119,10 +1121,10 @@ def __init__(self, txt=None, filename=None, size=None, color='black',
size = ('' if size[0] is None else str(size[0]),
'' if size[1] is None else str(size[1]))

cmd = ( [get_setting("IMAGEMAGICK_BINARY"),
cmd = ([get_setting("IMAGEMAGICK_BINARY"),
"-background", bg_color,
"-fill", color,
"-font", font])
"-fill", color,
"-font", font])

if fontsize is not None:
cmd += ["-pointsize", "%d" % fontsize]
Expand All @@ -1146,18 +1148,18 @@ def __init__(self, txt=None, filename=None, size=None, color='black',
"-type", "truecolormatte", "PNG32:%s" % tempfilename]

if print_cmd:
print( " ".join(cmd) )
print(" ".join(cmd))

try:
subprocess_call(cmd, verbose=False )
except (IOError,OSError) as err:
error = ("MoviePy Error: creation of %s failed because "
"of the following error:\n\n%s.\n\n."%(filename, str(err))
+ ("This error can be due to the fact that "
"ImageMagick is not installed on your computer, or "
"(for Windows users) that you didn't specify the "
"path to the ImageMagick binary in file conf.py, or."
"that the path you specified is incorrect" ))
subprocess_call(cmd, verbose=False)
except (IOError, OSError) as err:
error = ("MoviePy Error: creation of %s failed because of the "
"following error:\n\n%s.\n\n." % (filename, str(err))
+ ("This error can be due to the fact that ImageMagick "
"is not installed on your computer, or (for Windows "
"users) that you didn't specify the path to the "
"ImageMagick binary in file conf.py, or that the path "
"you specified is incorrect"))
raise IOError(error)

ImageClip.__init__(self, tempfilename, transparent=transparent)
Expand Down