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_file
, **kw
):
29 transcoder
= AudioTranscoder()
31 data
= transcoder
.discover(media_file
.name
)
33 if data
.is_audio
== True and data
.is_video
== False:
38 def process_audio(entry
):
39 audio_config
= mgg
.global_config
['media_type:mediagoblin.media_types.audio']
41 workbench
= mgg
.workbench_manager
.create_workbench()
43 queued_filepath
= entry
.queued_media_file
44 queued_filename
= workbench
.localized_file(
45 mgg
.queue_store
, queued_filepath
,
48 ogg_filepath
= create_pub_filepath(
50 '{original}.webm'.format(
51 original
=os
.path
.splitext(
52 queued_filepath
[-1])[0]))
54 ogg_tmp
= tempfile
.NamedTemporaryFile()
57 transcoder
= AudioTranscoder()
62 quality
=audio_config
['quality'])
64 data
= transcoder
.discover(ogg_tmp
.name
)
66 _log
.debug('Saving medium...')
67 mgg
.public_store
.get_file(ogg_filepath
, 'wb').write(
70 entry
.media_files
['ogg'] = ogg_filepath
72 entry
.media_data
['audio'] = {
73 u
'length': int(data
.audiolength
)}
75 thumbnail_tmp
= tempfile
.NamedTemporaryFile()
78 entry
.media_files
['thumb'] = ['fake', 'thumb', 'path.jpg']
80 mgg
.queue_store
.delete_file(queued_filepath
)