mirror of
https://github.com/beetbox/beets.git
synced 2026-01-01 21:42:48 +01:00
Merge remote-tracking branch 'upstream/master' into embedart_url
This commit is contained in:
commit
023f3d7df7
4 changed files with 25 additions and 0 deletions
|
|
@ -23,6 +23,8 @@ import threading
|
|||
import sqlite3
|
||||
import contextlib
|
||||
|
||||
from unidecode import unidecode
|
||||
|
||||
import beets
|
||||
from beets.util import functemplate
|
||||
from beets.util import py3_path
|
||||
|
|
@ -975,6 +977,7 @@ class Database:
|
|||
conn = sqlite3.connect(
|
||||
py3_path(self.path), timeout=self.timeout
|
||||
)
|
||||
self.add_functions(conn)
|
||||
|
||||
if self.supports_extensions:
|
||||
conn.enable_load_extension(True)
|
||||
|
|
@ -987,6 +990,15 @@ class Database:
|
|||
conn.row_factory = sqlite3.Row
|
||||
return conn
|
||||
|
||||
def add_functions(self, conn):
|
||||
def regexp(value, pattern):
|
||||
if isinstance(value, bytes):
|
||||
value = value.decode()
|
||||
return re.search(pattern, str(value)) is not None
|
||||
|
||||
conn.create_function("regexp", 2, regexp)
|
||||
conn.create_function("unidecode", 1, unidecode)
|
||||
|
||||
def _close(self):
|
||||
"""Close the all connections to the underlying SQLite database
|
||||
from all threads. This does not render the database object
|
||||
|
|
|
|||
|
|
@ -231,6 +231,9 @@ class RegexpQuery(StringFieldQuery):
|
|||
"a regular expression",
|
||||
format(exc))
|
||||
|
||||
def col_clause(self):
|
||||
return f" regexp({self.field}, ?)", [self.pattern.pattern]
|
||||
|
||||
@staticmethod
|
||||
def _normalize(s):
|
||||
"""Normalize a Unicode string's representation (used on both
|
||||
|
|
|
|||
|
|
@ -42,6 +42,14 @@ 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."""
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ New features:
|
|||
* :ref:`list-cmd` `singleton:1` and `singleton:0` can now alternatively be used in queries, same as `comp`
|
||||
* --from-logfile now parses log files using a UTF-8 encoding in `beets/beets/ui/commands.py`.
|
||||
:bug:`4693`
|
||||
* :doc:`/plugins/bareasc` lookups have been made faster
|
||||
* :ref:`list-cmd` lookups using the pattern operator `::` have been made faster
|
||||
* Added additional error handling for `spotify` plugin.
|
||||
:bug:`4686`
|
||||
* We now import the remixer field from Musicbrainz into the library.
|
||||
|
|
|
|||
Loading…
Reference in a new issue