aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2013-03-03 11:41:40 -0600
committerChristopher Allan Webber <cwebber@dustycloud.org>2013-03-03 11:41:40 -0600
commit787aafd64482de3a4d150c75ffec024e8e11f287 (patch)
tree21f1be831ed3ed059e6b60f5fcc01ed51956d87a
parentb35dfd3271bb40168b3d8c9335238715584eac02 (diff)
downloadmediagoblin-787aafd64482de3a4d150c75ffec024e8e11f287.tar.lz
mediagoblin-787aafd64482de3a4d150c75ffec024e8e11f287.tar.xz
mediagoblin-787aafd64482de3a4d150c75ffec024e8e11f287.zip
Extrapolate type= based on the video metadata that we have, if we can.
It's kind of awkward because it relies on there being a entry.media_data, but that's not guaranteed... (see http://issues.mediagoblin.org/ticket/650) so we use a dopey fallback in the template in that case (kind of annoying info duplication). This commit sponsored by Piotr Wieczorek. Thank you!
-rw-r--r--mediagoblin/media_types/video/models.py29
-rw-r--r--mediagoblin/media_types/video/util.py1
-rw-r--r--mediagoblin/templates/mediagoblin/media_displays/video.html6
3 files changed, 34 insertions, 2 deletions
diff --git a/mediagoblin/media_types/video/models.py b/mediagoblin/media_types/video/models.py
index e0043718..4639b8c8 100644
--- a/mediagoblin/media_types/video/models.py
+++ b/mediagoblin/media_types/video/models.py
@@ -26,6 +26,8 @@ from mediagoblin.db.extratypes import JSONEncoded
BACKREF_NAME = "video__media_data"
+DEFAULT_WEBM_TYPE = 'video/webm; codecs="vp8, vorbis"'
+
class VideoData(Base):
"""
Attributes:
@@ -57,6 +59,33 @@ class VideoData(Base):
orig_metadata = Column(JSONEncoded)
+ def source_type(self):
+ """
+ Construct a useful type=... that is to say, used like:
+ <video><source type="{{ entry.media_data.source_type() }}" /></video>
+
+ Try to construct it out of self.orig_metadata... if we fail we
+ just dope'ily fall back on DEFAULT_WEBM_TYPE
+ """
+ orig_metadata = self.orig_metadata or {}
+
+ if "webm_640" not in self.get_media_entry.media_files \
+ and "mimetype" in orig_metadata \
+ and "tags" in orig_metadata \
+ and "audio-codec" in orig_metadata["tags"] \
+ and "video-codec" in orig_metadata["tags"]:
+ if orig_metadata['mimetype'] == 'application/ogg':
+ # stupid ambiguous .ogg extension
+ mimetype = "video/ogg"
+ else:
+ mimetype = orig_metadata['mimetype']
+ return '%s; codecs="%s, %s"' % (
+ mimetype,
+ orig_metadata["tags"]["video-codec"].lower(),
+ orig_metadata["tags"]["audio-codec"].lower())
+ else:
+ return DEFAULT_WEBM_TYPE
+
DATA_MODEL = VideoData
MODELS = [VideoData]
diff --git a/mediagoblin/media_types/video/util.py b/mediagoblin/media_types/video/util.py
index 93f098f7..5765ecfb 100644
--- a/mediagoblin/media_types/video/util.py
+++ b/mediagoblin/media_types/video/util.py
@@ -57,4 +57,3 @@ def skip_transcode(metadata):
return False
return True
-
diff --git a/mediagoblin/templates/mediagoblin/media_displays/video.html b/mediagoblin/templates/mediagoblin/media_displays/video.html
index d30c6a2b..dc0c7b55 100644
--- a/mediagoblin/templates/mediagoblin/media_displays/video.html
+++ b/mediagoblin/templates/mediagoblin/media_displays/video.html
@@ -35,7 +35,11 @@
data-setup='{"height": {{ media.media_data.height }},
"width": {{ media.media_data.width }} }'>
<source src="{{ request.app.public_store.file_url(display_path) }}"
- type="video/webm; codecs=&quot;vp8, vorbis&quot;" />
+ {% if media.media_data %}
+ type="{{ media.media_data.source_type() }}"
+ {% else %}
+ type="video/webm; codecs=&quot;vp8, vorbis&quot;"
+ {% endif %} />
<div class="no_html5">
{%- trans -%}Sorry, this video will not work because
your web browser does not support HTML5