Removed diaper patterns from audio/video sniffers, video preload set to 'metadata'
authorJoar Wandborg <git@wandborg.com>
Wed, 7 Mar 2012 21:48:23 +0000 (22:48 +0100)
committerJoar Wandborg <git@wandborg.com>
Wed, 7 Mar 2012 21:48:23 +0000 (22:48 +0100)
* mediagoblin.processing THUMB_/MEDIUM_ constants are now based on the ini settings
* Removed diaper patterns from audio and video sniffing
* Changed HTML5 video preload to 'metadata'

mediagoblin/config_spec.ini
mediagoblin/media_types/__init__.py
mediagoblin/media_types/audio/processing.py
mediagoblin/media_types/audio/transcoders.py
mediagoblin/media_types/video/processing.py
mediagoblin/media_types/video/transcoders.py
mediagoblin/processing.py
mediagoblin/templates/mediagoblin/media_displays/video.html

index b429677c7554a6bf15dafbf0ab822b2e19d65729..5c71a9b85c028eb6210717a89b18a6225c5f5147 100644 (file)
@@ -66,10 +66,15 @@ storage_class = string(default="mediagoblin.storage.filestorage:BasicFileStorage
 base_dir = string(default="%(here)s/user_dev/media/queue")
 
 [media:medium]
+# Dimensions used when creating media display images.
 max_width = integer(default=640)
 max_height = integer(default=640)
 
 [media:thumb]
+# Dimensions used when creating media thumbnails
+# This is unfortunately not implemented in the media
+# types yet. You can help!
+# TODO: Make plugins follow the media size settings
 max_width = integer(default=180)
 max_height = integer(default=180)
 
index 19d822a315e6a2d112adfa0904e8809eb8a3103b..db8c6f73de06f4386d495a5af5f27150df16d614 100644 (file)
@@ -42,7 +42,10 @@ def sniff_media(media):
     for media_type, manager in get_media_managers():
         _log.info('Sniffing {0}'.format(media_type))
         if manager['sniff_handler'](media_file, media=media):
+            _log.info('{0} accepts the file'.format(media_type))
             return media_type, manager
+        else:
+            _log.debug('{0} did not accept the file'.format(media_type))
 
     raise FileTypeNotSupported(
         # TODO: Provide information on which file types are supported
index 6769f60586046a69b7885b981a62e5429742b6de..8348f8437f9897ce3366af48c2d8b9ec1edbe3e5 100644 (file)
@@ -19,7 +19,7 @@ import tempfile
 import os
 
 from mediagoblin import mg_globals as mgg
-from mediagoblin.processing import create_pub_filepath
+from mediagoblin.processing import create_pub_filepath, BadMediaFail
 
 from mediagoblin.media_types.audio.transcoders import AudioTranscoder, \
     AudioThumbnailer
@@ -27,14 +27,15 @@ from mediagoblin.media_types.audio.transcoders import AudioTranscoder, \
 _log = logging.getLogger(__name__)
 
 def sniff_handler(media_file, **kw):
-    transcoder = AudioTranscoder()
-    try:
+    try: 
+        transcoder = AudioTranscoder()
         data = transcoder.discover(media_file.name)
+    except BadMediaFail:
+        _log.debug('Audio discovery raised BadMediaFail')
+        return False
 
-        if data.is_audio == True and data.is_video == False:
-            return True
-    except:
-        pass
+    if data.is_audio == True and data.is_video == False:
+        return True
 
     return False
 
index 7649309c3db722a168fb45907f103361992a2ba9..ed40e03c6bb9a786352100f34a237b57e4cc0c68 100644 (file)
@@ -100,7 +100,7 @@ class AudioThumbnailer(object):
         Takes a spectrogram and creates a thumbnail from it
         '''
         if not (type(thumb_size) == tuple and len(thumb_size) == 2):
-            raise Exception('size argument should be a tuple(width, height)')
+            raise Exception('thumb_size argument should be a tuple(width, height)')
 
         im = Image.open(src)
 
@@ -110,7 +110,7 @@ class AudioThumbnailer(object):
         wadsworth_position = im_w * 0.3
 
         start_x = max((
-                wadsworth_position - (th_w / 2.0),
+                wadsworth_position - ((im_h * (th_w / th_h)) / 2.0),
                 0.0))
 
         stop_x = start_x + (im_h * (th_w / th_h))
index d2562e3b366681e69b560fc8b2762b09d74be138..a8fcf86d829127400bdf896e3b5ef190299062e5 100644 (file)
@@ -30,16 +30,17 @@ _log.setLevel(logging.DEBUG)
 
 def sniff_handler(media_file, **kw):
     transcoder = transcoders.VideoTranscoder()
-    try:
-        data = transcoder.discover(media_file.name)
+    data = transcoder.discover(media_file.name)
 
-        _log.debug('Discovered: {0}'.format(data.__dict__))
+    _log.debug('Discovered: {0}'.format(data))
 
-        if data.is_video == True:
-            return True
-    except:
-        _log.error('Exception caught when trying to discover {0}'.format(
+    if not data:
+        _log.error('Could not discover {0}'.format(
                 kw.get('media')))
+        return False
+
+    if data['is_video'] == True:
+        return True
 
     return False
 
index 6c2e885e26f0390f3c0f5b8803b5646cc33aa923..d865bc8d97bfaf82f95b5dab7faccd46641d5d45 100644 (file)
@@ -373,9 +373,13 @@ class VideoTranscoder:
 
         self.loop.run()
 
-        return self._discovered_data
+        if hasattr(self, '_discovered_data'):
+            return self._discovered_data.__dict__
+        else:
+            return None
 
     def __on_discovered(self, data, is_media):
+        _log.debug('Discovered: {0}'.format(data))
         if not is_media:
             self.__stop()
             raise Exception('Could not discover {0}'.format(self.source_path))
@@ -624,8 +628,9 @@ class VideoTranscoder:
     def __stop(self):
         _log.debug(self.loop)
 
-        # Stop executing the pipeline
-        self.pipeline.set_state(gst.STATE_NULL)
+        if hasattr(self, 'pipeline'):
+            # Stop executing the pipeline
+            self.pipeline.set_state(gst.STATE_NULL)
 
         # This kills the loop, mercifully
         gobject.idle_add(self.__stop_mainloop)
index 9e57380dec8bc4941cdbd932b7cc74b9fe7b161c..ff5eb00a1c984339a96a7d2b807032355a066337 100644 (file)
@@ -27,8 +27,11 @@ from mediagoblin.media_types import get_media_manager
 
 _log = logging.getLogger(__name__)
 
-THUMB_SIZE = 180, 180
-MEDIUM_SIZE = 640, 640
+THUMB_SIZE = (mgg.global_config['media:thumb']['max_width'],
+              mgg.global_config['media:thumb']['max_height'])
+
+MEDIUM_SIZE = (mgg.global_config['media:medium']['max_width'],
+               mgg.global_config['media:medium']['max_height'])
 
 
 def create_pub_filepath(entry, filename):
index ec4338fa3147e44f36868690a32d5129055bb6fc..84631ff568fcaf8de2e19373b32c439a84efba58 100644 (file)
@@ -24,7 +24,7 @@
           width="{{ media.media_data.video.width }}"
           height="{{ media.media_data.video.height }}"
           controls="controls"
-          preload="auto"
+          preload="metadata"
           data-setup="">
       <source src="{{ request.app.public_store.file_url(
                   media.media_files['webm_640']) }}"