diff --git a/organize-images b/organize-images index b20ebae..5382bd8 100755 --- a/organize-images +++ b/organize-images @@ -178,17 +178,19 @@ ai_dest() { python3 -c " import json, sys m = json.load(open('$AI_META')) -entry = m.get(sys.argv[1], {}) -if not entry: +entry = m.get(sys.argv[1]) +if not entry or not isinstance(entry, dict): print('AI/unknown') sys.exit(0) def clean(s): + if not s: + return 'unknown' return s.replace('/', '-').replace('\\\\', '-') -model = clean(entry.get('model', 'unknown')) -loras = entry.get('loras', []) +model = clean(entry.get('model')) +loras = entry.get('loras') or [] if loras: - combo = '+'.join(clean(l.strip()) for l in loras) + combo = '+'.join(clean(l.strip()) for l in loras if l) combo = (combo[:200]).rstrip('+') print(f'AI/{model}/{combo}') else: @@ -203,8 +205,12 @@ for f in "${FILES[@]}"; do cat=$(classify "$f") if [ "$cat" = "AI" ] && [ "$FLAT" = false ] && [ -n "$AI_META" ]; then - sub=$(ai_dest "$(basename "$f")") - dest="$TARGET/$sub" + sub=$(ai_dest "$(basename "$f")" 2>/dev/null) || sub="" + if [ -z "$sub" ]; then + dest="$TARGET/AI/unknown/" + else + dest="$TARGET/$sub" + fi else dest="$TARGET/$cat/" fi