diff options
author | bai | 2020-07-28 04:06:01 -0400 |
---|---|---|
committer | bai | 2020-07-28 04:06:01 -0400 |
commit | 45610ff8b3d8868dec8586f51be4c8b91cdee4bd (patch) | |
tree | 7ae676b77176a7a9b48d4d7874e3ad91397e43a6 | |
parent | 47638cc804c084821b2db69e3a2f044da3043d33 (diff) | |
download | weabot-45610ff8b3d8868dec8586f51be4c8b91cdee4bd.tar.gz weabot-45610ff8b3d8868dec8586f51be4c8b91cdee4bd.tar.xz weabot-45610ff8b3d8868dec8586f51be4c8b91cdee4bd.zip |
Usando el mas nuevo check_output para crear miniaturas
-rw-r--r-- | cgi/img.py | 49 |
1 files changed, 27 insertions, 22 deletions
@@ -95,15 +95,24 @@ def processImage(post, data, t, originalname, spoiler=False): logTime("Generating thumbnail") if used_filetype['mime'][:5] == 'video': - retcode = subprocess.call([ - Settings.FFMPEG_PATH, '-strict', '-2', '-ss', '0', '-i', file_path, - '-v', 'quiet', '-an', '-vframes', '1', '-f', 'mjpeg', '-vf', 'scale=%d:%d' % ( - file_thumb_width, file_thumb_height), - '-threads', '1', file_thumb_path]) - if spoiler: - args = [Settings.CONVERT_PATH, file_thumb_path, "-limit", "thread", "1", "-background", "white", "-flatten", "-resize", "%dx%d" % (file_thumb_width, file_thumb_height), "-blur", "0x12", "-gravity", "center", "-fill", "rgba(0,0,0, .6)", "-draw", "rectangle 0,%d,%d,%d" % ( - (file_thumb_height/2)-10, file_thumb_width, (file_thumb_height/2)+7), "-fill", "white", "-annotate", "0", "Alerta de spoiler", "-quality", str(Settings.THUMB_QUALITY), file_thumb_path] - retcode = subprocess.call(args) + # Create preview for video AND spoiler it if necessary + try: + subprocess.check_output([ + Settings.FFMPEG_PATH, '-strict', '-2', '-ss', '0', '-i', file_path, + '-v', 'quiet', '-an', '-vframes', '1', '-f', 'mjpeg', '-vf', 'scale=%d:%d' % ( + file_thumb_width, file_thumb_height), + '-threads', '1', file_thumb_path]) + if spoiler: + subprocess.check_output([Settings.CONVERT_PATH, file_thumb_path, "-limit", "thread", + "1", "-background", "white", "-flatten", "-resize", + "%dx%d" % (file_thumb_width, file_thumb_height), "-blur", "0x12", + "-gravity", "center", "-fill", "rgba(0,0,0, .6)", + "-draw", "rectangle 0,%d,%d,%d" % ((file_thumb_height/2)-10, file_thumb_width, (file_thumb_height/2)+7), + "-fill", "white", "-annotate", "0", "Alerta de spoiler", + "-quality", str(Settings.THUMB_QUALITY), file_thumb_path]) + except subprocess.CalledProcessError, e: + os.remove(file_path) + raise UserError, _("Thumbnail creation failure.") + ' ('+str(e.returncode)+')' elif used_filetype['mime'][:5] == 'audio': # we do an exception and use png for audio waveform thumbnails since they # 1. are smaller 2. allow for transparency @@ -119,19 +128,14 @@ def processImage(post, data, t, originalname, spoiler=False): file_thumb_width = 150 file_thumb_height = 75 - retcode = subprocess.call([ - Settings.FFMPEG_PATH, '-t', '300', '-i', file_path, + try: + subprocess.check_output([Settings.FFMPEG_PATH, '-t', '300', '-i', file_path, '-filter_complex', 'showwavespic=s=%dx%d:split_channels=1' % ( int(file_thumb_width), int(file_thumb_height)), '-frames:v', '1', '-threads', '1', file_thumb_path]) -# elif used_filetype['mime'] == 'application/x-shockwave-flash' or used_filetype['mime'] == 'mime/x-shockwave-flash': -# retcode = subprocess.call([ -# './ffmpeg', '-i', file_path, '-vcodec', 'mjpeg', '-vframes', '1', '-an', '-f', 'rawvideo', -# '-vf', 'scale=%d:%d' % (file_thumb_width, file_thumb_height), '-threads', '1', file_thumb_path]) - - if retcode != 0: - os.remove(file_path) - raise UserError, _("Thumbnail creation failure.") + ' ('+str(retcode)+')' + except subprocess.CalledProcessError, e: + os.remove(file_path) + raise UserError, _("Thumbnail creation failure.") + ' ('+str(e.returncode)+')' else: # use imagemagick to make thumbnail args = [Settings.CONVERT_PATH, file_path, "-limit", "thread", "1", "-background", @@ -143,10 +147,11 @@ def processImage(post, data, t, originalname, spoiler=False): # generate thumbnails logTime("Generating thumbnail") - retcode = subprocess.call(args) - if retcode != 0: + try: + subprocess.check_output(args) + except subprocess.CalledProcessError, e: os.remove(file_path) - raise UserError, _("Thumbnail creation failure.") + ' ('+str(retcode)+')' + raise UserError, _("Thumbnail creation failure.") + ' ('+str(e.returncode)+')' # check if thumbnail was truly created try: |