diff --git a/INSTALL.txt b/INSTALL.txt index 279546c..2ccf37b 100644 --- a/INSTALL.txt +++ b/INSTALL.txt @@ -32,6 +32,15 @@ looking at this usage: {% oembed 320x240 %} +Check if video exists before printing on the DOM +{% if video_url|is_video:video_url %} + {% oembed %} + Video url + {% endoembed %} +{% else %} + Some Default Video/Image +{% endif %} + Note that this application requires Python 2.3 or later, and Django later than 0.96. You can obtain Python from http://www.python.org/ and Django from http://www.djangoproject.com/. \ No newline at end of file diff --git a/oembed/templatetags/oembed_tags.py b/oembed/templatetags/oembed_tags.py index 2b1dcba..1252190 100644 --- a/oembed/templatetags/oembed_tags.py +++ b/oembed/templatetags/oembed_tags.py @@ -58,3 +58,11 @@ def render(self, context): kwargs['max_width'] = self.width kwargs['max_height'] = self.height return replace(self.nodelist.render(context), **kwargs) + +@register.filter +def is_video(object, link): + iframe = replace(link).find('iframe') + if iframe == 1: + return True + else: + return False