Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding in video image template tag.

  • Loading branch information...
commit 7ccf91dd1df1add014514ef663b553fb29528163 1 parent 63785b7
@etianen authored
View
20 src/optimizations/templatetags/assets.py
@@ -10,6 +10,7 @@
from optimizations.javascriptcache import default_javascript_cache
from optimizations.stylesheetcache import default_stylesheet_cache
from optimizations.templatetags import simple_tag, inclusion_tag, assignment_tag
+from optimizations.videocache import default_video_cache, PROPORTIONAL as VIDEO_PROPORTIONAL, JPEG_FORMAT, VideoError
register = template.Library()
@@ -59,6 +60,25 @@ def img(src, width=None, height=None, method=PROPORTIONAL, alt="", **attrs):
return params
+@inclusion_tag(register, "assets/img.html")
+@assignment_tag(register, name="get_video_img")
+def video_img(src, width, height, method=VIDEO_PROPORTIONAL, alt="", **attrs):
+ """Renders an image tag from the given video."""
+ params = {
+ "alt": alt,
+ "attrs": attrs,
+ "width": width,
+ "height": height,
+ }
+ try:
+ url = default_video_cache.get_url(src, width, height, method, format=JPEG_FORMAT)
+ except VideoError:
+ asset = AdaptiveAsset(src)
+ url = asset.get_url(),
+ params["url"] = url
+ return params
+
+
def is_url(s):
"""Checks if the given string is a URL."""
if not isinstance(s, basestring):
View
12 src/optimizations/videocache.py
@@ -187,7 +187,7 @@ def __init__(self, asset_cache=default_asset_cache):
"""Initializes the video cache."""
self._asset_cache = asset_cache
- def get_video(self, asset, width=None, height=None, method=PAD, format=MP4_FORMAT, offset=None):
+ def _get_video_asset(self, asset, width=None, height=None, method=PAD, format=MP4_FORMAT, offset=None):
"""
Returns a processed video from the given video.
"""
@@ -210,7 +210,15 @@ def get_video(self, asset, width=None, height=None, method=PAD, format=MP4_FORMA
# Adapt the asset.
asset = AdaptiveAsset(asset)
# Create the video.
- return self._asset_cache.get_path(VideoAsset(asset, width, height, method, format, offset), force_save=True)
+ return VideoAsset(asset, width, height, method, format, offset)
+
+ def get_path(self, *args, **kwargs):
+ """Returns the path of the given video asset."""
+ return self._asset_cache.get_path(self._get_video_asset(*args, **kwargs), force_save=True)
+
+ def get_url(self, *args, **kwargs):
+ """Returns the URL of the given video asset."""
+ return self._asset_cache.get_url(self._get_video_asset(*args, **kwargs), force_save=True)
# The default video cache.
Please sign in to comment.
Something went wrong with that request. Please try again.