From 6ecb62431ed3139ed5466a396dd0aad40e81ecee Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Fri, 28 Apr 2023 20:52:23 -0400 Subject: [PATCH] Add negation filters --- c3dbdl/c3dbdl.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/c3dbdl/c3dbdl.py b/c3dbdl/c3dbdl.py index af5e731..18e3821 100755 --- a/c3dbdl/c3dbdl.py +++ b/c3dbdl/c3dbdl.py @@ -354,7 +354,6 @@ def downloadSong(destination, filename, entry, dlid, dldesc): if download_url is None: continue - print(entry) download_filename = filename.format( genre=entry["genre"], artist=entry["artist"], @@ -625,7 +624,13 @@ def download(_filters, _id, _desc, _limit, _file_structure): for information_filter in song_information_filters: filter_field = information_filter[0].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("~", "") if filter_value in song[filter_field].lower(): pending_information_filters.append(True) @@ -725,6 +730,13 @@ def search(_filters): For example, to match all songs with "Word" in their titles: --filter title ~word + A filter can be negated by adding an exclamation mark ("!") to the beginning of the + "". 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 fitler is given, only songs which contain parts for the given instrument(s) will be shown. @@ -781,7 +793,13 @@ def search(_filters): for information_filter in song_information_filters: filter_field = information_filter[0].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("~", "") if filter_value in song[filter_field].lower(): pending_information_filters.append(True)