Skip to content
Browse files

Merge branch 'feature/video' of github.com:nmfm/django-filer into fea…

…ture/video

Conflicts:
	filer/models/videomodels.py
  • Loading branch information...
2 parents 8304681 + 5926ff2 commit 0796ca63d756e51be3c271c122b6ffa9e77d5570 @nmfm committed
View
13 filer/models/videomodels.py
@@ -78,6 +78,19 @@ def formats(self):
pass
return _formats
+ def formats_html5(self):
+ """ Video formats supported by HTML5 browsers """
+ HTML5_FORMATS = ('mp4','ogv','webm')
+ _formats = []
+ for format, url in self.formats.items():
+ if format in HTML5_FORMATS:
+ _formats.append({'format':format, 'url':url})
+ return _formats
+
+ def format_flash(self):
+ """ Returns flash video file if available """
+ return self.formats.get('flv', None)
+
@property
def poster(self):
try:
View
2 filer/settings.py
@@ -115,7 +115,7 @@
# formats recognized as video file formats (no leading dot)
FILER_SOURCE_VIDEO_FORMATS = ('mp4', 'avi', 'wmv', 'mov', 'mpg')
# formats to convert into (no leading dot)
-FILER_VIDEO_FORMATS = ('flv', 'mp4')
+FILER_VIDEO_FORMATS = ('flv', 'mp4','ogv','webm')
# command line for video checking of dimensions
FFMPEG_CHECK_CMD = "ffmpeg -i %(input_file)s"
# command line for video conversion
View
BIN filer/static/filer/flash/flowplayer-3.2.7.swf
Binary file not shown.
View
BIN filer/static/filer/flash/flowplayer.controls-3.2.5.swf
Binary file not shown.
View
23 filer/templates/filer/video.html
@@ -0,0 +1,23 @@
+{% 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 -->
+<!-- warning: playback does not work on iOS3 if you include the poster attribute! fixed in iOS4.0 -->
+<video 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 }}' />
+ {% endfor %}
+
+ {% if video.format_flash %}
+ <!-- fallback to Flash: -->
+ <object width="{{ dimensions.0 }}" height="{{ dimensions.1 }}" type="application/x-shockwave-flash" data="{% filer_staticmedia_prefix %}flash/flowplayer-3.2.7.swf">
+ <!-- Firefox uses the `data` attribute above, IE/Safari uses the param below -->
+ <param name="movie" value="{% filer_staticmedia_prefix %}flash/flowplayer-3.2.7.swf" />
+ <param name="wmode" value="transparent" />
+ <param name="flashVars" value="config={'playlist':['/media/app24.png',{'url':'{{ video.format_flash }}','autoPlay':false}]}" />
+ <!-- fallback image. note the title field below, put the title of the video there -->
+ <img src="/media/app24.png" width="640" height="360" alt="__TITLE__"
+ title="No video playback capabilities, please download the video below" />
+ </object>
+ {% endif %}
+</video>
View
63 filer/templatetags/filer_video_tags.py
@@ -0,0 +1,63 @@
+import re
+import types
+from django.template import Library, Node, VariableDoesNotExist, \
+ TemplateSyntaxError
+
+register = Library()
+
+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):
+ """
+ Creates HTML5 video tag with the alternative video formats and fallback to
+ flash if that format is available.
+
+ Tag Syntax
+
+ {% filer_video [source] [dimensions] %}
+
+ *source* must be a Django Filer video object
+
+ *dimensions* is the display width and height and can be a string with
+ ``[width]x[height]`` (for example ``{% filer_video obj 320x240 %}``) or
+ a tuple variable with two integers. If no display dimensions are given
+ the movie dimensions are used.
+ """
+ tag_syntax_error = False
+ if dimensions:
+ if type(dimensions) == types.TupleType:
+ if len(dimensions) != 2:
+ tag_syntax_error = True
+ else:
+ match = RE_DIMENSIONS.match(size)
+ if not match or len(match.groups()) != 2:
+ tag_syntax_error = True
+ else:
+ dimensions = map(int, match.groups())
+ else:
+ try:
+ dimensions = (source.width, source.height)
+ except:
+ tag_syntax_error
+
+ if tag_syntax_error:
+ raise TemplateSyntaxError("Invalid syntax. Expected "
+ "'{%% %s source [dimensions] %%}'" % tag)
+ return {'video': source, 'dimensions': dimensions}
+
+
+
+register.inclusion_tag('filer/video.html')(filer_video)

0 comments on commit 0796ca6

Please sign in to comment.
Something went wrong with that request. Please try again.