dct
is a Python package designed for processing ICC JSON files in a variety of ways.
NOTE:
To use dct
, you need to provide a configuration YAML file.
Sample config.yaml with all parameters with sample values: config.yaml.
There is also a sample config with all parameters that you can copy in config example section.
See the usage
, configuration parameters
and config examples
sections below to get detailed explanations.
- Downloading
dct
without Installing - Installing
- Usage
- Configuration Parameters
- Config Examples (non-exhaustive list)
Download the corresponding executable for you platform from Latest Github Release
For windows: grab the dct_windows.exe binary file from above release link.
For linux: grab the dct_linux binary file from above release link.
Make sure that the binary file has permission to be executable.
Windows: Double click to run. Give path where your configuration files are, select the one you want to use.
Make sure you give double \\
in paths instead of single \
if you are changing INPUT_DIRECTORY
or OUTPUT_DIRECTORY
in the configuration files.
Correct:
D:\\my awesome folder\\subfolder of downloads\\cyoa tools
Incorrect: D:\my awesome folder\subfolder of downloads\cyoa tools
Linux:
Binaries/scripts many times are not executable in linux due to insufficient permission. run this command to give executing permission to binary:
chmod +x path/to/the/downloaded/dct_linux
After doing this you can run the binary with this command in terminal:
./dct_linux
Give path where your configuration files are, select the one you want to use.
As dct
is a python package that uses poetry for package build/dependency/install, you can easily install it yourself by cloning the repo and running the commands below.
Requirements for installing : Python 3.12 or higher, Git (for cloning, or you can download the repo manually), poetry (for installing the package and its dependencies).
git clone https://github.com/DelicateIntegral/dct.git
cd dct
poetry install
As pip can directly install a project with pyproject.toml since the release of pip version 21.3, which supports PEP 660, you can also do the following to install dct
:
git clone https://github.com/DelicateIntegral/dct.git
pip install dct/.
OR if you don't want to clone repo separately first, just install with pip directly like this (you still need git installed):
# general format : pip install git+https://github.com/DelicateIntegral/dct.git@[branch or release tag]
pip install git+https://github.com/DelicateIntegral/[email protected]
The above command clones the git repo to temp location, checkouts the tag (branch if branch name given instead of tag name like above) and then installs the dependencies and dct
.
Note: It is recommended to create virtual environment and install the package in that to not effect or mess up the global python in your system. You can search the internet on how to create venv and activate it or see it in the install scripts (mentioned below) before using installation methods command.
To make the install process easier and also create launch script with desktop shortcuts, there are install scripts present in the repo.
Windows: install.bat
Linux: install.sh
Script will ask you to enter the Install_Path
and will do this steps if path provided is valid and exists:
- It will create a venv named
cyoaenv
in%USERPROFILE%\python\env\
for windows OR$HOME/python/env/
for linux, and activate this environment - It will run the
poetry install
command - It will create launch script named
launch-dct.bat
(for windows) ORlaunch-dct.sh
(for linux) in path:INSTALL_PATH/dct
. - It will then create desktop shortcut and start menu shortcut for this launch script.
If you are insterested in building the binaries yourself, you can check the build.yml that is used in Github Actions to generate binaries.
NOTE: It is recommended to install the package with poetry or install script as pyinstaller
can behave or give errors in different environments.
You can skip this if you are not interested in using the dct
from terminal/cmd with custom config path and name without using the manual selection mode that was added in v0.6.6
.
Running with config parameter in terminal:
# if you are using the python package directly in terminal (assuming you have already activated environment if you use one)
dct --config="path/to/your/custom.yaml"
Below listed are the valid parameters that you can define in the config file.
Details about parameters:
INPUT_DIRECTORY
: Optional.The directory path where the JSON file (PROJECT_FILE
) is stored. Default is current working directory which the tool calculates programtically if this config option is disabled or not given.OUTPUT_DIRECTORY
: Optional.The directory path where the output JSON (OUTPUT_FILE
) will be stored, and where theIMAGE_FOLDER
for downloaded images will reside. Default is current working directory which the tool calculates programtically if this config option is disabled or not given.PROCESS_DISCORD_LINKS
: Optional. If set toTrue
, it will process Discord links present in the JSON. Default isFalse
. IfDOWNLOAD_IMAGES
isTrue
, it will download images toIMAGE_FOLDER
and update links like this:IMAGE_FOLDER/image_name
. Otherwise, it will just refresh URLs and replace old ones.TOKEN
: Optional but required ifPROCESS_DISCORD_LINKS
isTrue
. Default isYOUR TOKEN
. Your Discord bot token required for authentication with Discord's API.PROJECT_FILE
: Optional. Default isproject.json
. The name of the input ICC JSON file containing Discord links.OUTPUT_FILE
: Optional. Default isproject_new.json
. The name of the output JSON file where updated ICC JSON data will be saved.IMAGE_FOLDER
: Optional. Default isimages
. The name of the folder where downloaded images will be stored.CONVERT_IMAGES
: Optional. Default isFalse
.IMAGE_QUALITY
: Optional. Default is90
. The image quality of the webp images saved inIMAGE_FOLDER
. Value between 0-100.CONVERT_IMAGES
should beTrue
for this to be taken into account.IMAGE_FORMAT
: Optional. Default isWEBP
.CONVERT_IMAGES
should beTrue
for this to be taken into account.UPDATE_PREFIXES
: Optional. Default isFalse
. If set toTrue
, it will update image URLs by replacingOLD_PREFIX
withNEW_PREFIX
. Helpful if you have some folder of images in a server with constant prefix and you moved that folder to another server.OLD_PREFIX
: Optional. Default is""
. The old prefix to replace in image URLs. When it is not blank, only those urls which contain theOLD_PREFIX
are changed toNEW_PREFIX
.NEW_PREFIX
: Optional. Default is""
. The new prefix to prepend to updated image URLs. Leave blank if you are uploadingIMAGE_FOLDER
to Neocities or GitHub in the same directory asindex.html
.MINIFY
: Optional. Default isFalse
. Set toTrue
to minify the output JSON file.RATE_LIMIT
: Optional. Default is2
. The maximum number of concurrent requests allowed for Discord URL refresh operations. Recommended to skip this option in the config and leave it at default value.BASE64_TO_IMAGE
: Optional. Default isFalse
. If set toTrue
, it will process base64 encoded images in the JSON, converting them to webp and storing toIMAGE_FOLDER
and updating links like this:IMAGE_FOLDER/image_name
. You can provideNEW_PREFIX
and setUPDATE_PREFIXES
toTrue
to update links to this:NEW_PREFIX/IMAGE_FOLDER/image_name
.DOWNLOAD_IMAGES
: Optional. Default isFalse
. If set toTrue
, it will download images linked in the JSON toIMAGE_FOLDER
and updating links like this:IMAGE_FOLDER/image_name
. You can provideNEW_PREFIX
and setUPDATE_PREFIXES
toTrue
to update links to this:NEW_PREFIX/IMAGE_FOLDER/image_name
.OVERWRITE_IMAGES
: Optional. Default isFalse
. If set toTrue
, it will overwrite existing images inIMAGE_FOLDER
otherwise skip pre-existing webp images.DISABLE_IMAGES
: Optional. Default isFalse
. If set toTrue
, it will disable all images in "image" (backgrounds etc are not affected) in the JSON and exit.DOWNLOAD_RATE_LIMIT
: Optional. Default is5
. The maximum number of concurrent requests allowed when downloading images. Recommended to keep below10
.IMAGE_TO_BASE64
: Optional. Default isFalse
. If set toTrue
, it will scan theIMAGE_FOLDER
for images and convert them to base64 and add them to the json only for those choice ids whose corresponding image is found.SHOW_CONFIG
: Optional. Default isFalse
. If set toTrue
, it will show all the config parameters with their values which the program will be using.PROJECT_URL
: Optional. Default is empty. If it is non-empty, the program will download the json file data and use it instead ofPROJECT_FILE
. NOTE: You have to give full url with json file included in the url like this:https://examplesitethatdoesnotexist.org/sldkfjlskjdf/lkjflskjflkj/mycyoa/customproject.json
SESSION_TIMEOUT
: Optional. Default value is600
. This is amount of seconds for total session when downloading.LOG_FILE
: Optional. Default value isdct_log
. Name of the log file that is written in theOUTPUT_DIRECTORY
.
INPUT_DIRECTORY
andOUTPUT_DIRECTORY
(The program continues after this.)PROJECT_FILE
orPROJECT_URL
(The program continues after this.)OUTPUT_FILE
(The program continues after this.)DISABLES_IMAGES
(The program exits after processing this.)IMAGE_FOLDER
(The program continues after this.)PROCESS_DISCORD_LINKS
(Uses these parameters:DOWNLOAD_IMAGES, TOKEN, OVERWRITE_IMAGES, RATE_LIMIT, IMAGE_FOLDER, IMAGE_QUALITY, DOWNLOAD_RATE_LIMIT, IMAGE_FORMAT, CONVERT_IMAGES
) (The program continues after this.)TOKEN
(uses:RATE_LIMIT
)DOWNLOAD_IMAGES
(uses:OVERWRITE_IMAGES, IMAGE_FOLDER, DOWNLOAD_RATE_LIMIT, CONVERT_IMAGES
(CONVERT_IMAGES
usesIMAGE_QUALITY, IMAGE_FORMAT
))
BASE64_TO_IMAGE
(Uses these parameters:IMAGE_FOLDER, IMAGE_QUALITY, OVERWRITE_IMAGES, IMAGE_FORMAT, CONVERT_IMAGES
) (The program continues after this.)DOWNLOAD_IMAGES
(This parameter is processed again as it downloads the other image urls that are not discord in this step. Uses these parameters:IMAGE_QUALITY, IMAGE_FOLDER, OVERWRITE_IMAGES, DOWNLOAD_RATE_LIMIT, IMAGE_FORMAT, CONVERT_IMAGES
) (The program continues after this.)IMAGE_TO_BASE64
(Will be skipped ifBASE64_TO_IMAGE
is also on and will show you a warning while skipping. Uses these parameters:IMAGE_FOLDER, OUTPUT_PATH, MINIFY
) (The program exits after processing this parameter, if it is skipped, the program continues.)UPDATE_PREFIXES
(Uses these parameters:NEW_PREFIX, OLD_PREFIX
) (The program exits after processing this parameter.)- IF nothing left the program exits.
This priority helps in deciding the combinations of tasks that you can do together. Any task combinations would work correctly if the parameters that exit the program are the lowest priority or if nothing left to do.
Sample Config with all parameters:
# BELOW ALL PARAMETERS ARE IN ENABLED STATE
# COMMENT PARAMETERS (PUT # BEFORE THEM) TO DISABLE THEM
# IF YOU WANT PARAMETERS TO HAVE DEFAULT VALUES, KEEP THEM DISABLED
# Values in INPUT_DIRECTORY and OUTPUT_DIRECTORY are just placeholders, actual current working directory will only be calculated if you keep them disabled.
# -----------------CONFIGURATION PARAMETERS (TOTAL 25)----------------
INPUT_DIRECTORY: "Current Working Directory"
OUTPUT_DIRECTORY: "Current Working Directory"
PROCESS_DISCORD_LINKS: False
TOKEN: "YOUR TOKEN"
PROJECT_FILE: "project.json"
PROJECT_URL: ""
OUTPUT_FILE: "project_new.json"
IMAGE_FOLDER: "images"
CONVERT_IMAGES: False
IMAGE_QUALITY: 90
IMAGE_FORMAT: "WEBP"
UPDATE_PREFIXES: False
OLD_PREFIX: ""
NEW_PREFIX: ""
MINIFY: False
RATE_LIMIT: 2
BASE64_TO_IMAGE: False
DOWNLOAD_IMAGES: False
OVERWRITE_IMAGES: False
DISABLE_IMAGES: False
SHOW_CONFIG: False
DOWNLOAD_RATE_LIMIT: 5
IMAGE_TO_BASE64: False
SESSION_TIMEOUT: int = 600
LOG_FILE: str = "dct_log"
Below are some config examples given for some of the tasks that dct
can do:
(All these examples don't have all parameters which indicates that the parameters that are not-defined/commented/disabled will automatically get default values)
-
You want to process discord urls so that the json has refreshed discord urls. Change the value of token with your actual BOT TOKEN. You can see this link to understand how to get discord BOT TOKEN: Getting BOT TOKEN
PROCESS_DISCORD_LINKS: True TOKEN: "example discord bot token string"
-
You want to convert the urls (other than discord) to local links and download images in a folder with a custom name
CyoaImages
for the folder.IMAGE_FOLDER: "CyoaImages" DOWNLOAD_IMAGES: True
-
You want to convert all urls (including discord) like in point 2.
PROCESS_DISCORD_LINKS: True TOKEN: "example discord bot token string" IMAGE_FOLDER: "CyoaImages" DOWNLOAD_IMAGES: True
-
You want to disable all images (base64, local linked, urls).
DISABLE_IMAGES: True
-
You want to convert base64 embedded images to local links and download them like in step 2.
IMAGE_FOLDER: "CyoaImages" BASE64_TO_IMAGE: True
-
You want to convert local links to new urls. Let's say you have folder
CyoaImages
in a server with url :https://example.com/alsdkfjklsd/lksdfj/CyoaImages
.NEW_PREFIX: "https://example.com/alsdkfjklsd/lksdfj/" UPDATE_PREFIXES: True
-
You already have urls in json but you want to move the image folder to new server.
OLD_PREFIX: "https://oldexample.com/oldalkdjfkajf/oldflakjdflkf/lsllk/" NEW_PREFIX: "https://example.com/alsdkfjklsd/lksdfj/" UPDATE_PREFIXES: True
You can also combine some tasks with each other like below (see the Priority order in Configuration Parameters to get idea on how to create valid combination of tasks):
Note: Colors may vary due to terminal color settings.