removed sort_by and now am overloading collection_order

pull/541/head
meisnate12 3 years ago
parent e0c42c272a
commit 4aa536b27a

@ -434,8 +434,10 @@ class CollectionBuilder:
self.details["collection_order"] = self.data[methods["collection_order"]].lower() self.details["collection_order"] = self.data[methods["collection_order"]].lower()
if self.data[methods["collection_order"]].lower() == "custom" and self.build_collection: if self.data[methods["collection_order"]].lower() == "custom" and self.build_collection:
self.custom_sort = True self.custom_sort = True
elif (self.library.is_movie and self.data[methods["collection_order"]].lower() in plex.movie_sorts) or (self.library.is_show and self.data[methods["collection_order"]].lower() in plex.show_sorts):
self.custom_sort = self.data[methods["collection_order"]].lower()
else: else:
raise Failed(f"{self.Type} Error: {self.data[methods['collection_order']]} collection_order invalid\n\trelease (Order Collection by release dates)\n\talpha (Order Collection Alphabetically)\n\tcustom (Custom Order Collection)") raise Failed(f"{self.Type} Error: {self.data[methods['collection_order']]} collection_order invalid\n\trelease (Order Collection by release dates)\n\talpha (Order Collection Alphabetically)\n\tcustom (Custom Order Collection)\n\tOther sorting options can be found at https://github.com/meisnate12/Plex-Meta-Manager/wiki/Smart-Builders#sort-options")
self.sort_by = None self.sort_by = None
if "sort_by" in methods and not self.playlist: if "sort_by" in methods and not self.playlist:
@ -596,7 +598,7 @@ class CollectionBuilder:
else: else:
logger.error(e) logger.error(e)
if self.custom_sort and (len(self.builders) > 1 or self.builders[0][0] not in custom_sort_builders): if self.custom_sort is True and (len(self.builders) > 1 or self.builders[0][0] not in custom_sort_builders):
raise Failed(f"{self.Type} Error: " + ('Playlists' if playlist else 'collection_order: custom') + raise Failed(f"{self.Type} Error: " + ('Playlists' if playlist else 'collection_order: custom') +
(f" can only be used with a single builder per {self.type}" if len(self.builders) > 1 else f" cannot be used with {self.builders[0][0]}")) (f" can only be used with a single builder per {self.type}" if len(self.builders) > 1 else f" cannot be used with {self.builders[0][0]}"))
@ -2245,11 +2247,11 @@ class CollectionBuilder:
logger.info("") logger.info("")
util.separator(f"Sorting {self.name} {self.Type}", space=False, border=False) util.separator(f"Sorting {self.name} {self.Type}", space=False, border=False)
logger.info("") logger.info("")
if self.sort_by: if self.custom_sort is True:
search_data = self.build_filter("plex_search", {"sort_by": self.sort_by, "any": {"collection": self.name}})
items = self.library.get_filter_items(search_data[2])
else:
items = self.added_items items = self.added_items
else:
search_data = self.build_filter("plex_search", {"sort_by": self.custom_sort, "any": {"collection": self.name}})
items = self.library.get_filter_items(search_data[2])
previous = None previous = None
for item in items: for item in items:
text = f"after {util.item_title(previous)}" if previous else "to the beginning" text = f"after {util.item_title(previous)}" if previous else "to the beginning"

@ -267,6 +267,7 @@ class ConfigFile:
"test": check_for_attribute(self.data, "test", parent="notifiarr", var_type="bool", default=False, do_print=False, save=False) "test": check_for_attribute(self.data, "test", parent="notifiarr", var_type="bool", default=False, do_print=False, save=False)
}) })
except Failed as e: except Failed as e:
util.print_stacktrace()
logger.error(e) logger.error(e)
logger.info(f"Notifiarr Connection {'Failed' if self.NotifiarrFactory is None else 'Successful'}") logger.info(f"Notifiarr Connection {'Failed' if self.NotifiarrFactory is None else 'Successful'}")
else: else:
@ -567,14 +568,14 @@ class ConfigFile:
if "tmdb_collections" in lib["operations"]: if "tmdb_collections" in lib["operations"]:
params["tmdb_collections"] = { params["tmdb_collections"] = {
"exclude_ids": [], "exclude_ids": [],
"remove_suffix": None, "remove_suffix": [],
"dictionary_variables": {}, "dictionary_variables": {},
"template": {"tmdb_collection_details": "<<collection_id>>"} "template": {"tmdb_collection_details": "<<collection_id>>"}
} }
if lib["operations"]["tmdb_collections"] and isinstance(lib["operations"]["tmdb_collections"], dict): if lib["operations"]["tmdb_collections"] and isinstance(lib["operations"]["tmdb_collections"], dict):
params["tmdb_collections"]["exclude_ids"] = check_for_attribute(lib["operations"]["tmdb_collections"], "exclude_ids", var_type="int_list", default_is_none=True, save=False) params["tmdb_collections"]["exclude_ids"] = check_for_attribute(lib["operations"]["tmdb_collections"], "exclude_ids", var_type="int_list", default_is_none=True, save=False)
params["tmdb_collections"]["remove_suffix"] = check_for_attribute(lib["operations"]["tmdb_collections"], "remove_suffix", default_is_none=True, save=False) params["tmdb_collections"]["remove_suffix"] = check_for_attribute(lib["operations"]["tmdb_collections"], "remove_suffix", var_type="comma_list", default_is_none=True, save=False)
if "dictionary_variables" in lib["operations"]["tmdb_collections"] and lib["operations"]["tmdb_collections"]["dictionary_variables"] and isinstance(lib["operations"]["tmdb_collections"]["dictionary_variables"], dict): if "dictionary_variables" in lib["operations"]["tmdb_collections"] and lib["operations"]["tmdb_collections"]["dictionary_variables"] and isinstance(lib["operations"]["tmdb_collections"]["dictionary_variables"], dict):
for key, value in lib["operations"]["tmdb_collections"]["dictionary_variables"].items(): for key, value in lib["operations"]["tmdb_collections"]["dictionary_variables"].items():
if isinstance(value, dict): if isinstance(value, dict):
@ -587,8 +588,6 @@ class ConfigFile:
logger.warning("Config Warning: Using default template for tmdb_collections") logger.warning("Config Warning: Using default template for tmdb_collections")
else: else:
logger.error("Config Error: tmdb_collections blank using default settings") logger.error("Config Error: tmdb_collections blank using default settings")
if params["tmdb_collections"]["remove_suffix"]:
params["tmdb_collections"]["remove_suffix"] = params["tmdb_collections"]["remove_suffix"].strip()
if "genre_mapper" in lib["operations"]: if "genre_mapper" in lib["operations"]:
if lib["operations"]["genre_mapper"] and isinstance(lib["operations"]["genre_mapper"], dict): if lib["operations"]["genre_mapper"] and isinstance(lib["operations"]["genre_mapper"], dict):
params["genre_mapper"] = {} params["genre_mapper"] = {}

@ -15,12 +15,14 @@ class Notifiarr:
self.apikey = params["apikey"] self.apikey = params["apikey"]
self.develop = params["develop"] self.develop = params["develop"]
self.test = params["test"] self.test = params["test"]
logger.debug(f"Environment: {'Test' if self.test else 'Develop' if self.develop else 'Production'}")
url, _ = self.get_url("user/validate/") url, _ = self.get_url("user/validate/")
response = self.config.get(url) response = self.config.get(url)
try: try:
response_json = response.json() response_json = response.json()
except JSONDecodeError as e: except JSONDecodeError as e:
raise Failed(e) logger.debug(e)
raise Failed("Notifiarr Error: Invalid response")
if response.status_code >= 400 or ("result" in response_json and response_json["result"] == "error"): if response.status_code >= 400 or ("result" in response_json and response_json["result"] == "error"):
logger.debug(f"Response: {response_json}") logger.debug(f"Response: {response_json}")
raise Failed(f"({response.status_code} [{response.reason}]) {response_json}") raise Failed(f"({response.status_code} [{response.reason}]) {response_json}")

@ -846,7 +846,6 @@ def library_operations(config, library):
logger.info("") logger.info("")
util.separator(f"Starting TMDb Collections") util.separator(f"Starting TMDb Collections")
logger.info("") logger.info("")
suffixes = util.get_list(library.tmdb_collections["remove_suffix"])
new_collections = {} new_collections = {}
for _i, _n in tmdb_collections.items(): for _i, _n in tmdb_collections.items():
if int(_i) not in library.tmdb_collections["exclude_ids"]: if int(_i) not in library.tmdb_collections["exclude_ids"]:
@ -854,8 +853,7 @@ def library_operations(config, library):
for k, v in library.tmdb_collections["dictionary_variables"]: for k, v in library.tmdb_collections["dictionary_variables"]:
if int(_i) in v: if int(_i) in v:
template[k] = v[int(_i)] template[k] = v[int(_i)]
if suffixes: for suffix in library.tmdb_collections["remove_suffix"]:
for suffix in suffixes:
if _n.endswith(suffix): if _n.endswith(suffix):
_n = _n[:-len(_n)] _n = _n[:-len(_n)]
new_collections[_n.strip()] = {"template": template} new_collections[_n.strip()] = {"template": template}
@ -1044,7 +1042,7 @@ def run_collection(config, library, metadata, requested_collections):
logger.info("") logger.info("")
logger.info(f"Plex Server Movie pre-roll video updated to {builder.server_preroll}") logger.info(f"Plex Server Movie pre-roll video updated to {builder.server_preroll}")
if (builder.item_details or builder.custom_sort or builder.sort_by) and run_item_details and builder.builders: if (builder.item_details or builder.custom_sort) and run_item_details and builder.builders:
try: try:
builder.load_collection_items() builder.load_collection_items()
except Failed: except Failed:
@ -1053,7 +1051,7 @@ def run_collection(config, library, metadata, requested_collections):
else: else:
if builder.item_details: if builder.item_details:
builder.update_item_details() builder.update_item_details()
if builder.custom_sort or builder.sort_by: if builder.custom_sort:
library.run_sort.append(builder) library.run_sort.append(builder)
# builder.sort_collection() # builder.sort_collection()

Loading…
Cancel
Save