Commits

phmongeau  committed b57e1cc

fuzzy: add prefix config

  • Participants
  • Parent commits 224a98f

Comments (0)

Files changed (1)

File beetsplug/fuzzy.py

 from beets.plugins import BeetsPlugin
 from beets.library import PluginQuery
 from beets.ui import Subcommand, decargs, print_obj
-from beets import config
 from beets import util
+import beets
 import difflib
 
 
         super(FuzzyQuery, self).__init__(field, pattern)
         # self.field = field
         self.name = 'PLUGIN'
-        self.prefix = "~"
+        self.prefix = beets.config['fuzzy']['prefix'].get() or '~'
+        self.threshold =  beets.config['fuzzy']['threshold'].as_number() or 0.7
 
     def match(self, pattern, val):
         if pattern is None:
             return False
         val = util.as_string(val)
         queryMatcher = difflib.SequenceMatcher(None, pattern, val)
-        return queryMatcher.quick_ratio() > config['fuzzy']['threshold'].as_number()
+        return queryMatcher.quick_ratio() > self.threshold
 
 
 class FuzzyPlugin(BeetsPlugin):
         super(FuzzyPlugin, self).__init__(self)
         self.config.add({
             'threshold': 0.7,
+            'prefix': '~',
         })
 
     def queries(self):