converted video media_type to plugin
authorRodney Ewing <ewing.rj@gmail.com>
Tue, 2 Jul 2013 15:57:10 +0000 (08:57 -0700)
committerRodney Ewing <ewing.rj@gmail.com>
Tue, 2 Jul 2013 16:00:57 +0000 (09:00 -0700)
mediagoblin/media_types/video/__init__.py
mediagoblin/media_types/video/processing.py

index 569cf11a3525b9529160c988636e72a3e2047adb..aa4cdb938dd9ea3ba46e2155de46cc5584d1037a 100644 (file)
 from mediagoblin.media_types import MediaManagerBase
 from mediagoblin.media_types.video.processing import process_video, \
     sniff_handler
+from mediagoblin.tools import pluginapi
+
+MEDIA_TYPE = 'mediagoblin.media_types.video'
+ACCEPTED_EXTENSIONS = [
+        "mp4", "mov", "webm", "avi", "3gp", "3gpp", "mkv", "ogv", "m4v"]
+
+
+def setup_plugin():
+    config = pluginapi.get_config(MEDIA_TYPE)
 
 
 class VideoMediaManager(MediaManagerBase):
     human_readable = "Video"
     processor = staticmethod(process_video)
-    sniff_handler = staticmethod(sniff_handler)
     display_template = "mediagoblin/media_displays/video.html"
     default_thumb = "images/media_thumbs/video.jpg"
-    accepted_extensions = [
-        "mp4", "mov", "webm", "avi", "3gp", "3gpp", "mkv", "ogv", "m4v"]
-        
+
     # Used by the media_entry.get_display_media method
     media_fetch_order = [u'webm_640', u'original']
     default_webm_type = 'video/webm; codecs="vp8, vorbis"'
 
 
-MEDIA_MANAGER = VideoMediaManager
+def get_media_manager(media_type):
+    if media_type == MEDIA_TYPE:
+        return VideoMediaManager
+
+
+def get_media_type_and_manager(ext):
+    if ext in ACCEPTED_EXTENSIONS:
+        return MEDIA_TYPE, VideoMediaManager
+
+hooks = {
+    'setup': setup_plugin,
+    'get_media_type_and_manager': get_media_type_and_manager,
+    'sniff_handler': sniff_handler,
+    'get_media_manager': get_media_manager,
+}
index ff2c94a02bd8b6422723ca6f89ba74cb74dc1e6a..5386ba60b6983cc9451607c951eeb7402409e533 100644 (file)
@@ -29,6 +29,8 @@ from .util import skip_transcode
 _log = logging.getLogger(__name__)
 _log.setLevel(logging.DEBUG)
 
+MEDIA_TYPE = 'mediagoblin.media_types.video'
+
 
 class VideoTranscodingFail(BaseProcessingFail):
     '''
@@ -41,17 +43,18 @@ def sniff_handler(media_file, **kw):
     transcoder = transcoders.VideoTranscoder()
     data = transcoder.discover(media_file.name)
 
+    _log.info('Sniffing {0}'.format(MEDIA_TYPE))
     _log.debug('Discovered: {0}'.format(data))
 
     if not data:
         _log.error('Could not discover {0}'.format(
                 kw.get('media')))
-        return False
+        return None
 
     if data['is_video'] == True:
-        return True
+        return MEDIA_TYPE
 
-    return False
+    return None
 
 
 def process_video(proc_state):
@@ -186,7 +189,7 @@ def store_metadata(media_entry, metadata):
             [(key, tags_metadata[key])
              for key in [
                      "application-name", "artist", "audio-codec", "bitrate",
-                     "container-format", "copyright", "encoder", 
+                     "container-format", "copyright", "encoder",
                      "encoder-version", "license", "nominal-bitrate", "title",
                      "video-codec"]
              if key in tags_metadata])
@@ -203,7 +206,7 @@ def store_metadata(media_entry, metadata):
                 dt.get_year(), dt.get_month(), dt.get_day(), dt.get_hour(),
                 dt.get_minute(), dt.get_second(),
                 dt.get_microsecond()).isoformat()
-    
+
         metadata['tags'] = tags
 
     # Only save this field if there's something to save