mirror of
https://github.com/beetbox/beets.git
synced 2025-12-08 01:23:09 +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
|
"""Determine whether the item should be transcoded as part of
|
||||||
conversion (i.e., its bitrate is high or it has the wrong format).
|
conversion (i.e., its bitrate is high or it has the wrong format).
|
||||||
"""
|
"""
|
||||||
maxbr = config['convert']['max_bitrate'].get(int)
|
maxbr = config['convert']['max_bitrate'].get(int)
|
||||||
format_name = config['convert']['format'].get(unicode)
|
return format.lower() != item.format.lower() or \
|
||||||
return format_name.lower() != item.format.lower() or \
|
|
||||||
item.bitrate >= 1000 * maxbr
|
item.bitrate >= 1000 * maxbr
|
||||||
|
|
||||||
|
|
||||||
def convert_item(dest_dir, keep_new, path_formats, command, ext,
|
def convert_item(dest_dir, keep_new, path_formats, format, pretend=False):
|
||||||
pretend=False):
|
command, ext = get_format(format)
|
||||||
while True:
|
while True:
|
||||||
item = yield
|
item = yield
|
||||||
dest = item.destination(basedir=dest_dir, path_formats=path_formats)
|
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)
|
util.move(item.path, original)
|
||||||
|
|
||||||
if not should_transcode(item):
|
if not should_transcode(item, format):
|
||||||
if pretend:
|
if pretend:
|
||||||
log.info(u'cp {0} {1}'.format(
|
log.info(u'cp {0} {1}'.format(
|
||||||
util.displayable_path(original),
|
util.displayable_path(original),
|
||||||
|
|
@ -219,7 +218,8 @@ def convert_on_import(lib, item):
|
||||||
"""Transcode a file automatically after it is imported into the
|
"""Transcode a file automatically after it is imported into the
|
||||||
library.
|
library.
|
||||||
"""
|
"""
|
||||||
if should_transcode(item):
|
format = config['convert']['format'].get(unicode).lower()
|
||||||
|
if should_transcode(item, format):
|
||||||
command, ext = get_format()
|
command, ext = get_format()
|
||||||
fd, dest = tempfile.mkstemp(ext)
|
fd, dest = tempfile.mkstemp(ext)
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
|
|
@ -252,8 +252,6 @@ def convert_func(lib, opts, args):
|
||||||
if not opts.format:
|
if not opts.format:
|
||||||
opts.format = config['convert']['format'].get(unicode).lower()
|
opts.format = config['convert']['format'].get(unicode).lower()
|
||||||
|
|
||||||
command, ext = get_format(opts.format)
|
|
||||||
|
|
||||||
pretend = opts.pretend if opts.pretend is not None else \
|
pretend = opts.pretend if opts.pretend is not None else \
|
||||||
config['convert']['pretend'].get(bool)
|
config['convert']['pretend'].get(bool)
|
||||||
|
|
||||||
|
|
@ -270,8 +268,7 @@ def convert_func(lib, opts, args):
|
||||||
convert = [convert_item(opts.dest,
|
convert = [convert_item(opts.dest,
|
||||||
opts.keep_new,
|
opts.keep_new,
|
||||||
path_formats,
|
path_formats,
|
||||||
command,
|
opts.format,
|
||||||
ext,
|
|
||||||
pretend)
|
pretend)
|
||||||
for _ in range(opts.threads)]
|
for _ in range(opts.threads)]
|
||||||
pipe = util.pipeline.Pipeline([items, convert])
|
pipe = util.pipeline.Pipeline([items, convert])
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue