mp3togo version 0.5.2
/mp3togo/helpers.py
blob:3627b994e25512df43697db0c5e9d1b3f8411a13 -> blob:af0baded076a5bebb62a8db5b3010511d0442e48
--- mp3togo/helpers.py
+++ mp3togo/helpers.py
@@ -140,6 +140,21 @@ def recode_wav(input, output, args=None)
input to output. Throws OSError on error."""
return lambda: shutil.copyfile(input, output)
+def parse_m4a_dec(buf):
+ n = buf.find('% decoding')
+ # if n==1 then we are at single digit progress (i.e. 5%) and
+ # at the beginning of the buffer
+ if n == 1:
+ s = buf[0]
+ # else we are somewhere deeper in the buffer...check if we are at
+ # single or double digit progress by looking two characters back
+ elif buf[n-2] == '\n':
+ s = buf[n-1:n]
+ else:
+ s = buf[n-2:n]
+ return int(s)
+
+
## Command line escape sequences:
#
# escape: for:
@@ -178,6 +193,10 @@ helpers = {
'cmd': 'flac --decode -F -o %o %i',
'type': 'flac',
'action': 'decode'},
+ 'm4a_dec':{'parser': parse_m4a_dec,
+ 'cmd': 'faad -o %o %i',
+ 'type': 'm4a',
+ 'action': 'decode'},
'wav_dec': {'parser': None,
'cmd': recode_wav,
'type': 'wav',
@@ -221,5 +240,5 @@ def make_args(helper, input, output, arg
def est_decoded_size(filename):
# This could be much better
tp = conf.getfiletype(filename)
- factors = {'mp3': 16.5, 'ogg': 16.5, 'flac': 2.8, 'wav': 1}
+ factors = {'mp3': 16.5, 'ogg': 16.5, 'flac': 2.8, 'wav': 1, 'm4a': 16.5}
return os.stat(filename).st_size * factors[tp]