Skip to content
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
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions beetsplug/markunmatched.py
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()
Copy link
Contributor

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.

return action.SKIP
1 change: 1 addition & 0 deletions docs/plugins/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ following to your configuration::
limit
loadext
lyrics
markunmatched
mbcollection
mbsubmit
mbsync
Expand Down
38 changes: 38 additions & 0 deletions docs/plugins/markunmatched.rst
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.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ per-file-ignores =
./beetsplug/bpsync.py:D
./beetsplug/__init__.py:D
./beetsplug/edit.py:D
./beetsplug/markunmatched.py:D
./beetsplug/types.py:D
./beetsplug/embedart.py:D
./beetsplug/mpdupdate.py:D
Expand Down