Browse Source

Colocando iframe do youtube na tela de detalhes da sessao (#2838)

* Adicionando suporte de video youtube e facebook

* melhorando regex video do facebook

* Resolvendo erros e melhorias relatados no pr
pull/2761/head
Ulysses Lara 6 years ago
committed by Edward
parent
commit
d35f5ec2fc
  1. 28
      sapl/base/templatetags/common_tags.py
  2. 17
      sapl/templates/crud/detail.html

28
sapl/base/templatetags/common_tags.py

@ -223,8 +223,32 @@ def audio_url(value):
@register.filter @register.filter
def video_url(value): def is_video_url(value):
return True if url(value) and value.endswith("mp4") else False video_extensions = ["mp4", "ogg", "webm", "3gp", "ogv"]
has_ext = any([value.endswith(i) for i in video_extensions])
return url(value) and has_ext
@register.filter
def youtube_url(value):
# Test if YouTube video
# tested on https://pythex.org/
youtube_pattern = "^(http://?|https://?www\.?youtube\.com/watch\?v=)"
r = re.findall(youtube_pattern, value)
return True if r else False
@register.filter
def facebook_url(value):
facebook_pattern = "^(http://?|https://?(www?|pt-br?)\.facebook\.com/(.*?)/videos/(.*?))"
r = re.findall(facebook_pattern, value)
return True if r else False
@register.filter
def youtube_id(value):
from urllib.parse import urlparse, parse_qs
u_pars = urlparse(value)
quer_v = parse_qs(u_pars.query).get('v')[0]
return quer_v
@register.filter @register.filter

17
sapl/templates/crud/detail.html

@ -72,13 +72,21 @@
<p>Este navegador não suporta o elemento áudio.</p> <p>Este navegador não suporta o elemento áudio.</p>
</audio> </audio>
</div> </div>
{% elif column.text|video_url %} {% elif column.text|is_video_url %}
<div class="form-control-static"> <div class="form-control-static">
<video width="320" height="120" controls> <video width="420" height="230" controls>
<source src="{{ column.text|safe }}" type="video/{{ column.text|file_extension }}"> <source src="{{ column.text|safe }}" type="video/{{ column.text|file_extension }}">
<p>Este navegador não suporta o elemento vídeo.</p> <p>Este navegador não suporta o elemento vídeo.</p>
</video> </video>
</div> </div>
{% elif column.text|youtube_url %}
<iframe id="ytplayer" type="text/html" width="420" height="230"
src="http://www.youtube.com/embed/{{ column.text|youtube_id }}"
frameborder="0"></iframe>
{% elif column.text|facebook_url %}
<div class="fb-video" data-href="{{ column.text|safe }}"
data-width="420" data-show-text="false">
</div>
{% elif column.text|url %} {% elif column.text|url %}
<div class="form-control-static"><a href="{{ column.text|safe }}"> {{ column.text|safe|default:"" }} </a></div> <div class="form-control-static"><a href="{{ column.text|safe }}"> {{ column.text|safe|default:"" }} </a></div>
{% else %} {% else %}
@ -131,4 +139,7 @@
{% endblock table_content %} {% endblock table_content %}
{% endblock base_content %} {% endblock base_content %}
{% block extra_js %}{% endblock %} {% block extra_js %}
<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v3.3"></script>
{% endblock %}

Loading…
Cancel
Save