From df7365e270fa1625494e032411abdedc84d5b978 Mon Sep 17 00:00:00 2001 From: Mitchell Klijs Date: Wed, 30 May 2018 18:04:21 +0200 Subject: [PATCH 1/2] Add option to ignore blacklist --- README.md | 3 +++ helpers/trakt.py | 10 ++++++++-- traktarr.py | 39 ++++++++++++++++++++++++--------------- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 1c58e2e..b652b01 100644 --- a/README.md +++ b/README.md @@ -726,6 +726,7 @@ You can customize how the scheduled traktarr is ran by editing the `traktarr.ser --no-search Disable search when adding to Sonarr / Radarr. --run-now Do a first run immediately without waiting. --no-notifications Disable notifications. + --ignore-blacklist Ignores the blacklist when running the command. --help Show this message and exit. ``` @@ -809,6 +810,7 @@ Options: -f, --folder TEXT Add movies with this root folder to Radarr. --no-search Disable search when adding movies to Radarr. --notifications Send notifications. + --ignore-blacklist Ignores the blacklist when running the command. --authenticate-user TEXT Specify which user to authenticate with to retrieve Trakt lists. Default: first user in the config. @@ -861,6 +863,7 @@ Options: -f, --folder TEXT Add shows with this root folder to Sonarr. --no-search Disable search when adding shows to Sonarr. --notifications Send notifications. + --ignore-blacklist Ignores the blacklist when running the command. --authenticate-user TEXT Specify which user to authenticate with to retrieve Trakt lists. Default: first user in the config diff --git a/helpers/trakt.py b/helpers/trakt.py index 6e65ccb..484d28a 100644 --- a/helpers/trakt.py +++ b/helpers/trakt.py @@ -106,7 +106,10 @@ def blacklisted_show_id(show, blacklisted_ids): return blacklisted -def is_show_blacklisted(show, blacklist_settings): +def is_show_blacklisted(show, blacklist_settings, ignore_blacklist): + if ignore_blacklist: + return False + blacklisted = False try: if blacklisted_show_year(show, blacklist_settings.blacklisted_min_year, @@ -228,7 +231,10 @@ def blacklisted_movie_id(movie, blacklisted_ids): return blacklisted -def is_movie_blacklisted(movie, blacklist_settings): +def is_movie_blacklisted(movie, blacklist_settings, ignore_blacklist): + if ignore_blacklist: + return False + blacklisted = False try: if blacklisted_movie_title(movie, blacklist_settings.blacklist_title_keywords): diff --git a/traktarr.py b/traktarr.py index 4718e74..6a5a34c 100755 --- a/traktarr.py +++ b/traktarr.py @@ -181,8 +181,9 @@ def show(show_id, folder=None, no_search=False): @click.option('--notifications', is_flag=True, help='Send notifications.') @click.option('--authenticate-user', help='Specify which user to authenticate with to retrieve Trakt lists. Default: first user in the config') +@click.option('--ignore-blacklist', is_flag=True, help='Ignores the blacklist when running the command.') def shows(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_search=False, notifications=False, - authenticate_user=None): + authenticate_user=None, ignore_blacklist=False): from media.sonarr import Sonarr from media.trakt import Trakt from helpers import misc as misc_helper @@ -260,7 +261,7 @@ def shows(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_sea continue # check if series passes out blacklist criteria inspection - if not trakt_helper.is_show_blacklisted(series, cfg.filters.shows): + if not trakt_helper.is_show_blacklisted(series, cfg.filters.shows, ignore_blacklist): log.info("Adding: %s | Genres: %s | Network: %s | Country: %s", series['show']['title'], ', '.join(series['show']['genres']), series['show']['network'], series['show']['country'].upper()) @@ -358,8 +359,9 @@ def movie(movie_id, folder=None, no_search=False): @click.option('--notifications', is_flag=True, help='Send notifications.') @click.option('--authenticate-user', help='Specify which user to authenticate with to retrieve Trakt lists. Default: first user in the config.') +@click.option('--ignore-blacklist', is_flag=True, help='Ignores the blacklist when running the command.') def movies(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_search=False, notifications=False, - authenticate_user=None): + authenticate_user=None, ignore_blacklist=False): from media.radarr import Radarr from media.trakt import Trakt from helpers import misc as misc_helper @@ -438,7 +440,7 @@ def movies(list_type, add_limit=0, add_delay=2.5, genre=None, folder=None, no_se continue # check if movie passes out blacklist criteria inspection - if not trakt_helper.is_movie_blacklisted(movie, cfg.filters.movies): + if not trakt_helper.is_movie_blacklisted(movie, cfg.filters.movies, ignore_blacklist): log.info("Adding: %s (%d) | Genres: %s | Country: %s", movie['movie']['title'], movie['movie']['year'], ', '.join(movie['movie']['genres']), movie['movie']['country'].upper()) # add movie to radarr @@ -499,7 +501,7 @@ def callback_notify(data): return -def automatic_shows(add_delay=2.5, no_search=False, notifications=False): +def automatic_shows(add_delay=2.5, no_search=False, notifications=False, ignore_blacklist=False): from media.trakt import Trakt total_shows_added = 0 @@ -524,7 +526,7 @@ def automatic_shows(add_delay=2.5, no_search=False, notifications=False): # run shows added_shows = shows.callback(list_type=list_type, add_limit=limit, add_delay=add_delay, no_search=no_search, - notifications=notifications) + notifications=notifications, ignore_blacklist=ignore_blacklist) elif list_type.lower() == 'watchlist': for authenticate_user, limit in value.items(): if limit <= 0: @@ -536,7 +538,8 @@ def automatic_shows(add_delay=2.5, no_search=False, notifications=False): # run shows added_shows = shows.callback(list_type=list_type, add_limit=limit, add_delay=add_delay, no_search=no_search, - notifications=notifications, authenticate_user=authenticate_user) + notifications=notifications, authenticate_user=authenticate_user, + ignore_blacklist=ignore_blacklist) elif list_type.lower() == 'lists': for list, v in value.items(): if isinstance(v, dict): @@ -549,7 +552,8 @@ def automatic_shows(add_delay=2.5, no_search=False, notifications=False): # run shows added_shows = shows.callback(list_type=list, add_limit=limit, add_delay=add_delay, no_search=no_search, - notifications=notifications, authenticate_user=authenticate_user) + notifications=notifications, authenticate_user=authenticate_user, + ignore_blacklist=ignore_blacklist) if added_shows is None: log.error("Failed adding shows from Trakt's %s list", list_type) @@ -570,7 +574,7 @@ def automatic_shows(add_delay=2.5, no_search=False, notifications=False): return -def automatic_movies(add_delay=2.5, no_search=False, notifications=False): +def automatic_movies(add_delay=2.5, no_search=False, notifications=False, ignore_blacklist=False): from media.trakt import Trakt total_movies_added = 0 @@ -595,7 +599,7 @@ def automatic_movies(add_delay=2.5, no_search=False, notifications=False): # run movies added_movies = movies.callback(list_type=list_type, add_limit=limit, add_delay=add_delay, no_search=no_search, - notifications=notifications) + notifications=notifications, ignore_blacklist=ignore_blacklist) elif list_type.lower() == 'watchlist': for authenticate_user, limit in value.items(): if limit <= 0: @@ -607,7 +611,8 @@ def automatic_movies(add_delay=2.5, no_search=False, notifications=False): # run movies added_movies = movies.callback(list_type=list_type, add_limit=limit, add_delay=add_delay, no_search=no_search, - notifications=notifications, authenticate_user=authenticate_user) + notifications=notifications, authenticate_user=authenticate_user, + ignore_blacklist=ignore_blacklist) elif list_type.lower() == 'lists': for list, v in value.items(): if isinstance(v, dict): @@ -620,7 +625,8 @@ def automatic_movies(add_delay=2.5, no_search=False, notifications=False): # run shows added_movies = movies.callback(list_type=list, add_limit=limit, add_delay=add_delay, no_search=no_search, - notifications=notifications, authenticate_user=authenticate_user) + notifications=notifications, authenticate_user=authenticate_user, + ignore_blacklist=ignore_blacklist) if added_movies is None: log.error("Failed adding movies from Trakt's %s list", list_type) @@ -647,7 +653,8 @@ def automatic_movies(add_delay=2.5, no_search=False, notifications=False): @click.option('--no-search', is_flag=True, help='Disable search when adding to Sonarr / Radarr.') @click.option('--run-now', is_flag=True, help="Do a first run immediately without waiting.") @click.option('--no-notifications', is_flag=True, help="Disable notifications.") -def run(add_delay=2.5, no_search=False, run_now=False, no_notifications=False): +@click.option('--ignore-blacklist', is_flag=True, help='Ignores the blacklist when running the command.') +def run(add_delay=2.5, no_search=False, run_now=False, no_notifications=False, ignore_blacklist=False): log.info("Automatic mode is now running...") # Add tasks to schedule and do first run if enabled @@ -656,7 +663,8 @@ def run(add_delay=2.5, no_search=False, run_now=False, no_notifications=False): automatic_movies, add_delay, no_search, - not no_notifications + not no_notifications, + ignore_blacklist ) if run_now: movie_schedule.run() @@ -669,7 +677,8 @@ def run(add_delay=2.5, no_search=False, run_now=False, no_notifications=False): automatic_shows, add_delay, no_search, - not no_notifications + not no_notifications, + ignore_blacklist ) if run_now: shows_schedule.run() From 1d84aa46ca3f1c6ed39bc87d2834062b01a1ab00 Mon Sep 17 00:00:00 2001 From: Mitchell Klijs Date: Wed, 30 May 2018 18:33:39 +0200 Subject: [PATCH 2/2] Add ability to specify blacklist ignore in config --- README.md | 27 +++++++++++++++++++++++++++ misc/config.py | 2 ++ traktarr.py | 42 ++++++++++++++++++++++++++++++++++++------ 3 files changed, 65 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b652b01..10e7385 100644 --- a/README.md +++ b/README.md @@ -193,6 +193,7 @@ You can repeat this process for as many users as you like. }, "filters": { "movies": { + "disabled_for": [], "allowed_countries": [ "us", "gb", @@ -215,6 +216,7 @@ You can repeat this process for as many users as you like. "blacklisted_tmdb_ids": [] }, "shows": { + "disabled_for": [], "allowed_countries": [ "us", "gb", @@ -444,6 +446,7 @@ Use filters to specify the movie/shows's country of origin or blacklist (i.e. fi ```json "movies": { + "disabled_for": [], "allowed_countries": [ "us", "gb", @@ -466,6 +469,18 @@ Use filters to specify the movie/shows's country of origin or blacklist (i.e. fi }, ``` +`disabled_for` - specify for which lists the blacklist must be disabled when running in automatic mode + +Example: + +``` + "disabled_for": [ + "anticipated", + "watchlist:user1", + "list:http://url-to-list" + ], +``` + `allowed_countries` - only add movies from these countries. `allowed_languages` - only add movies with these languages (default/blank=English). @@ -530,6 +545,18 @@ Use filters to specify the movie/shows's country of origin or blacklist (i.e. fi } ``` +`disabled_for` - specify for which lists the blacklist must be disabled when running in automatic mode + +Example: + +``` + "disabled_for": [ + "anticipated", + "watchlist:user1", + "list:http://url-to-list" + ], +``` + `allowed_countries` - only add shows from these countries. `allowed_languages` - only add shows with these languages (default/blank=English). diff --git a/misc/config.py b/misc/config.py index f123139..e3fbfba 100644 --- a/misc/config.py +++ b/misc/config.py @@ -57,6 +57,7 @@ class Config(object, metaclass=Singleton): }, 'filters': { 'shows': { + 'disabled_for': [], 'blacklisted_genres': [], 'blacklisted_networks': [], 'allowed_countries': [], @@ -67,6 +68,7 @@ class Config(object, metaclass=Singleton): 'blacklisted_tvdb_ids': [], }, 'movies': { + 'disabled_for': [], 'blacklisted_genres': [], 'blacklisted_min_runtime': 60, 'blacklisted_min_year': 2000, diff --git a/traktarr.py b/traktarr.py index 6a5a34c..3ab9baf 100755 --- a/traktarr.py +++ b/traktarr.py @@ -523,10 +523,15 @@ def automatic_shows(add_delay=2.5, no_search=False, notifications=False, ignore_ else: log.info("Adding %d shows from Trakt's %s list", limit, list_type) + local_ignore_blacklist = ignore_blacklist + + if list_type.lower() in cfg.filters.shows.disabled_for: + local_ignore_blacklist = True + # run shows added_shows = shows.callback(list_type=list_type, add_limit=limit, add_delay=add_delay, no_search=no_search, - notifications=notifications, ignore_blacklist=ignore_blacklist) + notifications=notifications, ignore_blacklist=local_ignore_blacklist) elif list_type.lower() == 'watchlist': for authenticate_user, limit in value.items(): if limit <= 0: @@ -535,11 +540,16 @@ def automatic_shows(add_delay=2.5, no_search=False, notifications=False, ignore_ else: log.info("Adding %d shows from the %s from %s", limit, list_type, authenticate_user) + local_ignore_blacklist = ignore_blacklist + + if "watchlist:%s".format(authenticate_user) in cfg.filters.shows.disabled_for: + local_ignore_blacklist = True + # run shows added_shows = shows.callback(list_type=list_type, add_limit=limit, add_delay=add_delay, no_search=no_search, notifications=notifications, authenticate_user=authenticate_user, - ignore_blacklist=ignore_blacklist) + ignore_blacklist=local_ignore_blacklist) elif list_type.lower() == 'lists': for list, v in value.items(): if isinstance(v, dict): @@ -549,11 +559,16 @@ def automatic_shows(add_delay=2.5, no_search=False, notifications=False, ignore_ authenticate_user = None limit = v + local_ignore_blacklist = ignore_blacklist + + if "list:%s".format(list) in cfg.filters.shows.disabled_for: + local_ignore_blacklist = True + # run shows added_shows = shows.callback(list_type=list, add_limit=limit, add_delay=add_delay, no_search=no_search, notifications=notifications, authenticate_user=authenticate_user, - ignore_blacklist=ignore_blacklist) + ignore_blacklist=local_ignore_blacklist) if added_shows is None: log.error("Failed adding shows from Trakt's %s list", list_type) @@ -596,10 +611,15 @@ def automatic_movies(add_delay=2.5, no_search=False, notifications=False, ignore else: log.info("Adding %d movies from Trakt's %s list", limit, list_type) + local_ignore_blacklist = ignore_blacklist + + if list_type.lower() in cfg.filters.movies.disabled_for: + local_ignore_blacklist = True + # run movies added_movies = movies.callback(list_type=list_type, add_limit=limit, add_delay=add_delay, no_search=no_search, - notifications=notifications, ignore_blacklist=ignore_blacklist) + notifications=notifications, ignore_blacklist=local_ignore_blacklist) elif list_type.lower() == 'watchlist': for authenticate_user, limit in value.items(): if limit <= 0: @@ -608,11 +628,16 @@ def automatic_movies(add_delay=2.5, no_search=False, notifications=False, ignore else: log.info("Adding %d movies from the %s from %s", limit, list_type, authenticate_user) + local_ignore_blacklist = ignore_blacklist + + if "watchlist:%s".format(authenticate_user) in cfg.filters.movies.disabled_for: + local_ignore_blacklist = True + # run movies added_movies = movies.callback(list_type=list_type, add_limit=limit, add_delay=add_delay, no_search=no_search, notifications=notifications, authenticate_user=authenticate_user, - ignore_blacklist=ignore_blacklist) + ignore_blacklist=local_ignore_blacklist) elif list_type.lower() == 'lists': for list, v in value.items(): if isinstance(v, dict): @@ -622,11 +647,16 @@ def automatic_movies(add_delay=2.5, no_search=False, notifications=False, ignore authenticate_user = None limit = v + local_ignore_blacklist = ignore_blacklist + + if "list:%s".format(list) in cfg.filters.movies.disabled_for: + local_ignore_blacklist = True + # run shows added_movies = movies.callback(list_type=list, add_limit=limit, add_delay=add_delay, no_search=no_search, notifications=notifications, authenticate_user=authenticate_user, - ignore_blacklist=ignore_blacklist) + ignore_blacklist=local_ignore_blacklist) if added_movies is None: log.error("Failed adding movies from Trakt's %s list", list_type)