Add property to media_fetch_order
[mediagoblin.git] / mediagoblin / media_types / video / __init__.py
index 569cf11a3525b9529160c988636e72a3e2047adb..ea7bc0217675d1314a08f5f41d9bbfb41fdfb189 100644 (file)
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+from mediagoblin import mg_globals as mgg
 from mediagoblin.media_types import MediaManagerBase
-from mediagoblin.media_types.video.processing import process_video, \
-    sniff_handler
+from mediagoblin.media_types.video.processing import (VideoProcessingManager,
+        sniff_handler, sniffer)
+
+
+MEDIA_TYPE = 'mediagoblin.media_types.video'
+ACCEPTED_EXTENSIONS = [
+        "mp4", "mov", "webm", "avi", "3gp", "3gpp", "mkv", "ogv", "m4v"]
 
 
 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"]
-        
+    type_icon = "images/type_icons/video.png"
+
     # 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"'
 
+    @property
+    def media_fetch_order(self):
+        video_config = mgg.global_config['plugins'][MEDIA_TYPE]
+        video_res = video_config['available_resolutions']
+        video_res.remove(video_config['default_resolution'])
+        video_res.insert(0, video_config['default_resolution'])
+        video_res = map((lambda x: unicode('webm_' + str(x), 'utf-8')), video_res)
+        return ([u'webm_video'] + video_res + [u'original'])
+
+
+def get_media_type_and_manager(ext):
+    if ext in ACCEPTED_EXTENSIONS:
+        return MEDIA_TYPE, VideoMediaManager
+
+def type_match_handler(ext):
+    if ext in ACCEPTED_EXTENSIONS:
+        return MEDIA_TYPE, VideoMediaManager, sniffer
 
-MEDIA_MANAGER = VideoMediaManager
+hooks = {
+    'type_match_handler': type_match_handler,
+    'sniff_handler': sniff_handler,
+    ('media_manager', MEDIA_TYPE): lambda: VideoMediaManager,
+    ('reprocess_manager', MEDIA_TYPE): lambda: VideoProcessingManager,
+}