52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
import os
|
|
from datetime import datetime
|
|
|
|
class ImmatureImageCounter:
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"date": ("STRING", {"default": ""}),
|
|
"subfolder": ("STRING", {"default": "latent"})
|
|
}
|
|
}
|
|
|
|
@classmethod
|
|
def IS_CHANGED(cls, **kwargs):
|
|
return float("NaN")
|
|
|
|
RETURN_TYPES = ("INT",)
|
|
RETURN_NAMES = ("file_count",)
|
|
FUNCTION = "count_images"
|
|
OUTPUT_NODE = True
|
|
|
|
CATEGORY = "utils"
|
|
|
|
def count_images(self, date, subfolder):
|
|
dateFormat = "%Y-%m-%d"
|
|
# Determine the correct date to use
|
|
if not date:
|
|
current_date = datetime.now().strftime(dateFormat)
|
|
else:
|
|
try:
|
|
current_date = datetime.strptime(date, dateFormat).strftime(dateFormat)
|
|
except ValueError:
|
|
return (0,)
|
|
|
|
# Define the image folder path
|
|
image_folder_path = f"output/rapidfire/{current_date}/{subfolder}"
|
|
|
|
# Initialize set to store unique seeds
|
|
unique_seeds = set()
|
|
|
|
# Count unique seeds in the specified folder
|
|
if os.path.exists(image_folder_path) and os.path.isdir(image_folder_path):
|
|
for filename in os.listdir(image_folder_path):
|
|
if filename.lower().endswith('.png'):
|
|
# Split filename to get seed portion
|
|
parts = filename.split('_')
|
|
if parts: # if there's at least one part
|
|
seed = parts[0]
|
|
unique_seeds.add(seed)
|
|
|
|
return (len(unique_seeds),) |