|
|
|
# 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. |
|
|