def user_query(session): """A coroutine for interfacing with the user about the tagging process. The coroutine accepts an ImportTask objects. It uses the session's ``choose_match`` method to determine the ``action`` for this task. Depending on the action additional stages are exectuted and the processed task is yielded. It emits the ``import_task_choice`` event for plugins. Plugins have acces to the choice via the ``taks.choice_flag`` property and may choose to change it. """ recent = set() task = None while True: task = yield task if task.should_skip(): continue # Ask the user for a choice. choice = session.choose_match(task) task.set_choice(choice) session.log_choice(task) plugins.send("import_task_choice", session=session, task=task) # As-tracks: transition to singleton workflow. if task.choice_flag is action.TRACKS: # Set up a little pipeline for dealing with the singletons. def emitter(task): for item in task.items: yield ImportTask.item_task(item) yield ImportTask.progress_sentinel(task.toppath, task.paths) ipl = pipeline.Pipeline([emitter(task), item_lookup(session), item_query(session)]) task = pipeline.multiple(ipl.pull()) continue # As albums: group items by albums and create task for each album if task.choice_flag is action.ALBUMS: def emitter(task): yield task ipl = pipeline.Pipeline( [emitter(task), group_albums(session), initial_lookup(session), user_query(session)] ) task = pipeline.multiple(ipl.pull()) continue # Check for duplicates if we have a match (or ASIS). if task.choice_flag in (action.ASIS, action.APPLY): ident = task.chosen_ident() # The "recent" set keeps track of identifiers for recently # imported albums -- those that haven't reached the database # yet. if ident in recent or _duplicate_check(session.lib, task): session.resolve_duplicate(task) session.log_choice(task, True) recent.add(ident)
def user_query(session): """A coroutine for interfacing with the user about the tagging process. lib is the Library to import into and logfile may be a file-like object for logging the import process. The coroutine accepts and yields ImportTask objects. """ recent = set() task = None while True: task = yield task if task.sentinel: continue # Ask the user for a choice. choice = session.choose_match(task) task.set_choice(choice) session.log_choice(task) plugins.send('import_task_choice', session=session, task=task) # As-tracks: transition to singleton workflow. if choice is action.TRACKS: # Set up a little pipeline for dealing with the singletons. def emitter(task): for item in task.items: yield ImportTask.item_task(item) yield ImportTask.progress_sentinel(task.toppath, task.paths) ipl = pipeline.Pipeline([ emitter(task), item_lookup(session), item_query(session), ]) task = pipeline.multiple(ipl.pull()) continue # As albums: group items by albums and create task for each album if choice is action.ALBUMS: def emitter(task): yield task ipl = pipeline.Pipeline([ emitter(task), group_albums(session), initial_lookup(session), user_query(session) ]) task = pipeline.multiple(ipl.pull()) continue # Check for duplicates if we have a match (or ASIS). if task.choice_flag in (action.ASIS, action.APPLY): ident = task.chosen_ident() # The "recent" set keeps track of identifiers for recently # imported albums -- those that haven't reached the database # yet. if ident in recent or _duplicate_check(session.lib, task): session.resolve_duplicate(task) session.log_choice(task, True) recent.add(ident)
def user_query(session): """A coroutine for interfacing with the user about the tagging process. lib is the Library to import into and logfile may be a file-like object for logging the import process. The coroutine accepts and yields ImportTask objects. """ recent = set() task = None while True: task = yield task if task.should_skip(): continue # Ask the user for a choice. choice = session.choose_match(task) task.set_choice(choice) session.log_choice(task) plugins.send('import_task_choice', session=session, task=task) # As-tracks: transition to singleton workflow. if choice is action.TRACKS: # Set up a little pipeline for dealing with the singletons. def emitter(task): for item in task.items: yield ImportTask.item_task(item) yield ImportTask.progress_sentinel(task.toppath, task.paths) ipl = pipeline.Pipeline([ emitter(task), item_lookup(session), item_query(session), ]) task = pipeline.multiple(ipl.pull()) continue # As albums: group items by albums and create task for each album if choice is action.ALBUMS: def emitter(task): yield task ipl = pipeline.Pipeline([ emitter(task), group_albums(session), initial_lookup(session), user_query(session) ]) task = pipeline.multiple(ipl.pull()) continue # Check for duplicates if we have a match (or ASIS). if task.choice_flag in (action.ASIS, action.APPLY): ident = task.chosen_ident() # The "recent" set keeps track of identifiers for recently # imported albums -- those that haven't reached the database # yet. if ident in recent or _duplicate_check(session.lib, task): session.resolve_duplicate(task) session.log_choice(task, True) recent.add(ident)
def user_query(session, task): """A coroutine for interfacing with the user about the tagging process. The coroutine accepts an ImportTask objects. It uses the session's `choose_match` method to determine the `action` for this task. Depending on the action additional stages are exectuted and the processed task is yielded. It emits the ``import_task_choice`` event for plugins. Plugins have acces to the choice via the ``taks.choice_flag`` property and may choose to change it. """ if task.skip: return task # Ask the user for a choice. task.choose_match(session) plugins.send('import_task_choice', session=session, task=task) # As-tracks: transition to singleton workflow. if task.choice_flag is action.TRACKS: # Set up a little pipeline for dealing with the singletons. def emitter(task): for item in task.items: yield SingletonImportTask(task.toppath, item) yield SentinelImportTask(task.toppath, task.paths) ipl = pipeline.Pipeline([ emitter(task), lookup_candidates(session), user_query(session), ]) return pipeline.multiple(ipl.pull()) # As albums: group items by albums and create task for each album if task.choice_flag is action.ALBUMS: ipl = pipeline.Pipeline([ iter([task]), group_albums(session), lookup_candidates(session), user_query(session) ]) return pipeline.multiple(ipl.pull()) resolve_duplicates(session, task) return task
def user_query(session, task): """A coroutine for interfacing with the user about the tagging process. The coroutine accepts an ImportTask objects. It uses the session's `choose_match` method to determine the `action` for this task. Depending on the action additional stages are exectuted and the processed task is yielded. It emits the ``import_task_choice`` event for plugins. Plugins have acces to the choice via the ``taks.choice_flag`` property and may choose to change it. """ if task.skip: return task # Ask the user for a choice. task.choose_match(session) plugins.send('import_task_choice', session=session, task=task) # As-tracks: transition to singleton workflow. if task.choice_flag is action.TRACKS: # Set up a little pipeline for dealing with the singletons. def emitter(task): for item in task.items: yield SingletonImportTask(item) yield SentinelImportTask(task.toppath, task.paths) ipl = pipeline.Pipeline([ emitter(task), lookup_candidates(session), user_query(session), ]) return pipeline.multiple(ipl.pull()) # As albums: group items by albums and create task for each album if task.choice_flag is action.ALBUMS: ipl = pipeline.Pipeline([ iter([task]), group_albums(session), lookup_candidates(session), user_query(session) ]) return pipeline.multiple(ipl.pull()) resolve_duplicates(session, task) return task
def user_query(session): """A coroutine for interfacing with the user about the tagging process. lib is the Library to import into and logfile may be a file-like object for logging the import process. The coroutine accepts and yields ImportTask objects. """ recent = set() task = None while True: task = yield task if task.sentinel: continue # Ask the user for a choice. choice = session.choose_match(task) task.set_choice(choice) session.log_choice(task) plugins.send('import_task_choice', session=session, task=task) # As-tracks: transition to singleton workflow. if choice is action.TRACKS: # Set up a little pipeline for dealing with the singletons. item_tasks = [] def emitter(): for item in task.items: yield ImportTask.item_task(item) yield ImportTask.progress_sentinel(task.toppath, task.paths) def collector(): while True: item_task = yield item_tasks.append(item_task) ipl = pipeline.Pipeline((emitter(), item_lookup(session), item_query(session), collector())) ipl.run_sequential() task = pipeline.multiple(item_tasks) continue # Check for duplicates if we have a match (or ASIS). if task.choice_flag in (action.ASIS, action.APPLY): ident = task.chosen_ident() # The "recent" set keeps track of identifiers for recently # imported albums -- those that haven't reached the database # yet. task.duplicates = _duplicate_check(session.lib, task) if ident in recent: # TODO: Somehow manage duplicate hooks for recents pass plugins.send('import_task_duplicate', session=session, task=task) if task.duplicates: session.resolve_duplicate(task) session.log_choice(task, True) recent.add(ident)
def user_query(config): """A coroutine for interfacing with the user about the tagging process. lib is the Library to import into and logfile may be a file-like object for logging the import process. The coroutine accepts and yields ImportTask objects. """ lib = _reopen_lib(config.lib) task = None while True: task = yield task if task.sentinel: continue # Ask the user for a choice. choice = config.choose_match_func(task, config) task.set_choice(choice) # As-tracks: transition to singleton workflow. if choice is action.TRACKS: # Set up a little pipeline for dealing with the singletons. item_tasks = [] def emitter(): for item in task.items: yield ImportTask.item_task(item) def collector(): while True: item_task = yield item_tasks.append(item_task) ipl = pipeline.Pipeline((emitter(), item_lookup(config), item_query(config), collector())) ipl.run_sequential() task = pipeline.multiple(item_tasks) # Log certain choices. if choice is action.ASIS: tag_log(config.logfile, 'asis', task.path) elif choice is action.SKIP: tag_log(config.logfile, 'skip', task.path) # Check for duplicates if we have a match (or ASIS). if choice is action.ASIS or isinstance(choice, tuple): if choice is action.ASIS: artist = task.cur_artist album = task.cur_album else: artist = task.info['artist'] album = task.info['album'] if _duplicate_check(lib, artist, album): tag_log(config.logfile, 'duplicate', task.path) log.warn("This album is already in the library!") task.set_choice(action.SKIP)
def group_albums(session): """Group the items of a task by albumartist and album name and create a new task for each album. Yield the tasks as a multi message. """ def group(item): return (item.albumartist or item.artist, item.album) task = None while True: task = yield task if task.skip: continue tasks = [] for _, items in itertools.groupby(task.items, group): tasks.append(ImportTask(items=list(items))) tasks.append(SentinelImportTask(task.toppath, task.paths)) task = pipeline.multiple(tasks)
def _multi_work(): i = None while True: i = yield i i = pipeline.multiple([i, -i])
def user_query(session): """A coroutine for interfacing with the user about the tagging process. The coroutine accepts an ImportTask objects. It uses the session's ``choose_match`` method to determine the ``action`` for this task. Depending on the action additional stages are exectuted and the processed task is yielded. It emits the ``import_task_choice`` event for plugins. Plugins have acces to the choice via the ``taks.choice_flag`` property and may choose to change it. """ recent = set() task = None while True: task = yield task if task.should_skip(): continue # Ask the user for a choice. choice = session.choose_match(task) task.set_choice(choice) session.log_choice(task) plugins.send('import_task_choice', session=session, task=task) # As-tracks: transition to singleton workflow. if task.choice_flag is action.TRACKS: # Set up a little pipeline for dealing with the singletons. def emitter(task): for item in task.items: yield ImportTask.item_task(item) yield ImportTask.progress_sentinel(task.toppath, task.paths) ipl = pipeline.Pipeline([ emitter(task), item_lookup(session), item_query(session), ]) task = pipeline.multiple(ipl.pull()) continue # As albums: group items by albums and create task for each album if task.choice_flag is action.ALBUMS: def emitter(task): yield task ipl = pipeline.Pipeline([ emitter(task), group_albums(session), initial_lookup(session), user_query(session) ]) task = pipeline.multiple(ipl.pull()) continue # Check for duplicates if we have a match (or ASIS). if task.choice_flag in (action.ASIS, action.APPLY): ident = task.chosen_ident() # The "recent" set keeps track of identifiers for recently # imported albums -- those that haven't reached the database # yet. if ident in recent or _duplicate_check(session.lib, task): session.resolve_duplicate(task) session.log_choice(task, True) recent.add(ident)