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,
+}
_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):