diff --git a/misc/config.py b/misc/config.py index cb87777..536a98f 100644 --- a/misc/config.py +++ b/misc/config.py @@ -28,26 +28,22 @@ base_config = { }, 'filters': { 'shows': { - 'blacklisted_genres': ['animation', 'game-show', 'talk-show', 'home-and-garden', 'children', 'reality', - 'anime', 'news', 'documentary', 'special-interest'], - 'blacklisted_networks': ['twitch', 'youtube', 'nickelodeon', 'hallmark', 'reelzchannel', 'disney', - 'cnn', 'cbbc', 'the movie network', 'teletoon', 'cartoon network', 'espn', - 'yahoo!', - 'fox sports'], - 'allowed_countries': ['us', 'gb', 'ca'], + 'blacklisted_genres': [], + 'blacklisted_networks': [], + 'allowed_countries': [], 'blacklisted_min_runtime': 15, 'blacklisted_min_year': 2000, 'blacklisted_max_year': 2019, 'blacklisted_tvdb_ids': [], }, 'movies': { - 'blacklisted_genres': ['documentary', 'music', 'animation'], + 'blacklisted_genres': [], 'blacklisted_min_runtime': 60, 'blacklisted_min_year': 2000, 'blacklisted_max_year': 2019, - 'blacklist_title_keywords': ['untitled', 'barbie'], + 'blacklist_title_keywords': [], 'blacklisted_tmdb_ids': [], - 'allowed_countries': ['us', 'gb', 'ca'] + 'allowed_countries': [] } }, 'automatic': { @@ -113,25 +109,39 @@ def load_config(): return AttrConfig(json.load(fp)) -def upgrade_settings(defaults, current): +def upgrade_settings(defaults, currents): upgraded = False - res = current.copy() - for k, v in defaults.items(): - if k not in current: - res[k] = v - upgraded = True - print("Added config option: %s" % k) - - if hasattr(v, 'items'): - if k in current: - sub_upgrade, res[k] = upgrade_settings(v, current[k]) - if sub_upgrade: - upgraded = True - else: - res[k] = v - upgraded = True - - return upgraded, AttrConfig(res) + + def inner_upgrade(default, current, key=None): + sub_upgraded = False + merged = current.copy() + if isinstance(default, dict): + for k, v in default.items(): + # missing k + if k not in current: + merged[k] = v + sub_upgraded = True + if not key: + print("Added %r config option: %s" % (str(k), str(v))) + else: + print("Added %r to config option %r: %s" % (str(k), str(key), str(v))) + continue + # iterate children + if isinstance(v, dict) or isinstance(v, list): + did_upgrade, merged[k] = inner_upgrade(default[k], current[k], key=k) + sub_upgraded = did_upgrade if did_upgrade else sub_upgraded + + elif isinstance(default, list) and key: + for v in default: + if v not in current: + merged.append(v) + sub_upgraded = True + print("Added to config option %r: %s" % (str(key), str(v))) + continue + return sub_upgraded, merged + + upgraded, upgraded_settings = inner_upgrade(defaults, currents) + return upgraded, AttrConfig(upgraded_settings) ############################################################