added support for original audio download; rename
Renamed `ogg' to `webm_audio' in core__file_keynames
This commit is contained in:
parent
355fd6770d
commit
b781c3c928
@ -95,6 +95,7 @@ vorbis_quality = float(default=0.3)
|
||||
|
||||
|
||||
[media_type:mediagoblin.media_types.audio]
|
||||
keep_original = boolean(default=True)
|
||||
# vorbisenc qualiy
|
||||
quality = float(default=0.3)
|
||||
create_spectrogram = boolean(default=True)
|
||||
|
@ -1,5 +1,5 @@
|
||||
# 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
|
||||
@ -14,4 +14,22 @@
|
||||
# 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')
|
||||
)
|
||||
|
@ -19,10 +19,11 @@ import tempfile
|
||||
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__)
|
||||
|
||||
@ -48,29 +49,42 @@ def process_audio(entry):
|
||||
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))
|
||||
|
||||
|
@ -39,7 +39,7 @@
|
||||
<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
|
||||
@ -50,14 +50,16 @@
|
||||
</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 %}
|
||||
|
@ -184,6 +184,9 @@
|
||||
{% include "mediagoblin/utils/geolocation_map.html" %}
|
||||
|
||||
{% include "mediagoblin/utils/exif.html" %}
|
||||
|
||||
{% block mediagoblin_sidebar %}
|
||||
{% endblock %}
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
{% endblock %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user