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 __future__ import absolute_import, print_function, unicode_literals
from django.apps import AppConfig 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): def ffmpeg_check(app_configs, **kwargs):
errors = [] messages = []
if which('ffmpeg', path=path) is None: if not ffmpeg_installed():
errors.append( messages.append(
Error( Warning(
'ffmpeg could not be found on your system, try installing it.', 'ffmpeg could not be found on your system. Transcoding will be disabled',
hint=None, hint=None,
obj='SystemCheckError', id='wagtailvideos.W001',
id='wagtailvideos.E001',
) )
) )
return errors return messages
class WagtailVideosApp(AppConfig): class WagtailVideosApp(AppConfig):
......
...@@ -28,6 +28,8 @@ from wagtail.wagtailcore.models import CollectionMember ...@@ -28,6 +28,8 @@ from wagtail.wagtailcore.models import CollectionMember
from wagtail.wagtailsearch import index from wagtail.wagtailsearch import index
from wagtail.wagtailsearch.queryset import SearchableQuerySetMixin from wagtail.wagtailsearch.queryset import SearchableQuerySetMixin
from wagtailvideos.utils import ffmpeg_installed
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -149,6 +151,9 @@ class AbstractVideo(CollectionMember, TagSearchable): ...@@ -149,6 +151,9 @@ class AbstractVideo(CollectionMember, TagSearchable):
if self.duration: if self.duration:
return self.duration return self.duration
if not ffmpeg_installed():
return None
file_path = self.file.path file_path = self.file.path
try: try:
# FIXME prints out extra stuff on travis, pip stderr to dev/null # FIXME prints out extra stuff on travis, pip stderr to dev/null
...@@ -165,6 +170,9 @@ class AbstractVideo(CollectionMember, TagSearchable): ...@@ -165,6 +170,9 @@ class AbstractVideo(CollectionMember, TagSearchable):
if self.thumbnail: if self.thumbnail:
return self.thumbnail return self.thumbnail
if not ffmpeg_installed():
return None
file_path = self.file.path file_path = self.file.path
file_name = self.filename(include_ext=False) + '_thumb.jpg' file_name = self.filename(include_ext=False) + '_thumb.jpg'
......
...@@ -17,7 +17,13 @@ ...@@ -17,7 +17,13 @@
{% for video in videos %} {% for video in videos %}
<li> <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 %}"> <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> <h3>{{ video.title|ellipsistrim:60 }}</h3>
</a> </a>
</li> </li>
......
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
</ul> </ul>
</form> </form>
<div data-video-thumb="{{ video.id }}" class='thumb icon icon-image hasthumb'> <div data-video-thumb="{{ video.id }}" class='thumb icon icon-image hasthumb'>
{% if video.thumbnail %}
<img src="{{ video.thumbnail.url }}" /> <img src="{{ video.thumbnail.url }}" />
{% endif %}
</div> </div>
<script> <script>
......
...@@ -27,41 +27,50 @@ ...@@ -27,41 +27,50 @@
</div> </div>
<div class="col5 divider-after"> <div class="col5 divider-after">
<h2 class="label">{% trans "Video preview" %}</h2> {% video video controls style=max-width:100% %} <h2 class="label">{% trans "Video preview" %}</h2> {% video video controls style=max-width:100% %}
<h3 class="label">Transcodes</h3> {% if can_transcode %}
<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> <h3 class="label">Transcodes</h3>
{% if transcodes %} <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>
<h3 class="label">Available Transcodes</h3> {% if transcodes %}
<ul> <h3 class="label">Available Transcodes</h3>
{% for transcode in transcodes %} <ul>
<li> {% for transcode in transcodes %}
{{ transcode.media_format }} ({{ transcode.quality }} quality) {% if transcode.processing %} <span class='processing'>(Processing... hold tight) </span>{% endif %} {% if transcode.error_message %}
<span class='transcode-error'>ERROR:</span>
<div class='transcode-error'>
<pre> {{ transcode.error_message }}</pre>
</div>
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
<h3 class="label">Create transcode</h3>
<form action="{% url 'wagtailvideos:create_transcode' video.id %}" method="POST">
<ul class="fields">
{% csrf_token %} {% include "wagtailadmin/shared/field_as_li.html" with field=transcode_form.media_format %} {% include "wagtailadmin/shared/field_as_li.html" with field=transcode_form.quality %}
<li> <li>
<input class="button" type='submit' value="Start" /> {{ transcode.media_format }} ({{ transcode.quality }} quality) {% if transcode.processing %} <span class='processing'>(Processing... hold tight) </span>{% endif %} {% if transcode.error_message %}
<span class='transcode-error'>ERROR:</span>
<div class='transcode-error'>
<pre> {{ transcode.error_message }}</pre>
</div>
{% endif %}
</li> </li>
{% endfor %}
</ul> </ul>
</form> {% endif %}
<h3 class="label">Create transcode</h3>
<form action="{% url 'wagtailvideos:create_transcode' video.id %}" method="POST">
<ul class="fields">
{% csrf_token %} {% include "wagtailadmin/shared/field_as_li.html" with field=transcode_form.media_format %} {% include "wagtailadmin/shared/field_as_li.html" with field=transcode_form.quality %}
<li>
<input class="button" type='submit' value="Start" />
</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>
<div class="col2 "> <div class="col2 ">
<dl> <dl>
{% if video.thumbnail %}
<dt>{% trans "Thumbnail" %}</dt> <dt>{% trans "Thumbnail" %}</dt>
<dd><img src='{{ video.thumbnail.url }}' /></dd> <dd><img src='{{ video.thumbnail.url }}' /></dd>
{% endif %}
<dt>{% trans "Filesize" %}</dt> <dt>{% trans "Filesize" %}</dt>
<dd>{% if filesize %}{{ filesize|filesizeformat }}{% else %}{% trans "File not found" %}{% endif %}</dd> <dd>{% if filesize %}{{ filesize|filesizeformat }}{% else %}{% trans "File not found" %}{% endif %}</dd>
{% if video.duration %}
<dt>{% trans "Duration" %}</dt> <dt>{% trans "Duration" %}</dt>
<dd>{{ video.formatted_duration }}</dd> <dd>{{ video.formatted_duration }}</dd>
{% endif %}
</dl> </dl>
</div> </div>
</div> </div>
......
...@@ -20,8 +20,10 @@ ...@@ -20,8 +20,10 @@
<li> <li>
<a class="image-choice" href="{% url 'wagtailvideos:edit' video.id %}"> <a class="image-choice" href="{% url 'wagtailvideos:edit' video.id %}">
<div class="image"> <div class="image">
{% if video.thumbnail %}
<img src='{{video.thumbnail.url}}' height=165 width=165 class="show-transparency" /></img> <img src='{{video.thumbnail.url}}' height=165 width=165 class="show-transparency" /></img>
</div> {% endif %}
</div>
<h3>{{ video.title|ellipsistrim:60 }}</h3> <h3>{{ video.title|ellipsistrim:60 }}</h3>
</a> </a>
</li> </li>
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
{% block chosen_state_view %} {% block chosen_state_view %}
<div class="video-thumb"> <div class="video-thumb">
{% if video %} {% if video and video.thumbnail %}
<img src='{{video.thumbnail.url}}' width="165" height="165" class="show-transparency"> <img src='{{video.thumbnail.url}}' width="165" height="165" class="show-transparency">
{% else %} {% else %}
<img width="165" height="165" class="show-transparency"> <img width="165" height="165" class="show-transparency">
......
...@@ -41,7 +41,8 @@ class VideoNode(template.Node): ...@@ -41,7 +41,8 @@ class VideoNode(template.Node):
if not video: if not video:
raise template.TemplateSyntaxError("video tag requires a Video object as the first parameter") raise template.TemplateSyntaxError("video tag requires a Video object as the first parameter")
self.attrs['poster'] = video.thumbnail.url if video.thumbnail:
self.attrs['poster'] = video.thumbnail.url
mime = mimetypes.MimeTypes() mime = mimetypes.MimeTypes()
sources = ["<source src='{0}' type='{1}'>" sources = ["<source src='{0}' type='{1}'>"
......
...@@ -4,3 +4,7 @@ try: ...@@ -4,3 +4,7 @@ try:
from shutil import which from shutil import which
except ImportError: except ImportError:
from distutils.spawn import find_executable as which 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): ...@@ -30,7 +30,7 @@ def get_video_json(video):
'edit_link': reverse('wagtailvideos:edit', args=(video.id,)), 'edit_link': reverse('wagtailvideos:edit', args=(video.id,)),
'title': video.title, 'title': video.title,
'preview': { '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 ...@@ -17,6 +17,7 @@ from wagtail.wagtailsearch.backends import get_search_backends
from wagtailvideos.forms import VideoTranscodeAdminForm, get_video_form from wagtailvideos.forms import VideoTranscodeAdminForm, get_video_form
from wagtailvideos.models import Video from wagtailvideos.models import Video
from wagtailvideos.permissions import permission_policy from wagtailvideos.permissions import permission_policy
from wagtailvideos.utils import ffmpeg_installed
permission_checker = PermissionPolicyChecker(permission_policy) permission_checker = PermissionPolicyChecker(permission_policy)
...@@ -69,6 +70,7 @@ def index(request): ...@@ -69,6 +70,7 @@ def index(request):
}) })
return response return response
@permission_checker.require('change') @permission_checker.require('change')
def edit(request, video_id): def edit(request, video_id):
VideoForm = get_video_form(Video) VideoForm = get_video_form(Video)
...@@ -117,12 +119,12 @@ def edit(request, video_id): ...@@ -117,12 +119,12 @@ def edit(request, video_id):
'video': video, 'video': video,
'form': form, 'form': form,
'filesize': video.get_file_size(), 'filesize': video.get_file_size(),
'can_transcode': ffmpeg_installed(),
'transcodes': video.transcodes.all(), 'transcodes': video.transcodes.all(),
'transcode_form': VideoTranscodeAdminForm(video=video), 'transcode_form': VideoTranscodeAdminForm(video=video),
'user_can_delete': permission_policy.user_has_permission_for_instance(request.user, 'delete', video) 'user_can_delete': permission_policy.user_has_permission_for_instance(request.user, 'delete', video)
}) })
def create_transcode(request, video_id): def create_transcode(request, video_id):
if request.method != 'POST': if request.method != 'POST':
return HttpResponseNotAllowed(['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