From 92f129b5c707bdeaceb0cdf9807342b52db33b45 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Thu, 16 Feb 2012 18:43:15 +0100 Subject: [PATCH] Added sniffing logic for image media type For now, it's a re-implementation of the old file-extension checking logic, as I have not found a GStreamer-like "discoverer" in PIL. --- mediagoblin/media_types/image/processing.py | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mediagoblin/media_types/image/processing.py b/mediagoblin/media_types/image/processing.py index d301a69f..364a5afa 100644 --- a/mediagoblin/media_types/image/processing.py +++ b/mediagoblin/media_types/image/processing.py @@ -16,6 +16,7 @@ import Image import os +import logging from mediagoblin import mg_globals as mgg from mediagoblin.processing import BadMediaFail, \ @@ -23,7 +24,30 @@ from mediagoblin.processing import BadMediaFail, \ from mediagoblin.tools.exif import exif_fix_image_orientation, \ extract_exif, clean_exif, get_gps_data, get_useful +_log = logging.getLogger(__name__) + +SUPPORTED_FILETYPES = ['png', 'gif', 'jpg', 'jpeg'] + def sniff_handler(media_file, **kw): + if not kw.get('media') == None: # That's a double negative! + name, ext = os.path.splitext(kw['media'].filename) + clean_ext = ext[1:].lower() # Strip the . from ext and make lowercase + + _log.debug('name: {0}\next: {1}\nlower_ext: {2}'.format( + name, + ext, + clean_ext)) + + if clean_ext in SUPPORTED_FILETYPES: + _log.info('Found file extension in supported filetypes') + return True + else: + _log.debug('Media present, extension not found in {1}'.format( + SUPPORTED_FILETYPES)) + else: + _log.warning('Need additional information (keyword argument \'media\')' + ' to be able to handle sniffing') + return False def process_image(entry): -- 2.25.1