So if you've been keeping tabs on CivitAI News, civitai recently added an annoying restriction to nsfw images in particular without meta, and now they're hidden or unpublished, until you add meta to them. Some of us might have hundred of posts or images without meta, either due to generating them in comfy or through other sites, and it isn't feasible to manually tag every single one of them. So this script is a major F-U to this unnecessary setback.
To get an idea how many images you have that requires metadata, go to your account page, to the images tab, and click filters, then under modifiers click "Requiring Metadata"
Note: civitai's API is god damn terrible, so half the filters dont work, but this script can do atleast half of all your images (I had 1800 images on my account in total, it checked 1000 images)
# Civitai Post Metadata Editor Script
This Python script automates the process of adding placeholder metadata to image posts on Civitai.com that currently lack it. It performs the following actions:
1. Fetches Image Data: It uses the Civitai API to retrieve lists of images for a specific user, iterating through different sorting options ("Most Comments", "Newest", etc.) and NSFW filters ("None", "Soft", etc.).
2. Identifies Posts Without Metadata: It checks each image item retrieved from the API. If an image's data does not contain a meta field, it proceeds.
3. Opens Edit Page: It uses Selenium and ChromeDriver to automatically open the "edit" page for the corresponding post in a Chrome browser.
4. Edits and Saves:
* It locates and clicks the specific "EDIT" button associated with the image on the post edit page.
* It finds the prompt text area and enters "Filler Text" (Default if not filled)
* It locates and clicks the "Save" button.
5. Pagination and Tracking: It handles pagination using API cursors and keeps track of processed posts and cursors to avoid redundant operations and potential loops.
The script attempts to connect to an existing Chrome instance running with remote debugging enabled on localhost:8989. If it cannot connect, it will automatically download the appropriate chromedriver using webdriver-manager and launch a new Chrome instance.
## Installation
1. Python: Ensure you have Python 3 installed on your system. You can download it from [python.org](https://www.python.org/).
2. Google Chrome: You need the Google Chrome browser installed.
3. Required Packages: Open your terminal (macOS/Linux) or Command Prompt/PowerShell (Windows) and install the necessary Python packages using pip:
pip3 install selenium requests webdriver-manager## Usage
1. Save the Script: Download the Python Script Attached to the Article.
2. Setting up Chrome: We want to control a Chrome browser, so we can edit each post without meta. To do this, you need to launch Chrome with remote debugging enabled before running the script. Close all running instances of Chrome first. Then, open your terminal or command prompt and run the appropriate command for your OS:
*Windows (Command Prompt):**
"C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=8989(Adjust the path if Chrome is installed elsewhere)
*macOS (Terminal):**
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=8989*Linux (Terminal):**
google-chrome --remote-debugging-port=8989(The exact command might vary slightly depending on your Linux distribution and how Chrome was installed, e.g., chromium-browser)
Now Log in to your CivitAI Account to edit metadata for, if you haven't already.
3. Navigate to Directory: Open your terminal or command prompt and navigate to the directory where you saved the python file.
*Windows:** cd C:\path\to\directory
*macOS/Linux:** cd /path/to/directory
(Replace /path/to/directory with the actual path, e.g., /Users/username/Downloads/)
4. Run the Script: Execute the script using Python:
python3 civitmetadata.py5. Enter Token, Username, and (Optional: Filler Text): The script will prompt you to paste your Civitai API token, and then prompt you for your username, and then the filler text (You will need to obtain the civitai token from your Civitai account settings):
Paste your Civitai token:Write your Civitai username: Write the text that will be added to the Prompt [Press Enter to skip]: After each, press Enter.
6. Execution: The script will then start fetching data and interacting with the Chrome browser to edit posts as described in the "Purpose" section. It will print progress information.


