Skip to content

Commit

Permalink
mbsubmit: Add picard and markunmatched PromptChoices
Browse files Browse the repository at this point in the history
Make it possible to open picard from the import menu when there are weak
recommendations. Add another menu option to print the tracks into a
beets-unmatched file for later parsing.
  • Loading branch information
doronbehar committed Oct 27, 2023
1 parent 6655760 commit 64ee313
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
29 changes: 28 additions & 1 deletion beetsplug/mbsubmit.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
[1] https://wiki.musicbrainz.org/History:How_To_Parse_Track_Listings
"""

import subprocess
from pathlib import Path

from beets import ui
from beets.autotag import Recommendation
Expand Down Expand Up @@ -56,7 +58,32 @@ def __init__(self):

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(
"f",
'print tracks into a "beets-unmatched" File',
self.markunmatched,
),
PromptChoice(
"o", "Open Picard with the relevent files", self.picard
),
]

def markunmatched(self, session, task):
fmt = self.config["format"].as_str()
for item in task.items:
unmatched_path = (
Path(item.path.decode("utf-8")).parent / "beets-unmatched"
)
with open(unmatched_path, "a") as p:
p.write(format(item, fmt) + "\n")

def picard(self, session, task):
paths = []
for p in task.paths:
paths.append(p.decode("utf-8"))
subprocess.Popen(["picard"] + paths)

def print_tracks(self, session, task):
for i in sorted(task.items, key=lambda i: i.track):
Expand Down
2 changes: 1 addition & 1 deletion test/plugins/test_mbsubmit.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_print_tracks_output_as_tracks(self):
self.importer.run()

# Manually build the string for comparing the output.
tracklist = "Print tracks? " "02. Tag Title 2 - Tag Artist (0:01)"
tracklist = "Print tracks," "02. Tag Title 2 - Tag Artist (0:01)"
self.assertIn(tracklist, output.getvalue())


Expand Down

0 comments on commit 64ee313

Please sign in to comment.