[media_type:mediagoblin.media_types.audio]
+keep_original = boolean(default=True)
# vorbisenc qualiy
quality = float(default=0.3)
create_spectrogram = boolean(default=True)
# GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 MediaGoblin contributors. See AUTHORS.
+# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from sqlalchemy import MetaData, Table
+
+from mediagoblin.db.sql.util import RegisterMigration
+
+
MIGRATIONS = {}
+
+
+@RegisterMigration(1, MIGRATIONS)
+def ogg_to_webm_audio(db_conn):
+ metadata = MetaData(bind=db_conn.bind)
+
+ file_keynames = Table('core__file_keynames', metadata, autoload=True,
+ autoload_with=db_conn.bind)
+
+ db_conn.execute(
+ file_keynames.update().where(file_keynames.c.name=='ogg').
+ values(name='webm_audio')
+ )
import os
from mediagoblin import mg_globals as mgg
-from mediagoblin.processing import create_pub_filepath, BadMediaFail
+from mediagoblin.processing import (create_pub_filepath, BadMediaFail,
+ FilenameBuilder)
-from mediagoblin.media_types.audio.transcoders import AudioTranscoder, \
- AudioThumbnailer
+from mediagoblin.media_types.audio.transcoders import (AudioTranscoder,
+ AudioThumbnailer)
_log = logging.getLogger(__name__)
queued_filename = workbench.localized_file(
mgg.queue_store, queued_filepath,
'source')
+ name_builder = FilenameBuilder(queued_filename)
- ogg_filepath = create_pub_filepath(
+ webm_audio_filepath = create_pub_filepath(
entry,
'{original}.webm'.format(
original=os.path.splitext(
queued_filepath[-1])[0]))
+ if audio_config['keep_original']:
+ with open(queued_filename, 'rb') as queued_file:
+ original_filepath = create_pub_filepath(
+ entry, name_builder.fill('{basename}{ext}'))
+
+ with mgg.public_store.get_file(original_filepath, 'wb') as \
+ original_file:
+ _log.debug('Saving original...')
+ original_file.write(queued_file.read())
+
+ entry.media_files['original'] = original_filepath
+
transcoder = AudioTranscoder()
- with tempfile.NamedTemporaryFile() as ogg_tmp:
+ with tempfile.NamedTemporaryFile() as webm_audio_tmp:
transcoder.transcode(
queued_filename,
- ogg_tmp.name,
+ webm_audio_tmp.name,
quality=audio_config['quality'])
- data = transcoder.discover(ogg_tmp.name)
+ data = transcoder.discover(webm_audio_tmp.name)
_log.debug('Saving medium...')
- mgg.public_store.get_file(ogg_filepath, 'wb').write(
- ogg_tmp.read())
+ mgg.public_store.get_file(webm_audio_filepath, 'wb').write(
+ webm_audio_tmp.read())
- entry.media_files['ogg'] = ogg_filepath
+ entry.media_files['webm_audio'] = webm_audio_filepath
# entry.media_data_init(length=int(data.audiolength))
<audio class="audio-player" controls="controls"
preload="metadata">
<source src="{{ request.app.public_store.file_url(
- media.media_files.ogg) }}" type="audio/webm; codecs=vorbis" />
+ 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
</div>
</audio>
</div>
- {% if 'original' in media.media_files %}
- <p>
- <a href="{{ request.app.public_store.file_url(
- media.media_files['original']) }}">
- {%- trans -%}
- Original
- {%- endtrans -%}
- </a>
- </p>
- {% endif %}
+{% endblock %}
+
+{% block mediagoblin_sidebar %}
+ <h3>{% trans %}Download{% endtrans %}</h3>
+ <ul>
+ {% if 'original' in media.media_files %}
+ <li><a href="{{ request.app.public_store.file_url(
+ media.media_files.original) }}">{% trans %}original file{% endtrans %}</a>
+ {% endif %}
+ <li><a href="{{ request.app.public_store.file_url(
+ media.media_files.webm_audio) }}">{% trans %}WebM file (Vorbis codec){% endtrans %}</a>
+ </ul>
{% endblock %}
{% include "mediagoblin/utils/geolocation_map.html" %}
{% include "mediagoblin/utils/exif.html" %}
+
+ {% block mediagoblin_sidebar %}
+ {% endblock %}
</div>
<div class="clear"></div>
{% endblock %}