From 114d3f95bd5beb7b81df59bde56a75e8ce46865c Mon Sep 17 00:00:00 2001 From: Thomas Scholtes Date: Tue, 9 Sep 2014 22:06:18 +0200 Subject: [PATCH] Check conversion against custom format --- beetsplug/convert.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/beetsplug/convert.py b/beetsplug/convert.py index 44c0afa99..2799355a8 100644 --- a/beetsplug/convert.py +++ b/beetsplug/convert.py @@ -124,18 +124,17 @@ def encode(command, source, dest, pretend=False): ) -def should_transcode(item): +def should_transcode(item, format): """Determine whether the item should be transcoded as part of conversion (i.e., its bitrate is high or it has the wrong format). """ maxbr = config['convert']['max_bitrate'].get(int) - format_name = config['convert']['format'].get(unicode) - return format_name.lower() != item.format.lower() or \ + return format.lower() != item.format.lower() or \ item.bitrate >= 1000 * maxbr -def convert_item(dest_dir, keep_new, path_formats, command, ext, - pretend=False): +def convert_item(dest_dir, keep_new, path_formats, format, pretend=False): + command, ext = get_format(format) while True: item = yield dest = item.destination(basedir=dest_dir, path_formats=path_formats) @@ -176,7 +175,7 @@ def convert_item(dest_dir, keep_new, path_formats, command, ext, ) util.move(item.path, original) - if not should_transcode(item): + if not should_transcode(item, format): if pretend: log.info(u'cp {0} {1}'.format( util.displayable_path(original), @@ -219,7 +218,8 @@ def convert_on_import(lib, item): """Transcode a file automatically after it is imported into the library. """ - if should_transcode(item): + format = config['convert']['format'].get(unicode).lower() + if should_transcode(item, format): command, ext = get_format() fd, dest = tempfile.mkstemp(ext) os.close(fd) @@ -252,8 +252,6 @@ def convert_func(lib, opts, args): if not opts.format: opts.format = config['convert']['format'].get(unicode).lower() - command, ext = get_format(opts.format) - pretend = opts.pretend if opts.pretend is not None else \ config['convert']['pretend'].get(bool) @@ -270,8 +268,7 @@ def convert_func(lib, opts, args): convert = [convert_item(opts.dest, opts.keep_new, path_formats, - command, - ext, + opts.format, pretend) for _ in range(opts.threads)] pipe = util.pipeline.Pipeline([items, convert])