Repository: beetbox/beets

Issue:
Import: allow edit right after applying search results
Feature request. Often the information retrieved automatically by search engines during the import procedure needs some corrections (e.g. most CD reissues have the year of release as "year", instead of the year of the original recording): I'd like to make these fixes right away, using the "edit" command, instead of waiting for the import procedure to finish, and then run `beet edit ...` with the proper query to only match the album just imported.

Currently an "Edit" command is available in import mode, but it can be used alternatively to the Search command (i.e. starting from a blank template), it would be very convenient if "Edit" would be available right after applying the results of a search, using those as starting values in the editor.


Discussion:
Hi! It sounds like you want to edit the candidate metadata, which is actually possible already. At this prompt:

```
Apply, More candidates, [S]kip, Use as-is, as Tracks, Group albums,
Enter search, enter Id, aBort, eDit, edit Candidates, plaY?
```

choose the "edit Candidates" option instead of the "eDit" option. Does that do what you want?

> choose the "edit Candidates" option

Hey, wait a moment, I've never seen that option!!! Ah, it must be because of (quoting the Edit plugin documentation):

    Also, please be aware that the edit Candidates choice can only be used with the matches found during 
    the initial search (and currently not supporting the candidates found via the Enter search or enter Id choices). 

I almost always import files that lack any tags, so I can't use that option :(
Any possibility to make it available also in my use-case?
Hmm, that's odd—I wonder why the documentation says that! In a little experiment I ran here, it did actually appear after entering an ID. I can't really think of a reason that would have been a limitation in the past, but maybe it's just out of date somehow?
> it did actually appear after entering an ID.

You are talking about a different use-case. Here is mine, in detail:

1. `beet import some-directory`
1. beets doesn't come up with any automated results (not enough info in my filenames), so i choose `Enter search` and do a manual search for artist/album
1. beets presents me with the search results, and offers the following options
`[A]pply, More candidates, Skip, Use as-is, as Tracks, Group albums,
Enter search, enter Id, aBort, eDit?`

My problem is: I would like to have the `edit Candidates` option too. Is this clear now?

beets version 1.4.3
python version 2.7.13




Ah, sorry, I did misunderstand. But I did another experiment here too, using the "Enter search" option… and the screen that appeared after that did include the "edit Candidates" option. I'm guessing you had a single high-confidence match. Have you tried choosing "More candidates"? I think the option should then appear after it shows you a listing.
> Have you tried choosing "More candidates"? I think the option should then appear after it shows you a listing.

No it doesn't.

I tried removing the if clause in `beetsplug/edit.py` line 358, to always append `edit Candidates` unconditionally: the option now appears but it doesn't work (I'm trapped in an infinite loop of `Enter one of 1-0`), so it seems more work is needed (hints?).

Once we fix this, the next step would be to remove the limitation of only being able to edit the item-level fields, and also allow editing the album-level fields.
Weird! I don't know why I can't seem to reproduce the same problem. Are you running the latest source? (Sorry it's been so long since the last release—totally my fault.)
> Are you running the latest source?

I was running 1.4.3, so I pip-uninstalled it, downloaded the latest zip source from github, installed it via setup.py and repeated the test, but I still can't get the edit candidates option.

I also tried moving away my config file, to use the default config values: same result.

The kind of files that I usually import are m4a, with no information in the file name (e.g. 01.m4a etc) and sometimes the artist and/or title tag (but often they have no tags).

Weird! I'm still pretty stumped. I don't know why we're not seeing the same behavior.

Any chance you could include some pastes from full interactions—one where you did get the prompt and one where you didn't? Including verbose output would be even better.
...
> Any chance you could include some pastes from full interactions—one where you did get the prompt and one where you didn't? Including verbose output would be even better.

Ok, I hope this can help. See the attached images.

Images 01.jpg and 02.jpg show what happens when I run `beets -vv import mydir`, where `mydir` contains one .mp3 file without any tags. As you see, I choose `Enter search`, I get 5 candidates and no `Edit candidates` option; then I choose candidate number 2, and still no `Edit candidates` option.
This is the situation I already described in my previous messages.

![01](https://user-images.githubusercontent.com/3929903/32300322-51861502-bf59-11e7-8698-d46c7701b59e.jpg)
![02](https://user-images.githubusercontent.com/3929903/32300344-5b42d292-bf59-11e7-98cf-46ed2f9ff5fb.jpg)

Image 03.jpg shows what happens when I repeat the same operation on a file that already has tags.
As you see, beets uses the tags information to automatically suggest some candidates, and gives the `Edit candidates` option.

![03](https://user-images.githubusercontent.com/3929903/32300350-612eaf14-bf59-11e7-8d57-fff8af804dc9.jpg)

All this with beets 1.4.5.

I'd really love to see this fixed, so please let me know how I can help.

Resolving patch:
diff --git a/beets/ui/commands.py b/beets/ui/commands.py
--- a/beets/ui/commands.py
+++ b/beets/ui/commands.py
@@ -691,7 +691,6 @@ def choose_match(self, task):
             return action
 
         # Loop until we have a choice.
-        candidates, rec = task.candidates, task.rec
         while True:
             # Ask for a choice from the user. The result of
             # `choose_candidate` may be an `importer.action`, an
@@ -699,8 +698,8 @@ def choose_match(self, task):
             # `PromptChoice`.
             choices = self._get_choices(task)
             choice = choose_candidate(
-                candidates, False, rec, task.cur_artist, task.cur_album,
-                itemcount=len(task.items), choices=choices
+                task.candidates, False, task.rec, task.cur_artist,
+                task.cur_album, itemcount=len(task.items), choices=choices
             )
 
             # Basic choices that require no more action here.
@@ -716,8 +715,8 @@ def choose_match(self, task):
                     return post_choice
                 elif isinstance(post_choice, autotag.Proposal):
                     # Use the new candidates and continue around the loop.
-                    candidates = post_choice.candidates
-                    rec = post_choice.recommendation
+                    task.candidates = post_choice.candidates
+                    task.rec = post_choice.recommendation
 
             # Otherwise, we have a specific match selection.
             else:


Test patch: