convert auto: changelog and de-cloning (#212)

This commit is contained in:
Adrian Sampson 2013-03-10 13:12:56 -07:00
parent 47a549a31c
commit 8736a0bb4c
3 changed files with 23 additions and 11 deletions

View file

@ -27,7 +27,7 @@ from beets import config
log = logging.getLogger('beets')
DEVNULL = open(os.devnull, 'wb')
_fs_lock = threading.Lock()
_convert_tmp = []
_temp_files = [] # Keep track of temporary transcoded files for deletion.
def _destination(lib, dest_dir, item, keep_new):
@ -62,6 +62,14 @@ def encode(source, dest):
log.info(u'Finished encoding {0}'.format(util.displayable_path(source)))
def should_transcode(item):
"""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)
return item.format != 'MP3' or item.bitrate >= 1000 * maxbr
def convert_item(lib, dest_dir, keep_new):
while True:
item = yield
@ -87,8 +95,7 @@ def convert_item(lib, dest_dir, keep_new):
format(util.displayable_path(dest)))
util.move(item.path, dest)
maxbr = config['convert']['max_bitrate'].get(int)
if item.format == 'MP3' and item.bitrate < 1000 * maxbr:
if not should_transcode(item):
# No transcoding necessary.
log.info(u'Copying {0}'.format(util.displayable_path(item.path)))
if keep_new:
@ -123,15 +130,16 @@ def convert_item(lib, dest_dir, keep_new):
def convert_on_import(lib, item):
maxbr = config['convert']['max_bitrate'].get(int)
if item.format != 'MP3' or item.bitrate >= 1000 * maxbr:
# Transcoding necessary
"""Transcode a file automatically after it is imported into the
library.
"""
if should_transcode(item):
dest = os.path.splitext(item.path)[0] + '.mp3'
_convert_tmp.append(dest)
_temp_files.append(dest) # Delete the transcode later.
encode(item.path, dest)
item.path = dest
item.write()
item.read()
item.read() # Load new audio information data.
lib.store(item)
@ -200,7 +208,7 @@ class ConvertPlugin(BeetsPlugin):
@ConvertPlugin.listen('import_task_files')
def _cleanup(task, session):
for path in task.old_paths:
if path in _convert_tmp:
if path in _temp_files:
if os.path.isfile(path):
util.remove(path)
_convert_tmp.remove(path)
_temp_files.remove(path)

View file

@ -25,6 +25,8 @@ Other stuff:
* :doc:`/plugins/convert`: A new ``--keep-new`` option lets you store
transcoded files in your library while backing up the originals (instead of
vice-versa). Thanks to Lucas Duailibe.
* :doc:`/plugins/convert`: Also, a new ``auto`` config option will transcode
audio files automatically during import. Thanks again to Lucas Duailibe.
* :doc:`/plugins/echonest_tempo`: API errors now issue a warning instead of
exiting with an exception. We also avoid an error when track metadata
contains newlines.

View file

@ -58,7 +58,9 @@ The plugin offers several configuration options, all of which live under the
<num>".) If you want to specify a bitrate, use "-ab <bitrate>". Refer to the
`FFmpeg`_ documentation for more details.
* ``auto`` gives you the option to import transcoded versions of your files
automatically during the ``import`` command.
automatically during the ``import`` command. With this option enabled, the
importer will transcode all non-MP3 files over the maximum bitrate before
adding them to your library.
* Finally, ``threads`` determines the number of threads to use for parallel
encoding. By default, the plugin will detect the number of processors
available and use them all.