Permalink
Browse files

mimetypes in videos

  • Loading branch information...
1 parent 3e6597f commit d39796dc1071d31996e6070ffa15ab93014c7dfc @pvl pvl committed Oct 27, 2011
Showing with 15 additions and 27 deletions.
  1. +1 −2 docs/usage.rst
  2. +6 −4 filer/models/videomodels.py
  3. +3 −3 filer/templates/filer/video.html
  4. +5 −18 filer/templatetags/filer_video_tags.py
View
@@ -78,8 +78,7 @@ and fallback to flash if the flash format is available, and link to the poster
image. The filer_video tag can accept optional dimensions parameter for the
display window (otherwise uses the video dimensions).
-
- {% filer_video video_obj 640x480 %}
+ {% filer_video video_obj "640x480" %}
Note: if ffmpeg is not available for converting the videos, the dimensions of
the uploaded video are not extracted from the file and so they need to be set
@@ -1,5 +1,6 @@
#-*- coding: utf-8 -*-
import os
+import mimetypes
from django.db import models
from django.utils.translation import ugettext_lazy as _
from filer import settings as filer_settings
@@ -82,16 +83,17 @@ def formats(self):
def original_format(self):
url = self.file.storage.url(self.file.name)
name, ext = os.path.splitext(self.file.name)
+ mimetype = mimetypes.guess_type(self.file.name)[0]
format = ext.replace('.','')
- return {'url':url, 'format':format}
+ return {'url':url, 'format':format, 'mimetype':mimetype}
def formats_html5(self):
""" Video formats supported by HTML5 browsers """
- HTML5_FORMATS = ('mp4','ogv','webm')
+ HTML5_FORMATS = {'mp4':'video/mp4', 'ogv':'video/ogg','webm':'video/webm'}
_formats = []
for format, url in self.formats.items():
- if format in HTML5_FORMATS:
- _formats.append({'format':format, 'url':url})
+ if format in HTML5_FORMATS.keys():
+ _formats.append({'format':format, 'url':url, 'mimetype': HTML5_FORMATS[format]})
return _formats
def format_flash(self):
@@ -1,12 +1,12 @@
{% load filermedia %}
<!-- from: http://camendesign.com/code/video_for_everybody -->
<!-- first try HTML5 playback: if serving as XML, expand `controls` to `controls="controls"` and autoplay likewise -->
-<video {% if poster %} poster="{{ video.poster }}"{% endif %} width="{{ dimensions.0 }}" height="{{ dimensions.1 }}" controls>
+<video {% if video.poster %} poster="{{ video.poster }}"{% endif %} width="{{ dimensions.0 }}" height="{{ dimensions.1 }}" controls>
<!-- MP4 must be first for iPad! -->
{% for fileformat in video.formats_html5 %}
- <source src="{{ fileformat.url }}" type='video/{{ fileformat.format }}' />
+ <source src="{{ fileformat.url }}" type='{{ fileformat.mimetype }}' />
{% empty %}
- <source src="{{ video.original_format.url }}" type='video/{{ video.original_format.format }}' />
+ <source src="{{ video.original_format.url }}" type='{{ video.original_format.mimetype }}' />
{% endfor %}
{% if video.format_flash %}
@@ -7,20 +7,8 @@
RE_DIMENSIONS = re.compile(r'(\d+)x(\d+)$')
-class FilerVideoNode(Node):
- def __init__(self, source_var, opts, context_name=None):
- self.source_var = source_var
- self.opts = opts
- self.context_name = context_name
-
- def render(self, context):
- try:
- source = self.source_var.resolve(context)
- except VariableDoesNotExist:
- return ''
-
-def filer_video(source, dimensions=None):
+def filer_video(source, video_dimensions=None):
"""
Creates HTML5 video tag with the alternative video formats and fallback to
flash if that format is available.
@@ -37,12 +25,12 @@ def filer_video(source, dimensions=None):
the movie dimensions are used.
"""
tag_syntax_error = False
- if dimensions:
- if type(dimensions) == types.TupleType:
- if len(dimensions) != 2:
+ if video_dimensions:
+ if type(video_dimensions) == types.TupleType:
+ if len(video_dimensions) != 2:
tag_syntax_error = True
else:
- match = RE_DIMENSIONS.match(size)
+ match = RE_DIMENSIONS.match(video_dimensions)
if not match or len(match.groups()) != 2:
tag_syntax_error = True
else:
@@ -59,5 +47,4 @@ def filer_video(source, dimensions=None):
return {'video': source, 'dimensions': dimensions}
-
register.inclusion_tag('filer/video.html')(filer_video)

0 comments on commit d39796d

Please sign in to comment.