Address pycodestyle comments and extraneous newlines
This commit is contained in:
parent
eaf2fb15f8
commit
8dc24f0da7
1 changed files with 9 additions and 7 deletions
|
@ -12,7 +12,7 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
_SCALE_FIT_FMT = (
|
_SCALE_FIT_FMT = (
|
||||||
r'scale=iw*max({width}/iw\,{height}/ih):ih*max({width}/iw\,{height}/ih)')
|
r'scale=\'{width}:{height}\'')
|
||||||
|
|
||||||
|
|
||||||
class Image:
|
class Image:
|
||||||
|
@ -33,14 +33,13 @@ class Image:
|
||||||
return self.info['streams'][0]['nb_read_frames']
|
return self.info['streams'][0]['nb_read_frames']
|
||||||
|
|
||||||
def resize_fill(self, width: int, height: int) -> None:
|
def resize_fill(self, width: int, height: int) -> None:
|
||||||
|
|
||||||
width_greater = self.width > self.height
|
width_greater = self.width > self.height
|
||||||
scale_param = "scale='%d:%d" % ((-1, height) if width_greater else (width, -1))
|
width, height = (-1, height) if width_greater else (width, -1)
|
||||||
|
|
||||||
cli = [
|
cli = [
|
||||||
'-i', '{path}',
|
'-i', '{path}',
|
||||||
'-f', 'image2',
|
'-f', 'image2',
|
||||||
'-filter:v', scale_param,
|
'-filter:v', _SCALE_FIT_FMT.format(width=width, height=height),
|
||||||
'-map', '0:v:0',
|
'-map', '0:v:0',
|
||||||
'-vframes', '1',
|
'-vframes', '1',
|
||||||
'-vcodec', 'png',
|
'-vcodec', 'png',
|
||||||
|
@ -83,7 +82,8 @@ class Image:
|
||||||
'-',
|
'-',
|
||||||
])
|
])
|
||||||
|
|
||||||
def _execute(self, cli: List[str], program: str = 'ffmpeg', ignore_error_if_data: bool = False) -> bytes:
|
def _execute(self, cli: List[str], program: str = 'ffmpeg',
|
||||||
|
ignore_error_if_data: bool = False) -> bytes:
|
||||||
extension = mime.get_extension(mime.get_mime_type(self.content))
|
extension = mime.get_extension(mime.get_mime_type(self.content))
|
||||||
assert extension
|
assert extension
|
||||||
with util.create_temp_file(suffix='.' + extension) as handle:
|
with util.create_temp_file(suffix='.' + extension) as handle:
|
||||||
|
@ -102,9 +102,11 @@ class Image:
|
||||||
'Failed to execute ffmpeg command (cli=%r, err=%r)',
|
'Failed to execute ffmpeg command (cli=%r, err=%r)',
|
||||||
' '.join(shlex.quote(arg) for arg in cli),
|
' '.join(shlex.quote(arg) for arg in cli),
|
||||||
err)
|
err)
|
||||||
if (not ignore_error_if_data and len(out) > 0) or len(out) == 0:
|
if ((len(out) > 0 and not ignore_error_if_data)
|
||||||
|
or len(out) == 0):
|
||||||
raise errors.ProcessingError(
|
raise errors.ProcessingError(
|
||||||
'Error while processing image.\n' + err.decode('utf-8'))
|
'Error while processing image.\n'
|
||||||
|
+ err.decode('utf-8'))
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def _reload_info(self) -> None:
|
def _reload_info(self) -> None:
|
||||||
|
|
Reference in a new issue