Code help on launching an import from within a plugin

I am working on a plugin and I would like to launch an import session from code. I have a specific staging directory that I would like to point the import to and have it run in the normal interactive mode. I have been trying to get beets.ui.commands import_files(lib, paths, query) to work for me. Can’t seem to get it to work.

For parameters, I am passing the path to the staging directory in via the paths parameter. In my mind there is no query, but if I leave that blank, the import does indeed fire up, but it appears that it is running for the entire library instead of the staging directory. Thought maybe that paths means something else and I should be putting the staging directory in as the query. Tried that and the command did not return.

Is there another way to do this? Am I just confused about the parameters? Any help will be appreciated.

A little more information, hopefully it will stir some thoughts. I have tried various permutations of this and this is where I stand.

I have a path variable that contains the path to my staging directory. It looks like this -
path_variable = ‘/Volumes/share/tempmusic/artist/album’

That directory holds the files that I would like to import. I am calling the function like this -
import_files(lib, path_variable, None)

Note that I am setting the query parameter to None. When I call this function, it is kicking off the import, but it appears that it is starting an import at my root directory (‘/’). If I cancel and try again, it pops up and says that it is “Resuming interrupted import of /”

In my mind that means I am not specifying the path variable correctly. Could it be that it requires it to be in another format (either literally or variable type)?

Maybe there is another way to invoke the import function and I am way off base here, but it seems to be a valid path to take. Thanks in advance for any insight you can share.

It looks like the paths argument should be a list as opposed to a string:

import_files(lib, ['/path/to/import'], None)
2 Likes

You are the man! Worked like a charm. Thanks for your help.

1 Like