mirror of
https://github.com/rembo10/headphones.git
synced 2026-05-02 09:49:36 +01:00
update Beets
This commit is contained in:
@@ -16,31 +16,34 @@
|
||||
"""
|
||||
|
||||
|
||||
from beets.plugins import BeetsPlugin
|
||||
from beets.dbcore.query import StringFieldQuery
|
||||
from beets import config
|
||||
import difflib
|
||||
|
||||
from beets import config
|
||||
from beets.dbcore.query import StringFieldQuery
|
||||
from beets.plugins import BeetsPlugin
|
||||
|
||||
class FuzzyQuery(StringFieldQuery):
|
||||
|
||||
class FuzzyQuery(StringFieldQuery[str]):
|
||||
@classmethod
|
||||
def string_match(cls, pattern, val):
|
||||
def string_match(cls, pattern: str, val: str):
|
||||
# smartcase
|
||||
if pattern.islower():
|
||||
val = val.lower()
|
||||
query_matcher = difflib.SequenceMatcher(None, pattern, val)
|
||||
threshold = config['fuzzy']['threshold'].as_number()
|
||||
threshold = config["fuzzy"]["threshold"].as_number()
|
||||
return query_matcher.quick_ratio() >= threshold
|
||||
|
||||
|
||||
class FuzzyPlugin(BeetsPlugin):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.config.add({
|
||||
'prefix': '~',
|
||||
'threshold': 0.7,
|
||||
})
|
||||
self.config.add(
|
||||
{
|
||||
"prefix": "~",
|
||||
"threshold": 0.7,
|
||||
}
|
||||
)
|
||||
|
||||
def queries(self):
|
||||
prefix = self.config['prefix'].as_str()
|
||||
prefix = self.config["prefix"].as_str()
|
||||
return {prefix: FuzzyQuery}
|
||||
|
||||
Reference in New Issue
Block a user