OpenAI TCG Sorter is a script designed to organize images of trading cards by utilizing the OpenAI GPT-4o API for card identification. The script reads card images from a specified directory, processes them using the OpenAI API, and sorts them into categorized directories based on the card name, set name, and TCG name.
- API Integration: Uses OpenAI GPT-4o API for card identification.
- Image Encoding: Converts images to base64 format for API processing.
- Logging: Detailed logging of the processing steps and errors.
- File Organization: Moves and renames files based on card details.
- Alias Resolution: Handles multiple aliases for TCG names.
- Unicode Normalization: Sanitizes filenames to remove special characters.
- Python 3.6+
- An OpenAI API key with paid compute time available.
Install the required packages using pip:
pip install requests unidecodeCreate a tcg.cfg file in the same directory as the script with the following content:
api_key=YOUR_API_KEY_HERE
aliases=alias1:alias1_main,alias2:alias2_main
logging_level=WARNINGapi_key: Your OpenAI API key.aliases: A semicolon-separated list of alias pairs in the formatalias1:alias1_main,alias2:alias2_main.logging_level: Logging level (e.g.,DEBUG,INFO,WARNING,ERROR).
Run the script from the command line:
python script.py- Place your card images in the
Importdirectory. - Run the script using the command above.
- The script will process each image, identify the card details, and move the image to the
Sorteddirectory under a categorized subdirectory.
For an image named example_card.jpg with card name "Pikachu", set name "Base Set", and TCG name "Pokemon":
- The image will be moved to
Sorted/Pokemon/and renamed toPikachu - Base Set.jpg.
The script logs all actions and errors to log.txt. Check this file for detailed information on the script's operations and any issues encountered.
- Missing API Key: Ensure your
tcg.cfgfile contains a valid API key. - Invalid Aliases: Ensure alias pairs are correctly formatted in the
tcg.cfgfile. - File Permissions: Ensure the script has the necessary permissions to read and write files in the specified directories.
For further assistance, refer to the OpenAI documentation or the error logs generated by the script.