File size: 3,397 Bytes
592406a
9741963
 
592406a
9741963
592406a
9741963
592406a
 
 
 
 
 
 
 
9741963
592406a
9741963
 
 
93ad612
9741963
 
 
592406a
9741963
592406a
93ad612
9741963
592406a
9741963
592406a
9741963
 
 
592406a
9741963
 
 
 
 
 
 
 
 
 
592406a
9741963
 
 
592406a
9741963
592406a
9741963
 
592406a
9741963
 
 
 
 
 
 
 
592406a
9741963
 
 
 
 
 
 
 
592406a
9741963
 
592406a
9741963
592406a
9741963
592406a
 
9741963
592406a
9741963
592406a
9741963
 
 
 
 
 
592406a
9741963
592406a
9741963
592406a
9741963
 
 
592406a
 
9741963
592406a
 
9741963
 
 
592406a
9741963
592406a
9741963
 
 
 
 
 
592406a
9741963
 
 
592406a
 
 
9741963
592406a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

# ComfyUI LoRA Metadata Scraper

This is a Python tool to recursively extract metadata from `.safetensors` files inside your ComfyUI installation. It supports both local metadata extraction and optional CivitAI scraping (for trigger words, tags, descriptions, and preview images/videos).

Features:

- Extracts metadata from LoRAs, checkpoints, VAEs, and ControlNets
- Optionally scrapes CivitAI data (tags, trigger words, preview images/videos)
- Skips files that are already processed (unless forced)
- Lets you scan only the LoRAs folder or the entire ComfyUI setup
- Saves previews in subdirectories or alongside model files
- Supports downloading all, none, or a specific number of previews
- Fully interactive OR command-line friendly
- Gracefully handles CivitAI rate limiting and retries

Folder Setup:

Place everything inside:

```
ComfyUI/
└── utils/
    └── Scrapertool/
        ├── scrape_metadata_recursive.py
        ├── requirements.txt
        └── run_scraper.bat  (optional launcher)
```

Usage:

Option 1: Interactive Mode

Run:

python scrape_metadata_recursive.py --interactive

You’ll be prompted:

A) Scrape CivitAI? (Y/N)
B) Use default delay (0.5s), no delay (0), or custom delay?
C) Force re-scrape if metadata already exists? (Y/N)
D) Scan only the LoRA folder? (Y/N)
E) Save previews in a subdirectory? (Y/N)
F) How many preview images/videos to download? (A=All, N=None, or a number)

Option 2: Command-Line Arguments

Example:

python scrape_metadata_recursive.py --scrape-civitai --delay 0.5 --force --loras-only --previews-subdir --max-media 5

Command-Line Arguments:

--interactive
    Launch interactive menu.

--scrape-civitai
    Enable scraping of metadata and previews from CivitAI.

--delay [seconds]
    Set the delay between API calls and image/video downloads (default: 0.5 seconds).

--force
    Force re-scrape even if metadata JSON already exists.

--loras-only
    Scan only the ComfyUI/models/loras folder. If omitted, scans all subdirectories.

--previews-subdir
    Save previews inside a dedicated subdirectory (e.g., model_previews/).

--no-previews-subdir
    Save previews directly alongside the model file.

--max-media [number]
    Set max number of preview images/videos to download (0 = none, default = all).

How It Finds CivitAI Metadata:

1. First, the script checks if the `.safetensors` file contains a `civitai_metadata` block (fixed in the latest version to look in the correct place).
2. If that block is missing, it falls back to computing the SHA256 hash and queries CivitAI using that.

This ensures compatibility even if metadata is incomplete.

Dependencies:

safetensors
torch
requests
tqdm

Setup Instructions:

1. Create a virtual environment:

python -m venv scrapervenv

2. Activate the virtual environment:

On Windows:
scrapervenv\Scripts\activate

On macOS/Linux:
source scrapervenv/bin/activate

3. Install dependencies:

pip install -r requirements.txt

requirements.txt:

safetensors
torch
requests
tqdm

License:

Creative Commons Attribution 4.0 International (CC BY 4.0)

You may use, share, and adapt this tool for any purpose—including commercial use—as long as you provide attribution to the original creator.

Contributing:

Contributions and improvements are welcome. Please fork, submit pull requests, or open an issue if you'd like to suggest features or report bugs.