From: Christopher Allan Webber Date: Sun, 3 Mar 2013 01:06:31 +0000 (-0600) Subject: Huge amount of work to (mostly) allow .ogg (and maybe other) formats to skip transcode X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ddbf6af1e20222882a7ce559804ed48f4ad31a92;p=mediagoblin.git Huge amount of work to (mostly) allow .ogg (and maybe other) formats to skip transcode - Update get_display_media in several ways: - now uses the media type's own declaration of the order of things - returns both the media_size and the media_path, as per the docstring - implicitly uses self.media_files as opposed to forcing you to pass it in - update videos to use get_display_media - update images to declare media_fetch_order in the media manager (videos also) - update stl to use media.media_files['original'] instead of weird use of get_display_media - update sidebar to only conditionally show webm_640 TODO still: identify video type information *during* processing, show that in the element. This commit sponsored by Nathan Yergler. Thanks, nyergler! --- diff --git a/mediagoblin/db/mixin.py b/mediagoblin/db/mixin.py index 6789a970..c4bd806c 100644 --- a/mediagoblin/db/mixin.py +++ b/mediagoblin/db/mixin.py @@ -126,24 +126,30 @@ class MediaEntryMixin(object): """ return cleaned_markdown_conversion(self.description) - def get_display_media(self, media_map, - fetch_order=common.DISPLAY_IMAGE_FETCHING_ORDER): + def get_display_media(self, fetch_order=None): """ Find the best media for display. Args: - - media_map: a dict like - {u'image_size': [u'dir1', u'dir2', u'image.jpg']} - - fetch_order: the order we should try fetching images in + - fetch_order: the order we should try fetching images in. + If this isn't supplied, we try checking + self.media_data.fetching_order if it exists. Returns: - (media_size, media_path) + (media_size, media_path) + or, if not found, None. """ - media_sizes = media_map.keys() + fetch_order = self.media_manager.get("media_fetch_order") - for media_size in common.DISPLAY_IMAGE_FETCHING_ORDER: + # No fetching order found? well, give up! + if not fetch_order: + return None + + media_sizes = self.media_files.keys() + + for media_size in fetch_order: if media_size in media_sizes: - return media_map[media_size] + return media_size, self.media_files[media_size] def main_mediafile(self): pass diff --git a/mediagoblin/media_types/image/__init__.py b/mediagoblin/media_types/image/__init__.py index 36d7c201..3e167db1 100644 --- a/mediagoblin/media_types/image/__init__.py +++ b/mediagoblin/media_types/image/__init__.py @@ -25,4 +25,8 @@ MEDIA_MANAGER = { "sniff_handler": sniff_handler, "display_template": "mediagoblin/media_displays/image.html", "default_thumb": "images/media_thumbs/image.png", - "accepted_extensions": ["jpg", "jpeg", "png", "gif", "tiff"]} + "accepted_extensions": ["jpg", "jpeg", "png", "gif", "tiff"], + + # Used by the media_entry.get_display_media method + "media_fetch_order": [u'medium', u'original', u'thumb'], +} diff --git a/mediagoblin/media_types/video/__init__.py b/mediagoblin/media_types/video/__init__.py index 3faa5b9f..fd364c02 100644 --- a/mediagoblin/media_types/video/__init__.py +++ b/mediagoblin/media_types/video/__init__.py @@ -26,4 +26,8 @@ MEDIA_MANAGER = { "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"]} + "mp4", "mov", "webm", "avi", "3gp", "3gpp", "mkv", "ogv", "m4v"], + + # Used by the media_entry.get_display_media method + "media_fetch_order": [u'webm_640', u'original'], +} diff --git a/mediagoblin/templates/mediagoblin/media_displays/stl.html b/mediagoblin/templates/mediagoblin/media_displays/stl.html index 043faac8..a89e0b4f 100644 --- a/mediagoblin/templates/mediagoblin/media_displays/stl.html +++ b/mediagoblin/templates/mediagoblin/media_displays/stl.html @@ -23,7 +23,7 @@ {% set model_download = request.app.public_store.file_url( - media.get_display_media(media.media_files)) %} + media.media_files['original']) %} {% set perspective_view = request.app.public_store.file_url( media.media_files['perspective']) %} {% set top_view = request.app.public_store.file_url( diff --git a/mediagoblin/templates/mediagoblin/media_displays/video.html b/mediagoblin/templates/mediagoblin/media_displays/video.html index 9eeb7c85..2e33e1a3 100644 --- a/mediagoblin/templates/mediagoblin/media_displays/video.html +++ b/mediagoblin/templates/mediagoblin/media_displays/video.html @@ -33,7 +33,7 @@ data-setup='{"height": {{ media.media_data.height }}, "width": {{ media.media_data.width }} }'>
{%- trans -%}Sorry, this video will not work because @@ -53,7 +53,9 @@
  • {% trans %}Original file{% endtrans %} {% endif %} -
  • {% trans %}WebM file (640p; VP8/Vorbis){% endtrans %} + {% if 'webm_640' in media.media_files %} +
  • {% trans %}WebM file (640p; VP8/Vorbis){% endtrans %} + {% endif %} {% endblock %} diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html index f151c577..b77c12b9 100644 --- a/mediagoblin/templates/mediagoblin/user_pages/media.html +++ b/mediagoblin/templates/mediagoblin/user_pages/media.html @@ -47,7 +47,7 @@
    {% block mediagoblin_media %} {% set display_media = request.app.public_store.file_url( - media.get_display_media(media.media_files)) %} + media.get_display_media()[1]) %} {# if there's a medium file size, that means the medium size # isn't the original... so link to the original! #} diff --git a/mediagoblin/tools/common.py b/mediagoblin/tools/common.py index c9f9d032..34586611 100644 --- a/mediagoblin/tools/common.py +++ b/mediagoblin/tools/common.py @@ -16,7 +16,6 @@ import sys -DISPLAY_IMAGE_FETCHING_ORDER = [u'medium', u'original', u'thumb'] global TESTS_ENABLED TESTS_ENABLED = False