From 19d22d1428909b04a7bcfaeaa8fa7314f75292d3 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Sat, 18 Sep 2021 00:11:37 -0400 Subject: [PATCH] Implement inverse filtering for albums --- spotify_actions/album.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/spotify_actions/album.py b/spotify_actions/album.py index aebde6c..d0c7e4a 100644 --- a/spotify_actions/album.py +++ b/spotify_actions/album.py @@ -11,10 +11,17 @@ from spotipy import Spotify from .util import chunk, exhaust, parse_release_date -def album_filter_label(albums: Iterable[SimplifiedAlbum], label: str) -> Iterable[SearchAlbum]: - "Filter albums that match an exact label string" +def album_filter_label( + albums: Iterable[SimplifiedAlbum], label: str, include: bool = True +) -> Iterable[SimplifiedAlbum]: + """ + Filter albums based on the label. + + If `include`, yield labels that match the provided string (typical filter behavior). + Otherwise, yield only those albums that don't match the label. + """ for album in albums: - if album.label == label: + if (album.label == label) == include: yield album