mirror of
https://github.com/beetbox/beets.git
synced 2025-12-27 19:12:40 +01:00
move main importer driver logic to importer module
This commit is contained in:
parent
dffdbce5f1
commit
3222cc6213
3 changed files with 38 additions and 28 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue