jazzband / django-embed-video

Django app for easy embedding YouTube and Vimeo videos and music from SoundCloud.
http://django-embed-video.rtfd.org
MIT License
382 stars 135 forks source link

Support for `empty` syntax in template tag #35

Closed yetty closed 7 years ago

yetty commented 10 years ago

Proposal:

{% load embed_video_tags %}
{% video object.video as my_video %}
    Video has been found.
{% empty %}
    Video doesn't exist.
{% endvideo %}
cubicova17 commented 9 years ago

@yetty how would you recommend to implement it until v1.o realise?

SalahAdDin commented 9 years ago

Wow, this will be very useful, thank you!

yetty commented 9 years ago

The simpliest way is to get info in views. But it is supported only for Vimeo and SoundCloud backend. YouTube backend doesn't support it yet.

def my_view(...):
   ...
   video = detect_backend(url)
   try:
       video.get_info()
   except NotImplementedError:
       pass
   except VideoDoesntExistException: 
       # video doesnt exist
       video = None
   ...