mirror of
https://github.com/beetbox/beets.git
synced 2025-12-07 09:04:33 +01:00
Check conversion against custom format
This commit is contained in:
parent
8b73681cf3
commit
114d3f95bd
1 changed files with 8 additions and 11 deletions
|
|
@ -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])
|
||||
|
|
|
|||
Loading…
Reference in a new issue