update Beets

This commit is contained in:
AdeHub
2024-08-24 16:44:41 +12:00
parent a63098a919
commit 046d4d82b4
116 changed files with 17353 additions and 9964 deletions

View File

@@ -19,15 +19,17 @@
"""Provides a bare-ASCII matching query."""
from beets import ui
from beets.ui import print_, decargs
from beets.plugins import BeetsPlugin
from beets.dbcore.query import StringFieldQuery
from unidecode import unidecode
from beets import ui
from beets.dbcore.query import StringFieldQuery
from beets.plugins import BeetsPlugin
from beets.ui import decargs, print_
class BareascQuery(StringFieldQuery):
class BareascQuery(StringFieldQuery[str]):
"""Compare items using bare ASCII, without accents etc."""
@classmethod
def string_match(cls, pattern, val):
"""Convert both pattern and string to plain ASCII before matching.
@@ -42,27 +44,40 @@ class BareascQuery(StringFieldQuery):
val = unidecode(val)
return pattern in val
def col_clause(self):
"""Compare ascii version of the pattern."""
clause = f"unidecode({self.field})"
if self.pattern.islower():
clause = f"lower({clause})"
return rf"{clause} LIKE ? ESCAPE '\'", [f"%{unidecode(self.pattern)}%"]
class BareascPlugin(BeetsPlugin):
"""Plugin to provide bare-ASCII option for beets matching."""
def __init__(self):
"""Default prefix for selecting bare-ASCII matching is #."""
super().__init__()
self.config.add({
'prefix': '#',
})
self.config.add(
{
"prefix": "#",
}
)
def queries(self):
"""Register bare-ASCII matching."""
prefix = self.config['prefix'].as_str()
prefix = self.config["prefix"].as_str()
return {prefix: BareascQuery}
def commands(self):
"""Add bareasc command as unidecode version of 'list'."""
cmd = ui.Subcommand('bareasc',
help='unidecode version of beet list command')
cmd.parser.usage += "\n" \
'Example: %prog -f \'$album: $title\' artist:beatles'
cmd = ui.Subcommand(
"bareasc", help="unidecode version of beet list command"
)
cmd.parser.usage += (
"\n" "Example: %prog -f '$album: $title' artist:beatles"
)
cmd.parser.add_all_common_options()
cmd.func = self.unidecode_list
return [cmd]