diff --git a/helpers/misc.py b/helpers/misc.py index 6e0202e..0c6572b 100644 --- a/helpers/misc.py +++ b/helpers/misc.py @@ -44,3 +44,22 @@ def dict_merge(dct, merge_dct): dct[k] = merge_dct[k] return dct + + +def unblacklist_genres(genre, blacklisted_genres): + genres = genre.split(',') + for allow_genre in genres: + if allow_genre in blacklisted_genres: + blacklisted_genres.remove(allow_genre) + return + + +def allowed_genres(genre, object_type, trakt_object): + allowed_object = False + genres = genre.split(',') + + for item in genres: + if item.lower() in trakt_object[object_type]['genres']: + allowed_object = True + break + return allowed_object diff --git a/traktarr.py b/traktarr.py index cd06078..78524c6 100755 --- a/traktarr.py +++ b/traktarr.py @@ -184,14 +184,15 @@ def shows(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_sea authenticate_user=None): from media.sonarr import Sonarr from media.trakt import Trakt + from helpers import misc as misc_helper from helpers import sonarr as sonarr_helper from helpers import trakt as trakt_helper added_shows = 0 # remove genre from shows blacklisted_genres if supplied - if genre and genre in cfg.filters.shows.blacklisted_genres: - cfg['filters']['shows']['blacklisted_genres'].remove(genre) + if genre: + misc_helper.unblacklist_genres(genre, cfg['filters']['shows']['blacklisted_genres']) # replace sonarr root_folder if folder is supplied if folder: @@ -253,8 +254,8 @@ def shows(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_sea for series in sorted_series_list: try: # check if genre matches genre supplied via argument - if genre and genre.lower() not in series['show']['genres']: - log.debug("Skipping: %s because it was not from %s genre", series['show']['title'], genre.lower()) + if genre and not misc_helper.allowed_genres(genre, 'show', series): + log.debug("Skipping: %s because it was not from %s genre(s)", series['show']['title'], genre.lower()) continue # check if series passes out blacklist criteria inspection @@ -360,14 +361,15 @@ def movies(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_se authenticate_user=None): from media.radarr import Radarr from media.trakt import Trakt + from helpers import misc as misc_helper from helpers import radarr as radarr_helper from helpers import trakt as trakt_helper added_movies = 0 # remove genre from movies blacklisted_genres if supplied - if genre and genre in cfg.filters.movies.blacklisted_genres: - cfg['filters']['movies']['blacklisted_genres'].remove(genre) + if genre: + misc_helper.unblacklist_genres(genre, cfg['filters']['movies']['blacklisted_genres']) # replace radarr root_folder if folder is supplied if folder: @@ -430,8 +432,8 @@ def movies(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_se for movie in sorted_movies_list: try: # check if genre matches genre supplied via argument - if genre and genre.lower() not in movie['movie']['genres']: - log.debug("Skipping: %s because it was not from %s genre", movie['movie']['title'], genre.lower()) + if genre and not misc_helper.allowed_genres(genre, 'movie', movie): + log.debug("Skipping: %s because it was not from %s genre(s)", movie['movie']['title'], genre.lower()) continue # check if movie passes out blacklist criteria inspection