Skip to content

Commit

Permalink
Merge branch 'feature/video' of github.com:nmfm/django-filer into fea…
Browse files Browse the repository at this point in the history
…ture/video

Conflicts:
	filer/models/videomodels.py
  • Loading branch information
nmfm committed Oct 27, 2011
2 parents 7b5815e + 4808555 commit 9ee477e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 29 deletions.
3 changes: 1 addition & 2 deletions docs/usage.rst
Expand Up @@ -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 image. The filer_video tag can accept optional dimensions parameter for the
display window (otherwise uses the video dimensions). 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 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 the uploaded video are not extracted from the file and so they need to be set
Expand Down
12 changes: 7 additions & 5 deletions filer/models/videomodels.py
@@ -1,5 +1,6 @@
#-*- coding: utf-8 -*- #-*- coding: utf-8 -*-
import os import os
import mimetypes
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from filer import settings as filer_settings from filer import settings as filer_settings
Expand Down Expand Up @@ -82,16 +83,17 @@ def formats(self):
def original_format(self): def original_format(self):
url = self.file.storage.url(self.file.name) url = self.file.storage.url(self.file.name)
name, ext = os.path.splitext(self.file.name) name, ext = os.path.splitext(self.file.name)
fmt = ext.replace('.','') mimetype = mimetypes.guess_type(self.file.name)[0]
return {'url':url, 'format':fmt} fmt = ext.replace('.', '')
return {'url': url, 'format': fmt, 'mimetype': mimetype}


def formats_html5(self): def formats_html5(self):
""" Video formats supported by HTML5 browsers """ """ Video formats supported by HTML5 browsers """
HTML5_FORMATS = ('mp4', 'ogv', 'webm') HTML5_FORMATS = {'mp4':'video/mp4', 'ogv':'video/ogg','webm':'video/webm'}
_formats = [] _formats = []
for fmt, url in self.formats.items(): for fmt, url in self.formats.items():
if fmt in HTML5_FORMATS: if fmt in HTML5_FORMATS.keys():
_formats.append({'format': fmt, 'url': url}) _formats.append({'format': fmt, 'url': url, 'mimetype': HTML5_FORMATS[format]})
return _formats return _formats


def format_flash(self): def format_flash(self):
Expand Down
8 changes: 4 additions & 4 deletions filer/templates/filer/video.html
@@ -1,12 +1,12 @@
{% load filermedia %} {% load filermedia %}
<!-- from: http://camendesign.com/code/video_for_everybody --> <!-- from: http://camendesign.com/code/video_for_everybody -->
<!-- first try HTML5 playback: if serving as XML, expand `controls` to `controls="controls"` and autoplay likewise --> <!-- 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! --> <!-- MP4 must be first for iPad! -->
{% for fileformat in video.formats_html5 %} {% for fileformat in video.formats_html5 %}
<source src="{{ fileformat.url }}" type='video/{{ fileformat.format }}' /> <source src="{{ fileformat.url }}" type='{{ fileformat.mimetype }}' />
{% empty %} {% 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 %} {% endfor %}


{% if video.format_flash %} {% if video.format_flash %}
Expand All @@ -17,7 +17,7 @@
<param name="wmode" value="transparent" /> <param name="wmode" value="transparent" />
<param name="flashVars" value="config={'playlist':['{{ video.poster }}',{'url':'{{ video.format_flash }}','autoPlay':false}]}" /> <param name="flashVars" value="config={'playlist':['{{ video.poster }}',{'url':'{{ video.format_flash }}','autoPlay':false}]}" />
<!-- fallback image. note the title field below, put the title of the video there --> <!-- fallback image. note the title field below, put the title of the video there -->
<img src="{{ video.poster }}" alt="{{ video.default_alt_text }}" <img src="{{ video.poster }}" alt="{{ video.default_alt_text|default_if_none:'' }}"
title="No video playback capabilities" /> title="No video playback capabilities" />
</object> </object>
{% endif %} {% endif %}
Expand Down
23 changes: 5 additions & 18 deletions filer/templatetags/filer_video_tags.py
Expand Up @@ -7,20 +7,8 @@


RE_DIMENSIONS = re.compile(r'(\d+)x(\d+)$') 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 Creates HTML5 video tag with the alternative video formats and fallback to
flash if that format is available. flash if that format is available.
Expand All @@ -37,12 +25,12 @@ def filer_video(source, dimensions=None):
the movie dimensions are used. the movie dimensions are used.
""" """
tag_syntax_error = False tag_syntax_error = False
if dimensions: if video_dimensions:
if type(dimensions) == types.TupleType: if type(video_dimensions) == types.TupleType:
if len(dimensions) != 2: if len(video_dimensions) != 2:
tag_syntax_error = True tag_syntax_error = True
else: else:
match = RE_DIMENSIONS.match(size) match = RE_DIMENSIONS.match(video_dimensions)
if not match or len(match.groups()) != 2: if not match or len(match.groups()) != 2:
tag_syntax_error = True tag_syntax_error = True
else: else:
Expand All @@ -59,5 +47,4 @@ def filer_video(source, dimensions=None):
return {'video': source, 'dimensions': dimensions} return {'video': source, 'dimensions': dimensions}





register.inclusion_tag('filer/video.html')(filer_video) register.inclusion_tag('filer/video.html')(filer_video)

0 comments on commit 9ee477e

Please sign in to comment.