That is super helpful and gives me a great place to start. Unfortunately, I’ve spent a bit of time poking at the problem since and I’m struggling with two problems: a runtime error, and difficulty manipulating the config object. Here’s my super simple autobeet.py:
from beets import config
from beets import importer
from beets.ui import _open_library
from beets.autotag import Recommendation
class Autobeets(object):
class AutoImportSession(importer.ImportSession):
def should_resume(self, path):
return True
def choose_match(self, task):
if task.rec == Recommendation.strong:
return importer.action.APPLY
else:
return importer.action.SKIP
def resolve_duplicate(self, task, found_duplicates):
return importer.action.SKIP
def choose_item(self, task):
if task.rec == Recommendation.strong:
return importer.action.APPLY
else:
return importer.action.SKIP
def __init__(self, config_file, music_db):
config.set_file(config_file)
config.resolve()
self.lib = _open_library(config)
def import_directory(self, import_dir):
query = None
logger = None
self.session = Autobeets.AutoImportSession(self.lib, logger, [import_dir], query)
self.session.run()
And here’s what is calling it:
#!/usr/bin/python3
import os
import sys
import autobeet
def main():
config_file = 'autobeet.yaml'
library_path = 'autobeet.blb'
beets = autobeet.Autobeets(config_file, library_path)
beets.import_directory('inbox/Artist - Album (2011) [FLAC]')
if __name__ == "__main__":
main()
First up, here’s the error:
Traceback (most recent call last):
File "./import.py", line 14, in <module>
main()
File "./import.py", line 11, in main
beets.import_directory('inbox/Gang Gang Dance - Eye Contact (2011) [FLAC]')
File "/home/michaelmacleod/autobeet/autobeet.py", line 40, in import_directory
self.session.run()
File "/usr/local/lib/python3.4/dist-packages/beets/importer.py", line 325, in run
pl.run_parallel(QUEUE_SIZE)
File "/usr/local/lib/python3.4/dist-packages/beets/util/pipeline.py", line 445, in run_parallel
six.reraise(exc_info[0], exc_info[1], exc_info[2])
File "/usr/local/lib/python3.4/dist-packages/six.py", line 693, in reraise
raise value
File "/usr/local/lib/python3.4/dist-packages/beets/util/pipeline.py", line 312, in run
out = self.coro.send(msg)
File "/usr/local/lib/python3.4/dist-packages/beets/util/pipeline.py", line 171, in coro
task = func(*(args + (task,)))
File "/usr/local/lib/python3.4/dist-packages/beets/importer.py", line 1317, in user_query
task.choose_match(session)
File "/usr/local/lib/python3.4/dist-packages/beets/importer.py", line 800, in choose_match
self.set_choice(choice)
File "/usr/local/lib/python3.4/dist-packages/beets/importer.py", line 454, in set_choice
assert choice != action.APPLY # Only used internally.
AssertionError
And the second problem is I can’t figure out how to manipulate the config object without overwriting the whole thing. I’ve been looking through the beets ui code, and I see many examples where the config object is modified like a regular dict, but if I try and overwite any settings as if it were a dict it gets replaced entirely with only my override.
I’d appreciate any ideas on either subject.
Thanks