Commit e530ef03 authored by seb-b's avatar seb-b Committed by GitHub
Browse files

Merge pull request #4 from takeflight/ffmpeg-check-change

Ffmpeg check change
parents ef5f2449 73640e90
from __future__ import absolute_import, print_function, unicode_literals
from django.apps import AppConfig
from django.core.checks import Error, register
from django.core.checks import Warning, register
from wagtailvideos.utils import which
from wagtailvideos.utils import ffmpeg_installed
def ffmpeg_check(app_configs, path=None, **kwargs):
errors = []
if which('ffmpeg', path=path) is None:
errors.append(
Error(
'ffmpeg could not be found on your system, try installing it.',
def ffmpeg_check(app_configs, **kwargs):
messages = []
if not ffmpeg_installed():
messages.append(
Warning(
'ffmpeg could not be found on your system. Transcoding will be disabled',
hint=None,
obj='SystemCheckError',
id='wagtailvideos.E001',
id='wagtailvideos.W001',
)
)
return errors
return messages
class WagtailVideosApp(AppConfig):
......
......@@ -28,6 +28,8 @@ from wagtail.wagtailcore.models import CollectionMember
from wagtail.wagtailsearch import index
from wagtail.wagtailsearch.queryset import SearchableQuerySetMixin
from wagtailvideos.utils import ffmpeg_installed
logger = logging.getLogger(__name__)
......@@ -149,6 +151,9 @@ class AbstractVideo(CollectionMember, TagSearchable):
if self.duration:
return self.duration
if not ffmpeg_installed():
return None
file_path = self.file.path
try:
# FIXME prints out extra stuff on travis, pip stderr to dev/null
......@@ -165,6 +170,9 @@ class AbstractVideo(CollectionMember, TagSearchable):
if self.thumbnail:
return self.thumbnail
if not ffmpeg_installed():
return None
file_path = self.file.path
file_name = self.filename(include_ext=False) + '_thumb.jpg'
......
......@@ -17,7 +17,13 @@
{% for video in videos %}
<li>
<a class="image-choice" href="{% if will_select_format %}{% url 'wagtailvideos:chooser_select_format' video.id %}{% else %}{% url 'wagtailvideos:video_chosen' video.id %}{% endif %}">
<div class="image"><img src='{{video.thumbnail.url}}' width="165" height="165" class="show-transparency"></div>
<div class="image">
{% if video.thumbnail %}
<img src='{{video.thumbnail.url}}' width="165" height="165" class="show-transparency">
{% else %}
<img width="165" height="165" class="show-transparency">
{% endif %}
</div>
<h3>{{ video.title|ellipsistrim:60 }}</h3>
</a>
</li>
......
......@@ -16,7 +16,9 @@
</ul>
</form>
<div data-video-thumb="{{ video.id }}" class='thumb icon icon-image hasthumb'>
{% if video.thumbnail %}
<img src="{{ video.thumbnail.url }}" />
{% endif %}
</div>
<script>
......
......@@ -27,6 +27,7 @@
</div>
<div class="col5 divider-after">
<h2 class="label">{% trans "Video preview" %}</h2> {% video video controls style=max-width:100% %}
{% if can_transcode %}
<h3 class="label">Transcodes</h3>
<p>If you wish to generate HTML5 compliant transcodes use the form below. This may take a while depending on the length of the video.</p>
{% if transcodes %}
......@@ -53,15 +54,23 @@
</li>
</ul>
</form>
{% else %}
<br/><br/>
<span class='transcode-error'>Ffmpeg is not found on your server. Please install if you wish to transcode videos into an HTML5 video compliant format.</span>
{% endif %}
</div>
<div class="col2 ">
<dl>
{% if video.thumbnail %}
<dt>{% trans "Thumbnail" %}</dt>
<dd><img src='{{ video.thumbnail.url }}' /></dd>
{% endif %}
<dt>{% trans "Filesize" %}</dt>
<dd>{% if filesize %}{{ filesize|filesizeformat }}{% else %}{% trans "File not found" %}{% endif %}</dd>
{% if video.duration %}
<dt>{% trans "Duration" %}</dt>
<dd>{{ video.formatted_duration }}</dd>
{% endif %}
</dl>
</div>
</div>
......
......@@ -20,7 +20,9 @@
<li>
<a class="image-choice" href="{% url 'wagtailvideos:edit' video.id %}">
<div class="image">
{% if video.thumbnail %}
<img src='{{video.thumbnail.url}}' height=165 width=165 class="show-transparency" /></img>
{% endif %}
</div>
<h3>{{ video.title|ellipsistrim:60 }}</h3>
</a>
......
......@@ -4,7 +4,7 @@
{% block chosen_state_view %}
<div class="video-thumb">
{% if video %}
{% if video and video.thumbnail %}
<img src='{{video.thumbnail.url}}' width="165" height="165" class="show-transparency">
{% else %}
<img width="165" height="165" class="show-transparency">
......
......@@ -41,6 +41,7 @@ class VideoNode(template.Node):
if not video:
raise template.TemplateSyntaxError("video tag requires a Video object as the first parameter")
if video.thumbnail:
self.attrs['poster'] = video.thumbnail.url
mime = mimetypes.MimeTypes()
......
......@@ -4,3 +4,7 @@ try:
from shutil import which
except ImportError:
from distutils.spawn import find_executable as which
def ffmpeg_installed(path=None):
return which('ffmpeg', path=path) is not None
......@@ -30,7 +30,7 @@ def get_video_json(video):
'edit_link': reverse('wagtailvideos:edit', args=(video.id,)),
'title': video.title,
'preview': {
'url': video.thumbnail.url,
'url': video.thumbnail.url if video.thumbnail else '',
}
})
......
......@@ -17,6 +17,7 @@ from wagtail.wagtailsearch.backends import get_search_backends
from wagtailvideos.forms import VideoTranscodeAdminForm, get_video_form
from wagtailvideos.models import Video
from wagtailvideos.permissions import permission_policy
from wagtailvideos.utils import ffmpeg_installed
permission_checker = PermissionPolicyChecker(permission_policy)
......@@ -69,6 +70,7 @@ def index(request):
})
return response
@permission_checker.require('change')
def edit(request, video_id):
VideoForm = get_video_form(Video)
......@@ -117,12 +119,12 @@ def edit(request, video_id):
'video': video,
'form': form,
'filesize': video.get_file_size(),
'can_transcode': ffmpeg_installed(),
'transcodes': video.transcodes.all(),
'transcode_form': VideoTranscodeAdminForm(video=video),
'user_can_delete': permission_policy.user_has_permission_for_instance(request.user, 'delete', video)
})
def create_transcode(request, video_id):
if request.method != 'POST':
return HttpResponseNotAllowed(['POST'])
......
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