Skip to content

Commit

Permalink
Merge pull request #64 from mza921/develop
Browse files Browse the repository at this point in the history
Indentation
  • Loading branch information
mza921 authored Oct 26, 2020
2 parents e3c9e82 + 420c688 commit 4ee304c
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 139 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Plex Auto Collections
##### Version 2.0.0
##### Version 2.0.1
Plex Auto Collections is a Python 3 script that works off a configuration file to create/update Plex collections. Collection management with this tool can be automated in a varying degree of customizability. Supports IMDB, TMDb, and Trakt lists as well as built in Plex filters such as actors, genres, year, studio and more.

![https://i.imgur.com/iHAYFIZ.png](https://i.imgur.com/iHAYFIZ.png)
Expand Down
152 changes: 101 additions & 51 deletions app/config_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,33 @@ def check_for_attribute(config, attribute, parent=None, test_list=None, options=
from ruamel.yaml.util import load_yaml_guess_indent
new_config, ind, bsi = load_yaml_guess_indent(open(Config.config_path))
endline = "\n| {} sub-attribute {} added to config".format(parent, attribute)
if parent not in new_config: new_config = {parent: {attribute: default}}
elif not new_config[parent]: new_config[parent] = {attribute: default}
elif attribute not in new_config[parent]: new_config[parent][attribute] = default
else: endLine = ""
if parent not in new_config:
new_config = {parent: {attribute: default}}
elif not new_config[parent]:
new_config[parent] = {attribute: default}
elif attribute not in new_config[parent]:
new_config[parent][attribute] = default
else:
endLine = ""
ruamel.yaml.round_trip_dump(new_config, open(Config.config_path, 'w'), indent=ind, block_seq_indent=bsi)
elif not config[attribute] and config[attribute] != False: message = "| Config Error: {} is blank".format(text)
elif not config[attribute] and config[attribute] != False:
message = "| Config Error: {} is blank".format(text)
elif type == "bool":
if isinstance(config[attribute], bool): return config[attribute]
else: message = "| Config Error: {} must be either true or false".format(text)
if isinstance(config[attribute], bool):
return config[attribute]
else:
message = "| Config Error: {} must be either true or false".format(text)
elif type == "int":
if isinstance(config[attribute], int): return config[attribute]
else: message = "| Config Error: {} must an integer".format(text)
elif test_list == None: return config[attribute]
elif config[attribute] in test_list: return config[attribute]
else: message = "| Config Error: {}: {} is an invalid input".format(text, config[attribute])
if isinstance(config[attribute], int):
return config[attribute]
else:
message = "| Config Error: {} must an integer".format(text)
elif test_list == None:
return config[attribute]
elif config[attribute] in test_list:
return config[attribute]
else:
message = "| Config Error: {}: {} is an invalid input".format(text, config[attribute])
if default != None or default_is_none:
message = message + " using {} as default".format(default)
message = message + endline
Expand Down Expand Up @@ -117,15 +129,24 @@ def __init__(self, config_path):
config = Config(config_path).plex
fatal_message = ""
message = ""
try: self.library = check_for_attribute(config, "library", parent="plex", throw=True)
except SystemExit as e: fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try: self.library_type = check_for_attribute(config, "library_type", parent="plex", test_list=["movie", "show"], options="| \tmovie (Movie Library)\n| \tshow (Show Library)", throw=True)
except SystemExit as e: fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try: self.token = check_for_attribute(config, "token", parent="plex", throw=True)
except SystemExit as e: fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try: self.url = check_for_attribute(config, "url", parent="plex", throw=True)
except SystemExit as e: fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try: self.sync_mode = check_for_attribute(config, "sync_mode", parent="plex", default="append", test_list=["append", "sync"], options="| \tappend (Only Add Items to the Collection)\n| \tsync (Add & Remove Items from the Collection)", throw=True)
try:
self.library = check_for_attribute(config, "library", parent="plex", throw=True)
except SystemExit as e:
fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try:
self.library_type = check_for_attribute(config, "library_type", parent="plex", test_list=["movie", "show"], options="| \tmovie (Movie Library)\n| \tshow (Show Library)", throw=True)
except SystemExit as e:
fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try:
self.token = check_for_attribute(config, "token", parent="plex", throw=True)
except SystemExit as e:
fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try:
self.url = check_for_attribute(config, "url", parent="plex", throw=True)
except SystemExit as e:
fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try:
self.sync_mode = check_for_attribute(config, "sync_mode", parent="plex", default="append", test_list=["append", "sync"], options="| \tappend (Only Add Items to the Collection)\n| \tsync (Add & Remove Items from the Collection)", throw=True)
except SystemExit as e:
self.sync_mode = check_for_attribute(config, "sync_mode", parent="plex", default="append", test_list=["append", "sync"], do_print=False)
message = message + "\n" + str(e) if len(message) > 0 else str(e)
Expand Down Expand Up @@ -169,20 +190,34 @@ def __init__(self, config_path):
print("| Connecting to Radarr...")
fatal_message = ""
message = ""
try: self.url = check_for_attribute(config, "url", parent="radarr", throw=True)
except SystemExit as e: fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try: self.version = check_for_attribute(config, "version", parent="radarr", test_list=["v2", "v3"], options="| \tv2 (For Radarr 0.2)\n| \tv3 (For Radarr 3.0)", default="v2", throw=True)
except SystemExit as e: message = message + "\n" + str(e) if len(message) > 0 else str(e)
try: self.token = check_for_attribute(config, "token", parent="radarr", throw=True)
except SystemExit as e: fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try: self.quality_profile_id = check_for_attribute(config, "quality_profile_id", parent="radarr", type="int", throw=True)
except SystemExit as e: fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try: self.root_folder_path = check_for_attribute(config, "root_folder_path", parent="radarr", throw=True)
except SystemExit as e: fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try: self.add_movie = check_for_attribute(config, "add_movie", parent="radarr", options="| \ttrue (Add missing movies to Radarr)\n| \tfalse (Do not add missing movies to Radarr)", type="bool", default_is_none=True, throw=True)
except SystemExit as e: message = message + "\n" + str(e) if len(message) > 0 else str(e)
try: self.search_movie = check_for_attribute(config, "search_movie", parent="radarr", options="| \ttrue (Have Radarr seach the added movies)\n| \tfalse (Do not have Radarr seach the added movies)", type="bool", default=False, throw=True)
except SystemExit as e: message = message + "\n" + str(e) if len(message) > 0 else str(e)
try:
self.url = check_for_attribute(config, "url", parent="radarr", throw=True)
except SystemExit as e:
fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try:
self.version = check_for_attribute(config, "version", parent="radarr", test_list=["v2", "v3"], options="| \tv2 (For Radarr 0.2)\n| \tv3 (For Radarr 3.0)", default="v2", throw=True)
except SystemExit as e:
message = message + "\n" + str(e) if len(message) > 0 else str(e)
try:
self.token = check_for_attribute(config, "token", parent="radarr", throw=True)
except SystemExit as e:
fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try:
self.quality_profile_id = check_for_attribute(config, "quality_profile_id", parent="radarr", type="int", throw=True)
except SystemExit as e:
fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try:
self.root_folder_path = check_for_attribute(config, "root_folder_path", parent="radarr", throw=True)
except SystemExit as e:
fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try:
self.add_movie = check_for_attribute(config, "add_movie", parent="radarr", options="| \ttrue (Add missing movies to Radarr)\n| \tfalse (Do not add missing movies to Radarr)", type="bool", default_is_none=True, throw=True)
except SystemExit as e:
message = message + "\n" + str(e) if len(message) > 0 else str(e)
try:
self.search_movie = check_for_attribute(config, "search_movie", parent="radarr", options="| \ttrue (Have Radarr seach the added movies)\n| \tfalse (Do not have Radarr seach the added movies)", type="bool", default=False, throw=True)
except SystemExit as e:
message = message + "\n" + str(e) if len(message) > 0 else str(e)
if len(fatal_message) > 0:
print(fatal_message + "\n" + message)
Radarr.valid = False
Expand Down Expand Up @@ -217,10 +252,14 @@ def __init__(self, config_path):
fatal_message = ""
message = ""
tmdb = Collection()
try: self.apikey = check_for_attribute(config, "apikey", parent="tmdb", throw=True)
except SystemExit as e: fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try: self.language = check_for_attribute(config, "language", parent="tmdb", default="en", throw=True)
except SystemExit as e: message = message + "\n" + str(e) if len(message) > 0 else str(e)
try:
self.apikey = check_for_attribute(config, "apikey", parent="tmdb", throw=True)
except SystemExit as e:
fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try:
self.language = check_for_attribute(config, "language", parent="tmdb", default="en", throw=True)
except SystemExit as e:
message = message + "\n" + str(e) if len(message) > 0 else str(e)
if len(fatal_message) > 0:
print(fatal_message + "\n" + message)
TMDB.valid = False
Expand Down Expand Up @@ -250,10 +289,14 @@ def __init__(self, config_path):
elif TraktClient.valid == None:
print("| Connecting to Trakt...")
fatal_message = ""
try: self.client_id = check_for_attribute(config, "client_id", parent="trakt", throw=True)
except SystemExit as e: fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try: self.client_secret = check_for_attribute(config, "client_secret", parent="trakt", throw=True)
except SystemExit as e: fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try:
self.client_id = check_for_attribute(config, "client_id", parent="trakt", throw=True)
except SystemExit as e:
fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
try:
self.client_secret = check_for_attribute(config, "client_secret", parent="trakt", throw=True)
except SystemExit as e:
fatal_message = fatal_message + "\n" + str(e) if len(fatal_message) > 0 else str(e)
if len(fatal_message) > 0:
print(fatal_message)
TraktClient.valid = False
Expand Down Expand Up @@ -322,19 +365,26 @@ def __init__(self, config_path):
if config:
def checkPath(attribute, path, type, input_directory, extra=None):
if path is None:
if input_directory is None: print("| {} Directory was blank and defaults were not found".format(type))
else: print("| {} Directory: {} not found".format(type, input_directory))
if input_directory is None:
print("| {} Directory was blank and defaults were not found".format(type))
else:
print("| {} Directory: {} not found".format(type, input_directory))
else:
abspath = os.path.abspath(path)
if attribute in config: print("| Using {} for {} Directory".format(abspath, type) if os.path.exists(abspath) else "{} Directory not found: {}".format(type, abspath) if value else "{} attribute is empty".format(attribute))
elif extra and extra not in config: print("| {} & {} attributes not found".format(attribute, extra))
if attribute in config:
print("| Using {} for {} Directory".format(abspath, type) if os.path.exists(abspath) else "{} Directory not found: {}".format(type, abspath) if value else "{} attribute is empty".format(attribute))
elif extra and extra not in config:
print("| {} & {} attributes not found".format(attribute, extra))
checkPath("poster_directory", self.poster, "Posters", input_poster, "image_directory")
checkPath("background_directory", self.background, "Backgrounds", input_background, "image_directory")
checkPath("image_directory", self.image, "Images", input_image)
else:
if self.poster: print("| Using {} for posters directory".format(os.path.abspath(self.poster)))
if self.background: print("| Using {} for backgrounds directory".format(os.path.abspath(self.background)))
if self.image: print("| Using {} for images directory".format(os.path.abspath(self.image)))
if self.poster:
print("| Using {} for posters directory".format(os.path.abspath(self.poster)))
if self.background:
print("| Using {} for backgrounds directory".format(os.path.abspath(self.background)))
if self.image:
print("| Using {} for images directory".format(os.path.abspath(self.image)))
if not self.poster and not self.background and not self.image:
print("| Posters Directory not found: {} or {}".format(os.path.join(app_dir, "posters"), os.path.join(app_dir, "..", "config", "posters")))
print("| Backgrounds Directory not found: {} or {}".format(os.path.join(app_dir, "backgrounds"), os.path.join(app_dir, "..", "config", "backgrounds")))
Expand All @@ -345,7 +395,7 @@ def checkPath(attribute, path, type, input_directory, extra=None):
def modify_config(config_path, c_name, m, value):
config = Config(config_path)
if m == "movie":
print("| Movie's in config not supported yet")
print("| Movies in config not supported yet")
else:
try:
if value not in str(config.data['collections'][c_name][m]):
Expand Down
Loading

0 comments on commit 4ee304c

Please sign in to comment.