mirror of
https://github.com/beetbox/beets.git
synced 2026-01-30 03:54:21 +01:00
mbsubmit: Add picard PromptChoice
Make it possible to open picard from the import menu when there are weak recommendations.
This commit is contained in:
parent
293c3c19a1
commit
729a11e211
2 changed files with 22 additions and 3 deletions
|
|
@ -21,11 +21,13 @@ implemented by MusicBrainz yet.
|
|||
[1] https://wiki.musicbrainz.org/History:How_To_Parse_Track_Listings
|
||||
"""
|
||||
|
||||
import subprocess
|
||||
|
||||
from beets import ui
|
||||
from beets.autotag import Recommendation
|
||||
from beets.plugins import BeetsPlugin
|
||||
from beets.ui.commands import PromptChoice
|
||||
from beets.util import displayable_path
|
||||
from beetsplug.info import print_data
|
||||
|
||||
|
||||
|
|
@ -37,6 +39,7 @@ class MBSubmitPlugin(BeetsPlugin):
|
|||
{
|
||||
"format": "$track. $title - $artist ($length)",
|
||||
"threshold": "medium",
|
||||
"picard_path": "picard",
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -56,7 +59,21 @@ class MBSubmitPlugin(BeetsPlugin):
|
|||
|
||||
def before_choose_candidate_event(self, session, task):
|
||||
if task.rec <= self.threshold:
|
||||
return [PromptChoice("p", "Print tracks", self.print_tracks)]
|
||||
return [
|
||||
PromptChoice("p", "Print tracks", self.print_tracks),
|
||||
PromptChoice("o", "Open files with Picard", self.picard),
|
||||
]
|
||||
|
||||
def picard(self, session, task):
|
||||
paths = []
|
||||
for p in task.paths:
|
||||
paths.append(displayable_path(p))
|
||||
try:
|
||||
picard_path = self.config["picard_path"].as_str()
|
||||
subprocess.Popen([picard_path] + paths)
|
||||
self._log.info("launched picard from\n{}", picard_path)
|
||||
except OSError as exc:
|
||||
self._log.error(f"Could not open picard, got error:\n{exc}")
|
||||
|
||||
def print_tracks(self, session, task):
|
||||
for i in sorted(task.items, key=lambda i: i.track):
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class MBSubmitPluginTest(
|
|||
|
||||
# Manually build the string for comparing the output.
|
||||
tracklist = (
|
||||
"Print tracks? "
|
||||
"Open files with Picard? "
|
||||
"01. Tag Title 1 - Tag Artist (0:01)\n"
|
||||
"02. Tag Title 2 - Tag Artist (0:01)"
|
||||
)
|
||||
|
|
@ -61,7 +61,9 @@ class MBSubmitPluginTest(
|
|||
self.importer.run()
|
||||
|
||||
# Manually build the string for comparing the output.
|
||||
tracklist = "Print tracks? " "02. Tag Title 2 - Tag Artist (0:01)"
|
||||
tracklist = (
|
||||
"Open files with Picard? " "02. Tag Title 2 - Tag Artist (0:01)"
|
||||
)
|
||||
self.assertIn(tracklist, output.getvalue())
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue