From a63b640f12896a873ebf96f9fe0ef62d0794bfe7 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Mon, 21 Nov 2011 00:06:59 +0100 Subject: [PATCH] Stashing changes --- mediagoblin/init/celery/__init__.py | 3 -- mediagoblin/media_types/__init__.py | 26 +++++----- mediagoblin/media_types/video/processing.py | 49 +++---------------- mediagoblin/media_types/video/transcoders.py | 1 - mediagoblin/process_media/__init__.py | 3 ++ mediagoblin/templates/mediagoblin/base.html | 7 +++ .../mediagoblin/media_displays/video.html | 18 ++++--- setup.py | 1 - 8 files changed, 43 insertions(+), 65 deletions(-) diff --git a/mediagoblin/init/celery/__init__.py b/mediagoblin/init/celery/__init__.py index 05c54b05..c5d37420 100644 --- a/mediagoblin/init/celery/__init__.py +++ b/mediagoblin/init/celery/__init__.py @@ -17,11 +17,8 @@ import os import sys -from mediagoblin.media_types import get_media_types - MANDATORY_CELERY_IMPORTS = ['mediagoblin.process_media'] -MANDATORY_CELERY_IMPORTS = [i for i in get_media_types()] print(MANDATORY_CELERY_IMPORTS) diff --git a/mediagoblin/media_types/__init__.py b/mediagoblin/media_types/__init__.py index 49d3ab9d..2d13f5a6 100644 --- a/mediagoblin/media_types/__init__.py +++ b/mediagoblin/media_types/__init__.py @@ -26,31 +26,33 @@ class FileTypeNotSupported(Exception): class InvalidFileType(Exception): pass +# This should be more dynamic in the future. Perhaps put it in the .ini? +# -- Joar MEDIA_TYPES = [ 'mediagoblin.media_types.image', 'mediagoblin.media_types.video'] def get_media_types(): + ''' + Generator that returns the available media types + ''' for media_type in MEDIA_TYPES: yield media_type def get_media_managers(): + ''' + Generator that returns all available media managers + ''' for media_type in get_media_types(): - ''' - FIXME - __import__ returns the lowest-level module. If the plugin is located - outside the conventional plugin module tree, it will not be loaded - properly because of the [...]ugin.media_types. - - We need this if we want to support a separate site-specific plugin - folder. - ''' try: __import__(media_type) except ImportError as e: - raise Exception('ERROR: Could not import {0}: {1}'.format(media_type, e)) + raise Exception( + _('ERROR: Could not import {media_type}: {exception}').format( + media_type=media_type, + exception=e)) yield media_type, sys.modules[media_type].MEDIA_MANAGER @@ -67,8 +69,8 @@ def get_media_type_and_manager(filename): ext = os.path.splitext(filename)[1].lower() else: raise InvalidFileType( - 'Could not find any file extension in "{0}"'.format( - filename)) + _('Could not find any file extension in "{filename}"').format( + filename=filename)) if ext[1:] in manager['accepted_extensions']: return media_type, manager diff --git a/mediagoblin/media_types/video/processing.py b/mediagoblin/media_types/video/processing.py index 027f527b..4e05a71c 100644 --- a/mediagoblin/media_types/video/processing.py +++ b/mediagoblin/media_types/video/processing.py @@ -15,25 +15,21 @@ # along with this program. If not, see . import tempfile -import pkg_resources -import os import logging +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.util import lazy_pass_to_ugettext as _ -from mediagoblin.process_media.errors import BaseProcessingFail, BadMediaFail +from mediagoblin.process_media import BaseProcessingFail from mediagoblin.process_media import mark_entry_failed from . import transcoders THUMB_SIZE = 180, 180 MEDIUM_SIZE = 640, 640 -loop = None # Is this even used? - logger = logging.getLogger(__name__) logging.basicConfig() logger.setLevel(logging.DEBUG) @@ -59,7 +55,11 @@ def process_video(entry): 'source') medium_filepath = create_pub_filepath( - entry, '640p.webm') + entry, + '{original}-640p.webm'.format( + original=os.path.splitext( + queued_filepath[-1])[0] # Select the + )) thumbnail_filepath = create_pub_filepath( entry, 'thumbnail.jpg') @@ -163,38 +163,3 @@ class ProcessMedia(Task): process_media = registry.tasks[ProcessMedia.name] - - -def mark_entry_failed(entry_id, exc): - """ - Mark a media entry as having failed in its conversion. - - Uses the exception that was raised to mark more information. If the - exception is a derivative of BaseProcessingFail then we can store extra - information that can be useful for users telling them why their media failed - to process. - - Args: - - entry_id: The id of the media entry - - """ - # Was this a BaseProcessingFail? In other words, was this a - # type of error that we know how to handle? - if isinstance(exc, BaseProcessingFail): - # Looks like yes, so record information about that failure and any - # metadata the user might have supplied. - mgg.database['media_entries'].update( - {'_id': entry_id}, - {'$set': {u'state': u'failed', - u'fail_error': exc.exception_path, - u'fail_metadata': exc.metadata}}) - else: - # Looks like no, so just mark it as failed and don't record a - # failure_error (we'll assume it wasn't handled) and don't record - # metadata (in fact overwrite it if somehow it had previous info - # here) - mgg.database['media_entries'].update( - {'_id': entry_id}, - {'$set': {u'state': u'failed', - u'fail_error': None, - u'fail_metadata': {}}}) diff --git a/mediagoblin/media_types/video/transcoders.py b/mediagoblin/media_types/video/transcoders.py index f6a2eb21..8d80beda 100644 --- a/mediagoblin/media_types/video/transcoders.py +++ b/mediagoblin/media_types/video/transcoders.py @@ -56,7 +56,6 @@ try: import pygst pygst.require('0.10') import gst - from gst import pbutils from gst.extend import discoverer except: raise Exception('gst/pygst 0.10 could not be found') diff --git a/mediagoblin/process_media/__init__.py b/mediagoblin/process_media/__init__.py index 2b9eed6e..96fe49fe 100644 --- a/mediagoblin/process_media/__init__.py +++ b/mediagoblin/process_media/__init__.py @@ -53,10 +53,13 @@ class ProcessMedia(Task): # Try to process, and handle expected errors. try: + __import__(entry['media_type']) process_image(entry) except BaseProcessingFail, exc: mark_entry_failed(entry[u'_id'], exc) return + except ImportError, exc: + mark_entry_failed(entry[u'_id'], exc) entry['state'] = u'processed' entry.save() diff --git a/mediagoblin/templates/mediagoblin/base.html b/mediagoblin/templates/mediagoblin/base.html index b4c4dcf3..bad22e7e 100644 --- a/mediagoblin/templates/mediagoblin/base.html +++ b/mediagoblin/templates/mediagoblin/base.html @@ -28,8 +28,15 @@ href="{{ request.staticdirect('/css/extlib/960_16_col.css') }}"/> + + + + {% block mediagoblin_head %} {% endblock mediagoblin_head %} diff --git a/mediagoblin/templates/mediagoblin/media_displays/video.html b/mediagoblin/templates/mediagoblin/media_displays/video.html index bff9889a..5b8ec789 100644 --- a/mediagoblin/templates/mediagoblin/media_displays/video.html +++ b/mediagoblin/templates/mediagoblin/media_displays/video.html @@ -1,11 +1,17 @@ {% extends 'mediagoblin/user_pages/media.html' %} {% block mediagoblin_media %} - +
+ +
{% if 'original' in media.media_files %}