From 32f8ae938277e25bc4bb755e53edf2c7eb7d7d8c Mon Sep 17 00:00:00 2001 From: Ben Sturmfels Date: Tue, 7 Apr 2020 16:25:52 +1000 Subject: [PATCH] Update for MediaGoblin >= 0.9.0 with multi-resolution video. Also fixes the double-forwardslash in URLs. A more robust approach would be to use `urllib.parse.urljoin`. This is a little bit of a lash-up, since the administrator could have defined custom resolutions in the configuration. --- .../mediagoblin/plugins/embedcode/embed_code.html | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/embedcode/templates/mediagoblin/plugins/embedcode/embed_code.html b/embedcode/templates/mediagoblin/plugins/embedcode/embed_code.html index 5e39450..bf20d9c 100644 --- a/embedcode/templates/mediagoblin/plugins/embedcode/embed_code.html +++ b/embedcode/templates/mediagoblin/plugins/embedcode/embed_code.html @@ -20,9 +20,15 @@

{% if media.media_type == "mediagoblin.media_types.video" %} - {% set file_url = request.app.public_store.file_url(media.media_files.webm_video) %} + {% if 'webm_video' in media.media_files %} + {# MediaGoblin <= 0.9.0 #} + {% set file_url = request.app.public_store.file_url(media.media_files.webm_video) %} + {% elif 'webm_720p' in media.media_files %} + {# MediaGoblin > 0.9.0 with muti-resolution video #} + {% set file_url = request.app.public_store.file_url(media.media_files.webm_720p) %} + {% endif %} {% if '://' not in file_url %} - {% set file_url = request.host_url + file_url %} + {% set file_url = request.host_url[:-1] + file_url %} {% endif %}

{% trans %}Embed{% endtrans %}

@@ -39,7 +45,7 @@

{% trans %}Embed{% endtrans %}

{% if media.media_type == "mediagoblin.media_types.audio" %}

{% trans %}Embed{% endtrans %}

-

<audio class="audio-player" controls="controls" preload="metadata"> <source src="{{ request.host_url + request.app.public_store.file_url( media.media_files.webm_audio) }}" type="audio/webm; codecs=vorbis" /> <div class="no_html5"> {%- trans -%}Sorry, this audio will not work because your web browser does not support HTML5 audio.{%- endtrans -%} </div> </audio>
+
<audio class="audio-player" controls="controls" preload="metadata"> <source src="{{ request.host_url[:-1] + request.app.public_store.file_url( media.media_files.webm_audio) }}" type="audio/webm; codecs=vorbis" /> <div class="no_html5"> {%- trans -%}Sorry, this audio will not work because your web browser does not support HTML5 audio.{%- endtrans -%} </div> </audio>
{% endif %}
{% endblock %}