Adrian Sampson  committed 86f5cee

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

  • Participants
  • Parent commits 85d4777

Comments (0)

Files changed (3)

File beetsplug/

 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):'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
             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.
   'Copying {0}'.format(util.displayable_path(item.path)))
             if 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
+  # Load new audio information data.
 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):
-            _convert_tmp.remove(path)
+            _temp_files.remove(path)

File docs/changelog.rst

 * :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.

File docs/plugins/convert.rst

   <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.