added support for original audio download; rename
authorJakob Kramer <jakob.kramer@gmx.de>
Sat, 19 May 2012 16:17:33 +0000 (18:17 +0200)
committerJoar Wandborg <git@wandborg.com>
Sun, 20 May 2012 16:32:56 +0000 (18:32 +0200)
Renamed `ogg' to `webm_audio' in core__file_keynames

mediagoblin/config_spec.ini
mediagoblin/db/sql/migrations.py
mediagoblin/media_types/audio/processing.py
mediagoblin/templates/mediagoblin/media_displays/audio.html
mediagoblin/templates/mediagoblin/user_pages/media.html

index 01853e48528b3522d0bd55361a9e5ce10d21156d..ce81b35688207e9f06fde8b423dae5cdb09bcb3b 100644 (file)
@@ -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)
index 98d0d0aaf22c4aaa35dc30626e66bd02f1d21f24..3b7ee8b4890250c81abdb8e7232c84cbd89e7a10 100644 (file)
@@ -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
 # 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')
+    )
index f0b8d0f9c2b957bbd88d3ff44d1587fd355f8a2a..ef98e533fed38cfbcfb1b293d30eba75e4ace66f 100644 (file)
@@ -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))
 
index 06d4f88269cc5b1409fc330652461d21730aa35c..9713aa49a405cf762f37e9e31cd80bad8518d791 100644 (file)
@@ -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 
       </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 %}
index 4d41f19e5e0d0f25564014375ed3a9d5f71e7594..21990442a6cfadfe8b95584ee0d6eaadccf1fa15 100644 (file)
     {% include "mediagoblin/utils/geolocation_map.html" %}
 
     {% include "mediagoblin/utils/exif.html" %}
+    
+    {% block mediagoblin_sidebar %}
+    {% endblock %}
   </div>
   <div class="clear"></div>
 {% endblock %}