Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 53 lines (39 sloc) 1.574 kB
3c8e52e add 2 new hook scripts (including tests)
Bernd Schlapsi authored
1 # -*- coding: utf-8 -*-
2 # This hook adjusts the volume of audio files to a standard level
3 # Supported file formats are mp3 and ogg
4 #
5 # Requires: normalize-audio, mpg123
6 #
7 # (c) 2011-11-06 Bernd Schlapsi <brot@gmx.info>
8 # Released under the same license terms as gPodder itself.
9
10 import gpodder
11 from gpodder import youtube
12
13 import os
14 import shlex
15 import subprocess
16
17 import logging
18 logger = logging.getLogger(__name__)
19
20 # a tuple of (extension, command)
21 SUPPORTED = (('ogg', 'normalize-ogg "%s"'), ('mp3', 'normalize-mp3 "%s"'))
22
23 # http://normalize.nongnu.org/README.html FAQ #5
24 #MP3_CMD = 'normalize-audio "%s"'
25
26
27 class gPodderHooks(object):
28 def on_episode_downloaded(self, episode):
29 self._convert_episode(episode)
30
31 def _convert_episode(self, episode):
32 filename = episode.local_filename(create=False, check_only=True)
33 if filename is None:
34 return
35
36 formats, commands = zip(*SUPPORTED)
37 (basename, extension) = os.path.splitext(filename)
38 extension = extension.lstrip('.').lower()
39 if episode.file_type() == 'audio' and extension in formats:
40
41 cmd = commands[formats.index(extension)] % filename
42
43 p = subprocess.Popen(shlex.split(cmd),
44 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
45 stdout, stderr = p.communicate()
46
47 if p.returncode == 0:
48 logger.info('normalize-audio processing successfull.')
49
50 else:
51 logger.info('normalize-audio processing not successfull.')
52 logger.debug(stderr)
Something went wrong with that request. Please try again.