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

index 2eb7300e3e12e44f127f76340b58cb3325d1daba..dfe686606db19a9af9b147ef8ae417cc4be5d49e 100644 (file)
 from mediagoblin.media_types import MediaManagerBase
 from mediagoblin.media_types.audio.processing import process_audio, \
     sniff_handler
+from mediagoblin.tools import pluginapi
+
+ACCEPTED_EXTENSIONS = ["mp3", "flac", "wav", "m4a"]
+MEDIA_TYPE = 'mediagoblin.media_types.audio'
+
+
+def setup_plugin():
+    config = pluginapi.get_config(MEDIA_TYPE)
 
 
 class AudioMediaManager(MediaManagerBase):
     human_readable = "Audio"
     processor = staticmethod(process_audio)
-    sniff_handler = staticmethod(sniff_handler)
     display_template = "mediagoblin/media_displays/audio.html"
-    accepted_extensions = ["mp3", "flac", "wav", "m4a"]
 
 
-MEDIA_MANAGER = AudioMediaManager
+def get_media_manager(media_type):
+    if media_type == MEDIA_TYPE:
+        return AudioMediaManager
+
+
+def get_media_type_and_manager(ext):
+    if ext in ACCEPTED_EXTENSIONS:
+        return MEDIA_TYPE, AudioMediaManager
+
+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 101b83e5f8ace58c20af65954c1eddbf6d665811..22383bc1918aec51729dea0a1ce01f5be7c39006 100644 (file)
@@ -27,19 +27,22 @@ from mediagoblin.media_types.audio.transcoders import (AudioTranscoder,
 
 _log = logging.getLogger(__name__)
 
+MEDIA_TYPE = 'mediagoblin.media_types.audio'
+
 
 def sniff_handler(media_file, **kw):
+    _log.info('Sniffing {0}'.format(MEDIA_TYPE))
     try:
         transcoder = AudioTranscoder()
         data = transcoder.discover(media_file.name)
     except BadMediaFail:
         _log.debug('Audio discovery raised BadMediaFail')
-        return False
+        return None
 
     if data.is_audio == True and data.is_video == False:
-        return True
+        return MEDIA_TYPE
 
-    return False
+    return None
 
 
 def process_audio(proc_state):