beb12391885c718d805223a649bdd91587d4c75f
1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 from mediagoblin
import mg_globals
as mgg
22 from mediagoblin
.processing
import create_pub_filepath
24 from mediagoblin
.media_types
.audio
.transcoders
import AudioTranscoder
26 _log
= logging
.getLogger()
28 def sniff_handler(media
):
31 def process_audio(entry
):
32 audio_config
= mgg
.global_config
['media_type:mediagoblin.media_types.audio']
34 workbench
= mgg
.workbench_manager
.create_workbench()
36 queued_filepath
= entry
.queued_media_file
37 queued_filename
= workbench
.localized_file(
38 mgg
.queue_store
, queued_filepath
,
41 ogg_filepath
= create_pub_filepath(
43 '{original}.webm'.format(
44 original
=os
.path
.splitext(
45 queued_filepath
[-1])[0]))
47 ogg_tmp
= tempfile
.NamedTemporaryFile()
50 transcoder
= AudioTranscoder()
55 quality
=audio_config
['quality'])
57 data
= transcoder
.discover(ogg_tmp
.name
)
59 _log
.debug('Saving medium...')
60 mgg
.public_store
.get_file(ogg_filepath
, 'wb').write(
63 entry
.media_files
['ogg'] = ogg_filepath
65 entry
.media_data
['audio'] = {
66 u
'length': int(data
.audiolength
)}
68 thumbnail_tmp
= tempfile
.NamedTemporaryFile()
71 entry
.media_files
['thumb'] = ['fake', 'thumb', 'path.jpg']
73 mgg
.queue_store
.delete_file(queued_filepath
)