-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plugins: add markunmatched #4749
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from pathlib import Path | ||
import subprocess | ||
import shlex | ||
|
||
from beets.autotag.match import Recommendation | ||
from confuse import NotFoundError as ConfigParmNotFound | ||
from beets.plugins import BeetsPlugin | ||
from beets.ui.commands import PromptChoice | ||
from beets.importer import action | ||
|
||
|
||
class MarkUnmatched(BeetsPlugin): | ||
def __init__(self): | ||
super(MarkUnmatched, self).__init__() | ||
self.register_listener('before_choose_candidate', | ||
self.before_choose_candidate_event) | ||
|
||
def before_choose_candidate_event(self, session, task): | ||
if task.rec == Recommendation.strong: | ||
self._log.info("recommendation is strong, not notifying") | ||
return | ||
notify_command = "" | ||
try: | ||
notify_command = shlex.split(str(self.config['notify-command'])) | ||
except ConfigParmNotFound: | ||
self._log.info("no notify-command was configured") | ||
if notify_command: | ||
self._log.info("notifying no-match via command configured: %s", | ||
self.config['notify-command']) | ||
print_cmd = [ | ||
"printf", "%s", | ||
"failed to find match for paths:\n", | ||
"\n".join([path.decode('utf-8') for path in task.paths]) | ||
] | ||
p_msg = subprocess.Popen(print_cmd, stdout=subprocess.PIPE) | ||
p_out = subprocess.Popen(notify_command, stdin=p_msg.stdout, stdout=subprocess.PIPE) | ||
(stdout, stderr) = p_out.communicate() | ||
if stderr: | ||
print("'notify-command' printed errors:") | ||
print(stderr.decode('utf-8'), end='') | ||
if stdout: | ||
print("'notify-command' printed:") | ||
print(stdout.decode('utf-8'), end='') | ||
return [PromptChoice( | ||
'f', | ||
'create a \'beets-unmatched\' File and skip', | ||
self.touch_unmatched | ||
)] | ||
|
||
def touch_unmatched(self, session, task): | ||
for path in task.paths: | ||
Path(path.decode('utf-8') + "/beets-unmatched").touch() | ||
return action.SKIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,7 @@ following to your configuration:: | |
limit | ||
loadext | ||
lyrics | ||
markunmatched | ||
mbcollection | ||
mbsubmit | ||
mbsync | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
MarkUnmatched Plugin | ||
================== | ||
|
||
The ``markunmatched`` plugin is a simple plugin that adds a prompt choice when | ||
beets fails to find accurate enough matches when importing a directory (see | ||
:doc:`usage`). It also includes an option to notify you via a custom command | ||
when an import has encountered a too weak recommendation. | ||
|
||
To use the ``markunmatched`` plugin, enable it in your configuration (see | ||
:ref:`using-plugins`). | ||
|
||
Usage | ||
----- | ||
|
||
When importing many directories in a bulk, you may want to skip a directory but | ||
mark yourself to take care of it later - for example add that album to | ||
musicbrainz later, and not now during the bulk import. | ||
|
||
The prompt looks like this:: | ||
|
||
Apply, More candidates, Skip, Use as-is, as Tracks, Group albums, | ||
Enter search, enter Id, aBort, create a 'beets-unmatched' File and skip, | ||
Print tracks, eDit, edit Candidates? | ||
|
||
The `beets-unmatched` file can be used to later to reiterate the unmatched | ||
albums. | ||
|
||
Configuration: | ||
-------------- | ||
|
||
By default, no notification is made when a match is not found in an import | ||
procedure. To configure such notification, use (e.g):: | ||
|
||
markunmatched: | ||
notify-command: "gotify push --title 'Beets Music importer' --priority 4" | ||
|
||
Beets pipes to stdin of the above command the message mentioning the unmatched | ||
paths. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine you wanted this file to be easily visible from the terminal/file browser, but my first thought was that it should probably be hidden (i.e.
.beets-unmatched
).Could be useful to make the filename configurable too.