Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#4850] Preview for multimedia files
Currently, there is no preview for multimedia files, such as video or audio files. This changes implements the audio_preview, with simple HTML5 <audio> tag
- Loading branch information
calexandr
committed
Nov 27, 2019
1 parent
ef103f0
commit 557b7e0
Showing
4 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# encoding: utf-8 | ||
|
||
from six import text_type | ||
import ckan.plugins as p | ||
|
||
ignore_empty = p.toolkit.get_validator('ignore_empty') | ||
|
||
DEFAULT_AUDIO_FORMATS = 'wav ogg mp3' | ||
|
||
|
||
class AudioView(p.SingletonPlugin): | ||
'''This plugin makes views of audio resources, using an <audio> tag''' | ||
|
||
p.implements(p.IConfigurer, inherit=True) | ||
p.implements(p.IResourceView, inherit=True) | ||
|
||
def update_config(self, config): | ||
p.toolkit.add_template_directory(config, 'theme/templates') | ||
self.formats = config.get( | ||
'ckan.preview.audio_formats', | ||
DEFAULT_AUDIO_FORMATS).split() | ||
|
||
def info(self): | ||
return {'name': 'audio_view', | ||
'title': p.toolkit._('Audio'), | ||
'icon': 'file-audio-o', | ||
'schema': {'audio_url': [ignore_empty, text_type]}, | ||
'iframed': False, | ||
'always_available': True, | ||
'default_title': p.toolkit._('Audio'), | ||
} | ||
|
||
def can_view(self, data_dict): | ||
return (data_dict['resource'].get('format', '').lower() | ||
in self.formats) | ||
|
||
def view_template(self, context, data_dict): | ||
return 'audio_view.html' | ||
|
||
def form_template(self, context, data_dict): | ||
return 'audio_form.html' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{% import 'macros/form.html' as form %} | ||
|
||
{{ form.input('audio_url', id='field-audio_url', label=_('Audio url'), placeholder=_('eg. http://example.com/audio.mp3 (if blank uses resource url)'), value=data.audio_url, error=errors.audio_url, classes=['control-full', 'control-large']) }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{% set res_url = resource_view.get('audio_url') or resource.get('url') %} | ||
|
||
<audio style="margin:auto; max-height:100%; display:block; min-width: 100%;" | ||
controls src="{{ resource_view.audio_url or resource.get('url') }}"> | ||
{% trans %} | ||
Your browser does not support the <code>audio</code> element. | ||
But don't worry, you can <a href="{{ res_url }}" alt="video url">download it</a>. | ||
{% endtrans %} | ||
</audio> |