Started trying to figure out how to listen to the system bus for network changes

This commit is contained in:
Sumner Evans
2019-12-29 14:41:53 -07:00
parent 78c3fc5cf4
commit 2b31f508c9
6 changed files with 68 additions and 62 deletions

View File

@@ -6,6 +6,7 @@ import shutil
import json
import hashlib
from functools import lru_cache
from collections import defaultdict
from time import sleep
@@ -75,6 +76,12 @@ class SongCacheStatus(Enum):
DOWNLOADING = 3
# This may end up being called a lot, so cache the similarity ratios.
@lru_cache(maxsize=8192)
def similarity_ratio(query, string):
return fuzz.partial_ratio(query.lower(), string.lower())
class SearchResult:
_artist: Set[Union[Artist, ArtistID3]] = set()
_album: Set[Union[Child, AlbumID3]] = set()
@@ -100,14 +107,7 @@ class SearchResult:
def _to_result(self, it, transform):
all_results = sorted(
(
(
fuzz.partial_ratio(
self.query.lower(),
transform(x).lower(),
),
x,
) for x in it),
((similarity_ratio(self.query, transform(x)), x) for x in it),
key=lambda rx: rx[0],
reverse=True,
)