mirror of
https://github.com/beetbox/beets.git
synced 2026-01-06 07:53:40 +01:00
remove special-cased non-autotagged import function (simple_import)
This commit is contained in:
parent
856631a8a3
commit
fcee8b2ab6
3 changed files with 47 additions and 62 deletions
|
|
@ -282,18 +282,18 @@ def initial_lookup(config):
|
|||
(items, cur_artist, cur_album, candidates, rec) tuples. If no match
|
||||
is found, all of the yielded parameters (except items) are None.
|
||||
"""
|
||||
task = yield
|
||||
log.debug('Looking up: %s' % task.path)
|
||||
task = None
|
||||
while True:
|
||||
task = yield task
|
||||
if task.sentinel:
|
||||
task = yield task
|
||||
continue
|
||||
|
||||
log.debug('Looking up: %s' % task.path)
|
||||
try:
|
||||
task.set_match(*autotag.tag_album(task.items))
|
||||
except autotag.AutotagError:
|
||||
task.set_null_match()
|
||||
task = yield task
|
||||
|
||||
def user_query(config):
|
||||
"""A coroutine for interfacing with the user about the tagging
|
||||
|
|
@ -330,6 +330,23 @@ def user_query(config):
|
|||
tag_log(config.logfile, 'duplicate', task.path)
|
||||
log.warn("This album is already in the library!")
|
||||
task.set_choice(action.SKIP)
|
||||
|
||||
def show_progress(config):
|
||||
"""This stage replaces the initial_lookup and user_query stages
|
||||
when the importer is run without autotagging. It displays the album
|
||||
name and artist as the files are added.
|
||||
"""
|
||||
task = None
|
||||
while True:
|
||||
task = yield task
|
||||
if task.sentinel:
|
||||
continue
|
||||
|
||||
log.info(task.path)
|
||||
|
||||
# Behave as if ASIS were selected.
|
||||
task.set_null_match()
|
||||
task.set_choice(action.ASIS)
|
||||
|
||||
def apply_choices(config):
|
||||
"""A coroutine for applying changes to albums during the autotag
|
||||
|
|
@ -398,66 +415,32 @@ def apply_choices(config):
|
|||
task.save_progress()
|
||||
|
||||
|
||||
# Non-autotagged import (always sequential).
|
||||
#TODO probably no longer necessary; use the same machinery?
|
||||
|
||||
def simple_import(config):
|
||||
"""Add albums from the paths to the library without changing any
|
||||
tags.
|
||||
"""
|
||||
for task in read_albums(config):
|
||||
if task.sentinel:
|
||||
task.save_progress()
|
||||
continue
|
||||
|
||||
if config.copy:
|
||||
if config.delete:
|
||||
old_paths = [os.path.realpath(item.path) for item in task.items]
|
||||
for item in task.items:
|
||||
item.move(config.lib, True, True)
|
||||
|
||||
album = config.lib.add_album(task.items, True)
|
||||
config.lib.save()
|
||||
|
||||
# Announce that we added an album.
|
||||
plugins.send('album_imported', lib=config.lib, album=album)
|
||||
|
||||
if config.resume is not False:
|
||||
task.save_progress()
|
||||
|
||||
if config.copy and config.delete:
|
||||
new_paths = [os.path.realpath(item.path) for item in task.items]
|
||||
for old_path in old_paths:
|
||||
# Only delete files that were actually moved.
|
||||
if old_path not in new_paths:
|
||||
os.remove(syspath(old_path))
|
||||
|
||||
log.info('added album: %s - %s' % (album.albumartist, album.album))
|
||||
|
||||
|
||||
# Main driver.
|
||||
|
||||
def run_import(**kwargs):
|
||||
"""Run an import. The keyword arguments are the same as those to
|
||||
ImportConfig.
|
||||
"""
|
||||
config = ImportConfig(**kwargs)
|
||||
|
||||
# Set up the pipeline.
|
||||
stages = [read_albums(config)]
|
||||
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
|
||||
# Only look up and query the user when autotagging.
|
||||
stages += [initial_lookup(config), user_query(config)]
|
||||
else:
|
||||
# Simple import without autotagging. Always sequential.
|
||||
simple_import(config)
|
||||
# When not autotagging, just display progress.
|
||||
stages += [show_progress(config)]
|
||||
stages += [apply_choices(config)]
|
||||
pl = pipeline.Pipeline(stages)
|
||||
|
||||
# Run the pipeline.
|
||||
try:
|
||||
if config.threaded:
|
||||
pl.run_parallel(QUEUE_SIZE)
|
||||
else:
|
||||
pl.run_sequential()
|
||||
except ImportAbort:
|
||||
# User aborted operation. Silently stop.
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ class Pipeline(object):
|
|||
coros = [stage[0] for stage in self.stages]
|
||||
|
||||
# "Prime" the coroutines.
|
||||
for coro in coros:
|
||||
for coro in coros[1:]:
|
||||
coro.next()
|
||||
|
||||
# Begin the pipeline.
|
||||
|
|
@ -258,7 +258,6 @@ class Pipeline(object):
|
|||
for coro in self.stages[0]:
|
||||
threads.append(FirstPipelineThread(coro, queues[0], threads))
|
||||
|
||||
|
||||
# Middle stages.
|
||||
for i in range(1, len(self.stages)-1):
|
||||
for coro in self.stages[i]:
|
||||
|
|
|
|||
|
|
@ -33,13 +33,14 @@ TEST_TITLES = ('The Opener','The Second Track','The Last Track')
|
|||
class ImportTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.io = _common.DummyIO()
|
||||
self.io.install()
|
||||
#self.io.install()
|
||||
|
||||
# Suppress logging output.
|
||||
log = logging.getLogger('beets')
|
||||
log.setLevel(logging.CRITICAL)
|
||||
|
||||
self.lib = library.Library(':memory:')
|
||||
self.libdb = os.path.join('rsrc', 'testlib.blb')
|
||||
self.lib = library.Library(self.libdb)
|
||||
self.libdir = os.path.join('rsrc', 'testlibdir')
|
||||
self.lib.directory = self.libdir
|
||||
self.lib.path_formats = {
|
||||
|
|
@ -50,6 +51,8 @@ class ImportTest(unittest.TestCase):
|
|||
|
||||
def tearDown(self):
|
||||
self.io.restore()
|
||||
if os.path.exists(self.libdb):
|
||||
os.remove(self.libdb)
|
||||
if os.path.exists(self.libdir):
|
||||
shutil.rmtree(self.libdir)
|
||||
if os.path.exists(self.srcdir):
|
||||
|
|
|
|||
Loading…
Reference in a new issue