From 4535f7597f112443d8997bbd6b8a445612c2440d Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Tue, 6 Dec 2011 23:05:47 +0100 Subject: Bug 681 - Comments from reviewing the new video merge in mediagoblin.media_types and submodules - Moved VideoThumbnailer.errors initialization to VideoThumbnailer.__init__ - Cleaned up the image.processing imports - Removed default ``None`` from get_media_manager(_media_type) in mediagoblin.views - Removed media_types import - Removed sys import, and passing of sys to root.html template --- mediagoblin/media_types/__init__.py | 21 ++++++++++++++++++--- mediagoblin/media_types/image/processing.py | 9 ++------- mediagoblin/media_types/video/transcoders.py | 4 ++-- 3 files changed, 22 insertions(+), 12 deletions(-) (limited to 'mediagoblin/media_types') diff --git a/mediagoblin/media_types/__init__.py b/mediagoblin/media_types/__init__.py index 61786562..4fa56bc3 100644 --- a/mediagoblin/media_types/__init__.py +++ b/mediagoblin/media_types/__init__.py @@ -30,7 +30,7 @@ class InvalidFileType(Exception): def get_media_types(): """ - Generator that returns the available media types + Generator, yields the available media types """ for media_type in mg_globals.app_config['media_types']: yield media_type @@ -38,7 +38,7 @@ def get_media_types(): def get_media_managers(): ''' - Generator that returns all available media managers + Generator, yields all enabled media managers ''' for media_type in get_media_types(): __import__(media_type) @@ -46,20 +46,35 @@ def get_media_managers(): yield media_type, sys.modules[media_type].MEDIA_MANAGER -def get_media_manager(_media_type = None): +def get_media_manager(_media_type): + ''' + Get the MEDIA_MANAGER based on a media type string + + Example:: + get_media_type('mediagoblin.media_types.image') + ''' + if not _media_type: + return False + for media_type, manager in get_media_managers(): if media_type in _media_type: return manager def get_media_type_and_manager(filename): + ''' + Get the media type and manager based on a filename + ''' for media_type, manager in get_media_managers(): if filename.find('.') > 0: + # Get the file extension ext = os.path.splitext(filename)[1].lower() else: raise InvalidFileType( _('Could not find any file extension in "{filename}"').format( filename=filename)) + # Omit the dot from the extension and match it against + # the media manager if ext[1:] in manager['accepted_extensions']: return media_type, manager diff --git a/mediagoblin/media_types/image/processing.py b/mediagoblin/media_types/image/processing.py index 5b8259fc..e493eb2b 100644 --- a/mediagoblin/media_types/image/processing.py +++ b/mediagoblin/media_types/image/processing.py @@ -17,15 +17,10 @@ import Image import os -from celery.task import Task -from celery import registry - -from mediagoblin.db.util import ObjectId from mediagoblin import mg_globals as mgg -from mediagoblin.processing import BaseProcessingFail, \ - mark_entry_failed, BadMediaFail, create_pub_filepath, THUMB_SIZE, \ - MEDIUM_SIZE +from mediagoblin.processing import BadMediaFail, \ + create_pub_filepath, THUMB_SIZE, MEDIUM_SIZE ################################ # Media processing initial steps diff --git a/mediagoblin/media_types/video/transcoders.py b/mediagoblin/media_types/video/transcoders.py index d7ed14ca..7071b887 100644 --- a/mediagoblin/media_types/video/transcoders.py +++ b/mediagoblin/media_types/video/transcoders.py @@ -74,14 +74,14 @@ class VideoThumbnailer: buffer_probes = {} - errors = [] - def __init__(self, source_path, dest_path): ''' Set up playbin pipeline in order to get video properties. Initializes and runs the gobject.MainLoop() ''' + self.errors = [] + self.source_path = source_path self.dest_path = dest_path -- cgit v1.2.3