Add negation filters

This commit is contained in:
Joshua Boniface 2023-04-28 20:52:23 -04:00
parent 447eb4120a
commit 6ecb62431e
1 changed files with 21 additions and 3 deletions

View File

@ -354,7 +354,6 @@ def downloadSong(destination, filename, entry, dlid, dldesc):
if download_url is None: if download_url is None:
continue continue
print(entry)
download_filename = filename.format( download_filename = filename.format(
genre=entry["genre"], genre=entry["genre"],
artist=entry["artist"], artist=entry["artist"],
@ -625,7 +624,13 @@ def download(_filters, _id, _desc, _limit, _file_structure):
for information_filter in song_information_filters: for information_filter in song_information_filters:
filter_field = information_filter[0].lower() filter_field = information_filter[0].lower()
filter_value = information_filter[1].lower() filter_value = information_filter[1].lower()
if re.match("^~", filter_value): if re.match("^!", filter_value):
filter_value = filter_value.replace("!", "")
if filter_value in song[filter_field].lower():
pending_information_filters.append(False)
else:
pending_information_filters.append(True)
elif re.match("^~", filter_value):
filter_value = filter_value.replace("~", "") filter_value = filter_value.replace("~", "")
if filter_value in song[filter_field].lower(): if filter_value in song[filter_field].lower():
pending_information_filters.append(True) pending_information_filters.append(True)
@ -725,6 +730,13 @@ def search(_filters):
For example, to match all songs with "Word" in their titles: For example, to match all songs with "Word" in their titles:
--filter title ~word --filter title ~word
A filter can be negated by adding an exclamation mark ("!") to the beginning of the
"<value>". Note that "!" must be escaped or single-quoted under BASH.
\b
For example, to match all songs except those by Yes as their artist:
--filter artist '!Yes'
Instrument filters allow selection of the presence of instruments. If an instrument Instrument filters allow selection of the presence of instruments. If an instrument
fitler is given, only songs which contain parts for the given instrument(s) will be fitler is given, only songs which contain parts for the given instrument(s) will be
shown. shown.
@ -781,7 +793,13 @@ def search(_filters):
for information_filter in song_information_filters: for information_filter in song_information_filters:
filter_field = information_filter[0].lower() filter_field = information_filter[0].lower()
filter_value = information_filter[1].lower() filter_value = information_filter[1].lower()
if re.match("^~", filter_value): if re.match("^!", filter_value):
filter_value = filter_value.replace("!", "")
if filter_value in song[filter_field].lower():
pending_information_filters.append(False)
else:
pending_information_filters.append(True)
elif re.match("^~", filter_value):
filter_value = filter_value.replace("~", "") filter_value = filter_value.replace("~", "")
if filter_value in song[filter_field].lower(): if filter_value in song[filter_field].lower():
pending_information_filters.append(True) pending_information_filters.append(True)