#!/usr/bin/env python
#
-# Copyright (C) 2009-2011 W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2009-2012 W. Trevor King <wking@drexel.edu>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
if ext == self._target_extension:
shutil.copy(source, target)
return
- convert = getattr(self, 'convert_{}_to_{}'.format(
- ext, self._target_extension))
+ try:
+ convert = getattr(self, 'convert_{}_to_{}'.format(
+ ext, self._target_extension))
+ except AttributeError:
+ to_wav = getattr(self, 'convert_{}_to_wav'.format(ext))
+ from_wav = getattr(self, 'convert_wav_to_{}'.format(
+ self._target_extension))
+ def convert(source, target):
+ to_wav(source, self._tempfile)
+ from_wav(self._tempfile, target)
convert(source, target)
if not getattr(convert, 'handles_metadata', False):
get_metadata = getattr(self, 'get_{}_metadata'.format(ext))
return id3_encoding
raise ValueError(text_list)
- def convert_flac_to_mp3(self, source, target):
- self.convert_flac_to_wav(source, self._tempfile)
- self.convert_wav_to_mp3(self._tempfile, target)
-
def convert_flac_to_wav(self, source, target):
invoke(['ogg123', '-d', 'wav', '-f', target, source])
invoke(['oggenc', '--quiet', '-q', '3', source, '-o', target])
convert_flac_to_ogg.handles_metadata = True
- def convert_mp3_to_flac(self, source, target):
- self.convert_mp3_to_wav(source, self._tempfile)
- self.convert_wav_to_flac(self._tempfile, target)
-
- def convert_mp3_to_ogg(self, source, target):
- self.convert_mp3_to_wav(source, self._tempfile)
- self.convert_wav_to_ogg(self._tempfile, target)
def convert_mp3_to_wav(self, source, target):
invoke(['mpg123', '-w', target, source])
- def convert_ogg_to_flac(self, source, target):
- self.convert_ogg_to_wav(source, self._tempfile)
- self.convert_wav_to_flac(self._tempfile, target)
-
- def convert_ogg_to_mp3(self, source, target):
- self.convert_flac_to_mp3(source, target)
-
def convert_ogg_to_wav(self, source, target):
self.convert_flac_to_wav(source, target)