Commit 9576abd6 authored by gijs's avatar gijs
Browse files

Support for vimeo videos

parent b10570a4
......@@ -13,6 +13,8 @@ from django.utils.safestring import mark_safe
from generator.settings import SITE_URL
VIMEO_VIDEO_URL_PATTERN = re.compile('https:\/\/(?:player\.|www\.)?vimeo\.com\/(?:video\/)?(\d+)', re.I)
"""
- Alternatively: make and register models before parsing their fields.
Then unknown resources / objects are easier to spot.
......@@ -947,11 +949,23 @@ class Video (Model):
contentType = 'video'
keyField = 'video'
labelField = 'video'
@property
def vimeoId (self):
# Find more elegant solution?
video = self.video.value
if video:
m = VIMEO_VIDEO_URL_PATTERN.match(video)
if m:
return m.group(1)
return None
def _metadataFields (self):
return {
'video': fields.Single(fields.StringField()),
'type': fields.Single(fields.StringField()),
'type': fields.Single(fields.StringField(['video/mp4'])),
'title': fields.Single(fields.InlineMarkdownField()),
'caption': fields.Single(fields.InlineMarkdownField()),
'tags': multiLinkMultiReverse('tag', 'video'),
......@@ -966,7 +980,7 @@ class Audio (Model):
def _metadataFields (self):
return {
'audio': fields.Single(fields.StringField()),
'type': fields.Single(fields.StringField()),
'type': fields.Single(fields.StringField(['audio/mp3'])),
'title': fields.Single(fields.InlineMarkdownField()),
'caption': fields.Single(fields.InlineMarkdownField()),
'tags': multiLinkMultiReverse('tag', 'audio'),
......
<section class="video">
<video controls>
<source src="{{ video.video }}" type="{% if video.type %}{{ video.type }}{% else %}video/mp4{% endif %}">
</video>
{% if video.vimeoId %}
<div style="padding:60% 0 0 0;position:relative;">
<iframe src="https://player.vimeo.com/video/{{ video.vimeoId }}?color=ffffff&title=0&byline=0&portrait=0" style="position:absolute;top:0;left:0;width:100%;height:100%;" frameborder="0" allow="autoplay; fullscreen" allowfullscreen></iframe>
</div>
<script src="https://player.vimeo.com/api/player.js"></script>
{% else %}
<video controls>
<source src="{{ video.video }}" type="{{ video.type }}">
</video>
{% endif %}
{% if audio.description %}
<p>
{{ audio.description }}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment