Skip image instead of failing when the image is corrupted (fix #69).

This commit is contained in:
Simon Conseil
2014-05-08 00:35:52 +02:00
parent 85a1e7b65a
commit cf63f916c4
2 changed files with 13 additions and 4 deletions

View File

@@ -109,9 +109,13 @@ class Media(UnicodeMixin):
generator = video.generate_thumbnail
self.logger.debug('Generating thumbnail for %r', self)
generator(self.src_path, self.thumb_path,
self.settings['thumb_size'],
fit=self.settings['thumb_fit'])
try:
generator(self.src_path, self.thumb_path,
self.settings['thumb_size'],
fit=self.settings['thumb_fit'])
except Exception as e:
self.logger.error('Failed to generate thumbnail: %s', e)
return
return self.thumb_name

View File

@@ -128,6 +128,7 @@ def generate_thumbnail(source, outname, box, fit=True, options=None):
def process_image(filepath, outpath, settings):
"""Process one image: resize, create thumbnail."""
logger = logging.getLogger(__name__)
filename = os.path.split(filepath)[1]
outname = os.path.join(outpath, filename)
ext = os.path.splitext(filename)[1]
@@ -139,7 +140,11 @@ def process_image(filepath, outpath, settings):
else:
options = {}
generate_image(filepath, outname, settings, options=options)
try:
generate_image(filepath, outname, settings, options=options)
except Exception as e:
logger.error('Failed to process image: %s', e)
return
if settings['make_thumbs']:
thumb_name = os.path.join(outpath, get_thumb(settings, filename))