added support for original audio download; rename

Renamed `ogg' to `webm_audio' in core__file_keynames
This commit is contained in:
Jakob Kramer 2012-05-19 18:17:33 +02:00 committed by Joar Wandborg
parent 355fd6770d
commit b781c3c928
5 changed files with 60 additions and 22 deletions

View File

@ -95,6 +95,7 @@ vorbis_quality = float(default=0.3)
[media_type:mediagoblin.media_types.audio] [media_type:mediagoblin.media_types.audio]
keep_original = boolean(default=True)
# vorbisenc qualiy # vorbisenc qualiy
quality = float(default=0.3) quality = float(default=0.3)
create_spectrogram = boolean(default=True) create_spectrogram = boolean(default=True)

View File

@ -1,5 +1,5 @@
# GNU MediaGoblin -- federated, autonomous media hosting # 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 # 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 # it under the terms of the GNU Affero General Public License as published by
@ -14,4 +14,22 @@
# You should have received a copy of the GNU Affero General Public License # 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/>. # 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 = {} 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')
)

View File

@ -19,10 +19,11 @@ import tempfile
import os import os
from mediagoblin import mg_globals as mgg 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, \ from mediagoblin.media_types.audio.transcoders import (AudioTranscoder,
AudioThumbnailer AudioThumbnailer)
_log = logging.getLogger(__name__) _log = logging.getLogger(__name__)
@ -48,29 +49,42 @@ def process_audio(entry):
queued_filename = workbench.localized_file( queued_filename = workbench.localized_file(
mgg.queue_store, queued_filepath, mgg.queue_store, queued_filepath,
'source') 'source')
name_builder = FilenameBuilder(queued_filename)
ogg_filepath = create_pub_filepath( webm_audio_filepath = create_pub_filepath(
entry, entry,
'{original}.webm'.format( '{original}.webm'.format(
original=os.path.splitext( original=os.path.splitext(
queued_filepath[-1])[0])) 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() transcoder = AudioTranscoder()
with tempfile.NamedTemporaryFile() as ogg_tmp: with tempfile.NamedTemporaryFile() as webm_audio_tmp:
transcoder.transcode( transcoder.transcode(
queued_filename, queued_filename,
ogg_tmp.name, webm_audio_tmp.name,
quality=audio_config['quality']) quality=audio_config['quality'])
data = transcoder.discover(ogg_tmp.name) data = transcoder.discover(webm_audio_tmp.name)
_log.debug('Saving medium...') _log.debug('Saving medium...')
mgg.public_store.get_file(ogg_filepath, 'wb').write( mgg.public_store.get_file(webm_audio_filepath, 'wb').write(
ogg_tmp.read()) 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)) # entry.media_data_init(length=int(data.audiolength))

View File

@ -39,7 +39,7 @@
<audio class="audio-player" controls="controls" <audio class="audio-player" controls="controls"
preload="metadata"> preload="metadata">
<source src="{{ request.app.public_store.file_url( <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"> <div class="no_html5">
{%- trans -%}Sorry, this audio will not work because {%- trans -%}Sorry, this audio will not work because
your web browser does not support HTML5 your web browser does not support HTML5
@ -50,14 +50,16 @@
</div> </div>
</audio> </audio>
</div> </div>
{% if 'original' in media.media_files %} {% endblock %}
<p>
<a href="{{ request.app.public_store.file_url( {% block mediagoblin_sidebar %}
media.media_files['original']) }}"> <h3>{% trans %}Download{% endtrans %}</h3>
{%- trans -%} <ul>
Original {% if 'original' in media.media_files %}
{%- endtrans -%} <li><a href="{{ request.app.public_store.file_url(
</a> media.media_files.original) }}">{% trans %}original file{% endtrans %}</a>
</p> {% endif %}
{% endif %} <li><a href="{{ request.app.public_store.file_url(
media.media_files.webm_audio) }}">{% trans %}WebM file (Vorbis codec){% endtrans %}</a>
</ul>
{% endblock %} {% endblock %}

View File

@ -184,6 +184,9 @@
{% include "mediagoblin/utils/geolocation_map.html" %} {% include "mediagoblin/utils/geolocation_map.html" %}
{% include "mediagoblin/utils/exif.html" %} {% include "mediagoblin/utils/exif.html" %}
{% block mediagoblin_sidebar %}
{% endblock %}
</div> </div>
<div class="clear"></div> <div class="clear"></div>
{% endblock %} {% endblock %}