[19] #1174 fix content mapper, fix key names, and conditionals

pull/1184/head
meisnate12 2 years ago
parent 86c4d618bb
commit 19b6fff1a7

@ -1 +1 @@
1.18.0-develop18
1.18.0-develop19

@ -37,7 +37,7 @@ templates:
- key: truehd_atmos
value: '(?i)^(?=.*\btrue[ ._-]?hd(\b|\d))(?=.*\batmos(\b|\d))'
- key: dtsx
value: '(?i)\bdts[ ._-]?x(\b|\d)'
value: '(?i)\bdts[ ._-]?x\b'
- key: plus_atmos
value: '(?i)^(?=.*\b(dd[p+])|(dolby digital plus)\B)(?=.*\batmos(\b|\d))'
- key: dolby_atmos

@ -301,7 +301,9 @@ class DataFile:
elif language in var_value:
key_name_variables[var_key] = var_value[language]
if "key_name" in variables:
variables["translated_key_name"] = key_name_variables[variables["key_name"]] if variables["key_name"] in key_name_variables else variables["key_name"]
variables["original_key_name"] = variables["key_name"]
if variables["key_name"] in key_name_variables:
variables["key_name"] = key_name_variables[variables["key_name"]]
def replace_var(input_item, search_dicts):
if not isinstance(search_dicts, list):
@ -345,7 +347,10 @@ class DataFile:
raise Failed(f"{self.data_type} Error: conditional {con_key} is not a dictionary")
final_key = replace_var(con_key, [variables, default])
if final_key != con_key:
logger.debug(f"Variable: {final_key}")
logger.trace(f"Variable: {final_key}")
if final_key in variables:
logger.debug(f'Conditional Variable: {final_key} overwritten to "{variables[final_key]}"')
continue
if "conditions" not in con_value:
raise Failed(f"{self.data_type} Error: conditions sub-attribute required")
conditions = con_value["conditions"]
@ -368,34 +373,34 @@ class DataFile:
if var_key.endswith(".exists"):
var_value = util.parse(self.data_type, var_key, var_value, datatype="bool", default=False)
if (not var_value and var_key[:-7] in variables and variables[var_key[:-7]]) or (var_value and (var_key[:-7] not in variables or not variables[var_key[:-7]])):
logger.debug(f"Condition {i} Failed: {var_key}: {'true does not exist' if var_value else 'false exists'}")
logger.trace(f"Condition {i} Failed: {var_key}: {'true does not exist' if var_value else 'false exists'}")
condition_passed = False
elif var_key.endswith(".not"):
if (isinstance(var_value, list) and variables[var_key] in var_value) or \
(not isinstance(var_value, list) and str(variables[var_key]) == str(var_value)):
if isinstance(var_value, list):
logger.debug(f'Condition {i} Failed: {var_key} "{variables[var_key]}" in {var_value}')
logger.trace(f'Condition {i} Failed: {var_key} "{variables[var_key]}" in {var_value}')
else:
logger.debug(f'Condition {i} Failed: {var_key} "{variables[var_key]}" is "{var_value}"')
logger.trace(f'Condition {i} Failed: {var_key} "{variables[var_key]}" is "{var_value}"')
condition_passed = False
elif var_key in variables:
if (isinstance(var_value, list) and variables[var_key] not in var_value) or \
(not isinstance(var_value, list) and str(variables[var_key]) != str(var_value)):
if isinstance(var_value, list):
logger.debug(f'Condition {i} Failed: {var_key} "{variables[var_key]}" not in {var_value}')
logger.trace(f'Condition {i} Failed: {var_key} "{variables[var_key]}" not in {var_value}')
else:
logger.debug(f'Condition {i} Failed: {var_key} "{variables[var_key]}" is not "{var_value}"')
logger.trace(f'Condition {i} Failed: {var_key} "{variables[var_key]}" is not "{var_value}"')
condition_passed = False
elif var_key in default:
if (isinstance(var_value, list) and default[var_key] not in var_value) or \
(not isinstance(var_value, list) and str(default[var_key]) != str(var_value)):
if isinstance(var_value, list):
logger.debug(f'Condition {i} Failed: {var_key} "{default[var_key]}" not in {var_value}')
logger.trace(f'Condition {i} Failed: {var_key} "{default[var_key]}" not in {var_value}')
else:
logger.debug(f'Condition {i} Failed: {var_key} "{default[var_key]}" is not "{var_value}"')
logger.trace(f'Condition {i} Failed: {var_key} "{default[var_key]}" is not "{var_value}"')
condition_passed = False
else:
logger.debug(f"Condition {i} Failed: {var_key} is not a variable provided or a default variable")
logger.trace(f"Condition {i} Failed: {var_key} is not a variable provided or a default variable")
condition_passed = False
if condition_passed:
logger.debug(f'Conditional Variable: {final_key} is "{condition["value"]}"')
@ -404,11 +409,11 @@ class DataFile:
variables[f"{final_key}_encoded"] = requests.utils.quote(str(condition["value"]))
break
if not condition_found:
if "default" in con_value and final_key not in variables:
if "default" in con_value:
logger.debug(f'Conditional Variable: {final_key} defaults to "{con_value["default"]}"')
variables[final_key] = con_value["default"]
variables[f"{final_key}_encoded"] = requests.utils.quote(str(con_value["default"]))
elif final_key not in variables:
else:
logger.debug(f"Conditional Variable: {final_key} added as optional variable")
optional.append(str(final_key))
optional.append(f"{final_key}_encoded")

@ -359,12 +359,18 @@ class Operations:
new_rating = mal_item.rating
else:
raise Failed
if self.library.content_rating_mapper:
if new_rating is None and self.library.mass_content_rating_update not in ["remove", "reset"]:
if not new_rating:
logger.info(f"No Content Rating Found")
is_none = False
if self.library.content_rating_mapper or self.library.mass_content_rating_update in ["lock", "unlock"]:
if not new_rating and self.library.mass_content_rating_update not in ["remove", "reset"]:
new_rating = item.contentRating
if new_rating in self.library.content_rating_mapper:
if self.library.content_rating_mapper and new_rating in self.library.content_rating_mapper:
new_rating = self.library.content_rating_mapper[new_rating]
if self.library.mass_content_rating_update in ["remove", "reset"] and item.contentRating:
if not new_rating:
is_none = True
if (is_none or self.library.mass_content_rating_update in ["remove", "reset"]) and item.contentRating:
item.editField("contentRating", None, locked=self.library.mass_content_rating_update == "remove")
batch_display += f"\nContent Rating | None"
elif not new_rating and self.library.mass_content_rating_update not in ["lock", "unlock", "remove", "reset"]:

@ -1,5 +1,6 @@
import glob, logging, os, re, requests, ruamel.yaml, signal, sys, time
import glob, os, re, requests, ruamel.yaml, signal, sys, time
from datetime import datetime, timedelta
from modules.logs import MyLogger
from num2words import num2words
from pathvalidate import is_valid_filename, sanitize_filename
from plexapi.audio import Album, Track
@ -13,7 +14,7 @@ except ModuleNotFoundError:
windows = False
logger = logging.getLogger("Plex Meta Manager")
logger: MyLogger = None
class TimeoutExpired(Exception):
pass
@ -526,6 +527,8 @@ def is_boolean_filter(value, data):
def is_string_filter(values, modifier, data):
jailbreak = False
if modifier == ".regex":
logger.trace(f"Regex Values: {values}")
for value in values:
for check_value in data:
if (modifier in ["", ".not"] and check_value.lower() in value.lower()) \

Loading…
Cancel
Save