CommunityScripts
CommunityScripts copied to clipboard
[renamerOnUpdate] Ignore genders only if above performer_limit
I want to do the following. I have the performer_limit = 3
. When there are two females and one male I want them all to appear but if there are three females and one male I want the three females to appear. So I want to sort them based on gender. Instead of ignoring all but female as I can do right now with
performer_ignoreGender = ["MALE", "TRANSGENDER_MALE", "TRANSGENDER_FEMALE", "INTERSEX", "NON_BINARY"]
I would replace the ignore performers list for a prioritize performer list. The performers are chosen based on the order of genders in the PRIORITIZE_PERFORMERS list. Performers with genders not present in the list are discarded.
Here's the modified code that replaces the PERFORMER_IGNOREGENDER
list with a PRIORITIZE_PERFORMERS
list, which prioritizes performers based on their gender according to the order in the list. Performers with genders not present in the list are discarded:
# Prioritize performers based on their gender
# Performers with genders not present in the list will be discarded
PRIORITIZE_PERFORMERS = ["Female", "Male", "Transgender Female", "Transgender Male"]
# ...
def extract_info(scene: dict, template: None):
# ...
scene_information["performer_path"] = None
if scene.get("performers"):
perf_list = []
perf_list_stashid = []
perf_rating = {"0": []}
perf_favorite = {"yes": [], "no": []}
for perf in scene["performers"]:
if perf.get("gender"):
if perf["gender"] not in [gender.lower() for gender in PRIORITIZE_PERFORMERS]:
continue
else:
continue # Skip performers with undefined gender
# Path-related operations
# ...
perf_list.append(perf["name"])
# Rating and favorite operations
# ...
# Sort performers based on the priority order
perf_list.sort(key=lambda x: next((i for i, gender in enumerate(PRIORITIZE_PERFORMERS) if gender.lower() in x.lower()), float('inf')))
# Rest of the code
# ...
# ...
In this modified code, the PRIORITIZE_PERFORMERS
list is defined at the top, containing the desired order of genders to prioritize. In the extract_info
function, we first check if the performer's gender is present in the PRIORITIZE_PERFORMERS
list (after converting to lowercase for case-insensitive comparison). If the gender is not present, we skip that performer using the continue
statement.
For performers with valid genders, we proceed with the rest of the operations as before.
After populating the perf_list
, we sort it using a custom key function that assigns a numeric priority based on the order of genders in the PRIORITIZE_PERFORMERS
list. Performers with genders earlier in the list will have a lower numeric priority and will be sorted first. Performers with genders not present in the list will have a priority of float('inf')
and will effectively be sorted last (i.e., discarded).
The rest of the code remains the same, except for the removal of the PERFORMER_IGNOREGENDER
list, which is no longer needed.