implement simple AND-operator for library search
This commit is contained in:
parent
b3f4a596f8
commit
8f1434c28f
1 changed files with 24 additions and 6 deletions
30
mcg.py
30
mcg.py
|
|
@ -615,6 +615,7 @@ class MCGAlbum:
|
||||||
SORT_BY_YEAR = 'year'
|
SORT_BY_YEAR = 'year'
|
||||||
_FILE_NAMES = ['cover', 'folder']
|
_FILE_NAMES = ['cover', 'folder']
|
||||||
_FILE_EXTS = ['jpg', 'png', 'jpeg']
|
_FILE_EXTS = ['jpg', 'png', 'jpeg']
|
||||||
|
_FILTER_DELIMITER = ' '
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, title, host, image_dir):
|
def __init__(self, title, host, image_dir):
|
||||||
|
|
@ -697,12 +698,29 @@ class MCGAlbum:
|
||||||
|
|
||||||
|
|
||||||
def filter(self, filter_string):
|
def filter(self, filter_string):
|
||||||
values = self._artists + [self._title]
|
if len(filter_string) == 0:
|
||||||
values.extend(map(lambda track: track.get_title(), self._tracks))
|
return True
|
||||||
for value in values:
|
keywords = filter_string.split(MCGAlbum._FILTER_DELIMITER)
|
||||||
if filter_string.lower() in value.lower():
|
for keyword in keywords:
|
||||||
return True
|
if len(keyword) == 0:
|
||||||
return False
|
continue
|
||||||
|
result = False
|
||||||
|
keyword = keyword.lower()
|
||||||
|
# Search in album data
|
||||||
|
for value in self._artists + [self._title] + self._dates:
|
||||||
|
if keyword in value.lower():
|
||||||
|
result = True
|
||||||
|
break
|
||||||
|
if result:
|
||||||
|
continue
|
||||||
|
# Search in track data
|
||||||
|
for track in self._tracks:
|
||||||
|
if keyword in track.get_title().lower() or keyword in track.get_file().lower():
|
||||||
|
result = True
|
||||||
|
break
|
||||||
|
if not result:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def compare(album1, album2, criterion=None):
|
def compare(album1, album2, criterion=None):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue