diff --git a/beets/importer.py b/beets/importer.py index 9436df424..1c30b9794 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -24,6 +24,7 @@ from beets import autotag from beets import library import beets.autotag.art from beets import plugins +from beets.ui import pipeline CHOICE_SKIP = 'CHOICE_SKIP' CHOICE_ASIS = 'CHOICE_ASIS' @@ -122,7 +123,8 @@ class ImportConfig(object): """ __slots__ = ['lib', 'paths', 'resume', 'logfile', 'color', 'quiet', 'quiet_fallback', 'copy', 'write', 'art', 'delete', - 'choose_match_func', 'should_resume_func'] + 'choose_match_func', 'should_resume_func', 'threaded', + 'autot'] def __init__(self, **kwargs): for slot in self.__slots__: setattr(self, slot, kwargs[slot]) @@ -434,3 +436,31 @@ def simple_import(config): os.remove(library._syspath(old_path)) log.info('added album: %s - %s' % (album.albumartist, album.album)) + + +# Main driver. + +def run_import(**kwargs): + config = ImportConfig(**kwargs) + + if config.autot: + # Autotag. Set up the pipeline. + pl = pipeline.Pipeline([ + read_albums(config), + initial_lookup(config), + user_query(config), + apply_choices(config), + ]) + + # Run the pipeline. + try: + if config.threaded: + pl.run_parallel(QUEUE_SIZE) + else: + pl.run_sequential() + except ImportAbort: + # User aborted operation. Silently stop. + pass + else: + # Simple import without autotagging. Always sequential. + simple_import(config) diff --git a/beets/ui/commands.py b/beets/ui/commands.py index e3143715b..b4ec0dd23 100755 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -24,7 +24,6 @@ from beets import ui from beets.ui import print_ from beets import autotag import beets.autotag.art -from beets.ui import pipeline from beets import plugins from beets import importer from beets import library @@ -318,11 +317,11 @@ def import_files(lib, paths, copy, write, autot, logpath, art, threaded, if resume is None and quiet: resume = False - # Set up import configuration. - config = importer.ImportConfig( + # Perform the import. + importer.run_import( + lib = lib, paths = paths, resume = resume, - lib = lib, logfile = logfile, color = color, quiet = quiet, @@ -331,33 +330,12 @@ def import_files(lib, paths, copy, write, autot, logpath, art, threaded, write = write, art = art, delete = delete, + threaded = threaded, + autot = autot, choose_match_func = choose_match, should_resume_func = should_resume, ) - # Perform the import. - if autot: - # Autotag. Set up the pipeline. - pl = pipeline.Pipeline([ - importer.read_albums(config), - importer.initial_lookup(config), - importer.user_query(config), - importer.apply_choices(config), - ]) - - # Run the pipeline. - try: - if threaded: - pl.run_parallel(importer.QUEUE_SIZE) - else: - pl.run_sequential() - except importer.ImportAbort: - # User aborted operation. Silently stop. - pass - else: - # Simple import without autotagging. Always sequential. - importer.simple_import(config) - # If we were logging, close the file. if logfile: logfile.close() diff --git a/test/_common.py b/test/_common.py index 8fc2dfed4..f6628634a 100644 --- a/test/_common.py +++ b/test/_common.py @@ -55,6 +55,8 @@ def iconfig(lib, **kwargs): delete = False, choose_match_func = lambda x, y: importer.CHOICE_SKIP, should_resume_func = lambda _: False, + threaded = False, + autot = True, ) for k, v in kwargs.items(): setattr(config, k, v)