Confuzu / CivitAI-Model-grabber

The Script Downloads in bulk both model(Lora,Lycoris,Embeding etc..) and related images, from a given CivitAI Username
GNU General Public License v3.0
18 stars 4 forks source link
api civitai python3

Civit-Model-grabber

The script Supports different download types: Lora, Checkpoints, Embeddings, Training Data, Other, or All and related images from a given CivitAI username, organizing them into appropriate directories and maintaining details in a text file.

It's designed to download only the files that are not already present in the specified username's folder. If the user uploads new models, running the script again will download only the newly uploaded files.

Example of Details.txt

Model URL: https://civitai.com/models/ID
File Name: Name of the Model.ending
File URL: https://civitai.com/api/download/models/ID
Image ID: ID
Image URL: https://image.civitai.com/Random_characters/width=450/ID.jpeg

File Structure
The downloaded files will be organized in the following structure:

model_downloads/
├── username1/
│   ├── Lora/
│   │   ├── model1/
│   │   │   ├── file1.safetensors
│   │   │   ├── image1.jpeg
│   │   │   └── details.txt
│   │   └── model2/
│   │       ├── file3.safetensors
│   │       ├── image2.jpeg
│   │       └── details.txt
│   ├── Checkpoints/
│   ├── Embeddings/
│   ├── Training_Data/
│   └── Other/
└── username2/
    ├── Lora/
    ├── Checkpoints/
    ├── Embeddings/
    ├── Training_Data/
    └── Other/

How to use

install Python3
pip install -r requirements.txt
python civitAI_Model_downloader.py one or multiple usernames space separated

You can also give the script this 5 extra Arguments

--retry_delay 

Helper script fetch_all_models.py

python fetch_all_models.py --username <USERNAME> --token <API_TOKEN>

Example of username.txt created with helper script fetch_all_models.py

Summary:
Total - Count: 61
Checkpoints - Count: 12
Embeddings - Count: 33
Lora - Count: 11
Training_Data - Count: 2
Other - Count: 3

Detailed Listing:
Checkpoints - Count: 12
Checkpoints - Item: NAME
...

Embeddings - Count: 33
Embeddings - Item: NAME - Embeddings
...

Lora - Count: 11
Lora - Item: NAME
...

Training_Data - Count: 2
Training_Data - Item: NAME_training_data.zip
...

Other - Count: 3
Other - Item: NAME - Type: Other
...

You can create your API Key here Account Settings. Scoll down until the end and you find this Box

API

Updates & Bugfixes

0.4 New Features & Updates & Bugfixes

New features:

Updates:

Bugfixes:

0.3 Bugfix & Changes

Enhanced Character Filtering:
The script has been modified to extensively filter out forbidden and problematic characters to prevent issues during the folder creation process.

Error Handling Improvements:
In cases where the script encounters characters that prevent folder creation, it now logs the name and URL of the affected download.
This information is recorded in a pre-existing text file, which is automatically named after the user whose content is being downloaded. This update allows users to manually complete downloads if issues arise.

failed_downloads_username.txt

Changed from Skipping image to Truncate when path length exceeding the limit.

0.2 New Features & Update & Bugfix

New long awaited Feature

Selective Download Options
Users can now choose to download specific content types:
Lora
Checkpoints
Embeddings
Other
Everything but Lora, Checkpoints, Embeddings (grouped under Other_Model_types for less frequently downloaded items)
All
is the Default Download Behavior: The default option to download all available content remains if no specific download parameters are set.

Command Line and Interactive Enhancements:

Command Line Arguments: Users can directly specify their download preference (Lora, Checkpoints, Embedding, Other or All) via command line alongside other startup parameters.
Interactive Mode: If no command line arguments are specified, the program will prompt users interactively to select the content they wish to download. Pressing the Enter key activates the default settings to download all content.

Folder Structure Update:

Organized Storage: The program’s folder structure has been reorganized to support new download options efficiently:
Main directory: model_downloads/
User-specific subdirectory: Username/
Content-specific subfolders for Lora, Checkpoints, Embeddings, and Other_Model_types each containing item-specific subfolders.

Bugfix
The script will no longer remove the file name if it is written in the same way as the folder name. This could happen from time to time due to the sanitization function of the script.

0.1 Better Errorhandling

New function to avoid OSError: [Errno 36] File name too long:

Pagination is fixed
New Function Multiple Usernames