Skip to content

lloydsmart/chdtool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

189 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

License Release ShellCheck

๐ŸŽฎ chdtool

A robust Bash script for converting CD/DVD disc images and archives into CHD (Compressed Hunks of Data) format using chdman.

Designed for batch processing, validation, logging, and multi-disc handling โ€” ideal for emulation libraries.


Convert everything in a directory:

./chdtool.sh -r /path/to/roms

โœจ Features

  • ๐Ÿ“ฆ Supports common input formats:
    • Archives: zip, rar, 7z
    • Disc images: iso, cue, gdi, ccd
  • ๐Ÿ”„ Automatic extraction of archives before conversion
  • ๐Ÿ’ฟ Intelligent CD vs DVD detection (createcd vs createdvd)
  • โœ… Verification of CHDs using chdman verify
    • Automatic retry on failure
    • Deletes invalid CHDs
  • ๐Ÿ“‰ Space savings reporting
  • ๐Ÿงพ Automatic M3U generation for multi-disc sets
  • ๐Ÿงน Safe temp directory handling with cleanup traps
  • ๐Ÿงช Dry-run mode (no changes made)
  • ๐Ÿชต Structured logging system:
    • Console / file / syslog / journald
    • Configurable verbosity
  • โšก Progress bar (TTY-aware, non-spammy)

๐Ÿš€ Usage

./chdtool.sh [options] <input directory>

Options

Option Description
-k, --keep-originals Do not delete source files after conversion
-r, --recursive Process subdirectories
-n, --dry-run Show what would happen without making changes
-F, --file-tee Force logging to file
-N, --no-file-tee Disable logging to file

๐Ÿ“ Example

./chdtool.sh -r /mnt/roms

Dry run:

./chdtool.sh -n /mnt/roms

๐Ÿ“ฆ Supported Input Formats

Disc images

  • .iso
  • .cue (with referenced BIN/WAV/MP3 validation)
  • .gdi
  • .ccd

Archives

  • .zip
  • .rar
  • .7z

Archives are extracted to a temporary directory and processed automatically.


๐Ÿ’ฟ Output

  • CHDs are created alongside the input files
  • Temporary files use .tmp suffix until verified
  • Originals are removed unless --keep-originals is set

๐Ÿงพ Multi-disc Support

  • Automatically detects disc numbering patterns:
    • Disc 1, CD2, Part 3, Side A, 1 of 2, etc.
  • Generates .m3u playlists when 2+ discs are detected
  • Filenames are sanitized for cross-platform compatibility

Example:

Final Fantasy VII (Disc 1).chd
Final Fantasy VII (Disc 2).chd
Final Fantasy VII.m3u

๐Ÿ” Verification

  • All CHDs are verified with chdman verify
  • Failed verification:
    • Retried once
    • Deleted if still invalid
  • Existing CHDs are verified before skipping conversion

๐Ÿชต Logging

Configurable via environment variables:

LOG_DEST=auto|console|file|syslog|journald
LOG_LEVEL_THRESHOLD=DEBUG|INFO|WARN|ERROR
LOG_TEE_CONSOLE=auto|1|0
LOG_TEE_FILE=1|0
LOG_TAG=chdtool

Default log file:

logs/chd_conversion_<timestamp>.log

๐Ÿ“Š Output Summary

At the end of a run:

  • Total original size
  • Total CHD size
  • Space saved
  • Archives processed
  • CHDs created
  • Failures
  • Elapsed time

โš™๏ธ Requirements

The following tools must be installed:

  • chdman
  • unzip
  • unrar
  • 7z
  • stat
  • awk

Optional (enhancements):

  • file (better ISO detection)
  • perl (improved filename parsing)
  • uconv (Unicode normalization)
  • systemd-cat / logger (logging backends)

๐Ÿงช Dry Run Mode

Use --dry-run to preview actions:

./chdtool.sh -n /roms
  • No files are created, moved, or deleted
  • All intended operations are logged

โš ๏ธ Notes

  • DVD support requires a version of chdman with createdvd
  • CUE files referencing missing files will fail validation
  • Temporary files are cleaned automatically, even on interruption

๐Ÿ› ๏ธ Design Goals

  • Safe by default (verify before replace)
  • Idempotent (re-runs donโ€™t duplicate work)
  • Transparent logging
  • Minimal dependencies
  • Works well on large ROM collections

๐Ÿ“Œ Future Ideas

  • Parallel processing
  • Better metadata integration
  • Optional compression tuning
  • Integration with tools like Retromount / ROM managers

About

A Bash script that converts CD/DVD disc images (ZIP/RAR/7Z/ISO/CUE/GDI/CCD) into CHD using chdman.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors