aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoar Wandborg <git@wandborg.com>2012-02-16 18:43:15 +0100
committerJoar Wandborg <git@wandborg.com>2012-02-16 18:43:15 +0100
commit92f129b5c707bdeaceb0cdf9807342b52db33b45 (patch)
tree1ebd367498a578be7790e5fe548420b6332e6f8b
parentec4261a449c11b015190bc90dd9ae828261065cd (diff)
downloadmediagoblin-92f129b5c707bdeaceb0cdf9807342b52db33b45.tar.lz
mediagoblin-92f129b5c707bdeaceb0cdf9807342b52db33b45.tar.xz
mediagoblin-92f129b5c707bdeaceb0cdf9807342b52db33b45.zip
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.
-rw-r--r--mediagoblin/media_types/image/processing.py24
1 files changed, 24 insertions, 0 deletions
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):