Last active
August 1, 2020 05:19
-
-
Save Sanaki/0c3c114e9fe3e4499deb16978e74c9ec to your computer and use it in GitHub Desktop.
CD-type chd extractor (V5 only, supports clones)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
declare -A parents | |
function getparents { | |
for i in *.chd; do | |
if [[ "$(xxd -ps -s 104 -l 20 "$i")" = "0000000000000000000000000000000000000000" ]]; then | |
parents["$(xxd -ps -s 84 -l 20 "$i")"]="$i" | |
fi | |
done | |
} | |
for chdFile in *.chd; do | |
[[ $chdFile = '*.chd' ]] && echo "No chd files exist in the current directory" && break | |
# If first track is CHGD, extraction type should be gdi | |
parenthash=$(xxd -ps -s 104 -l 20 "$chdFile") | |
[[ $(xxd -ps -s 124 -l 4 "$chdFile") = "43484744" ]] && ext=".gdi" || ext=".cue" | |
game="${chdFile%.chd}" | |
echo "Extracting $game..." | |
if [[ $parenthash = "0000000000000000000000000000000000000000" ]]; then | |
# No parent, thus can be extracted directly | |
chdman extractcd -i "$chdFile" -o "$game$ext" | |
else | |
# Has parent, run getparents if the parents array is empty | |
[[ ${#x[@]} -eq 0 ]] && getparents | |
chdver=$(xxd -ps -s 12 -l 4 "$chdFile") | |
[[ chdver -ne 5 ]] && echo "Currently only CHD v5 is supported" && continue | |
# Bail if parent wasn't located | |
if [[ ${parents[$parenthash]} ]]; then | |
chdman extractcd -i "$chdFile" -ip "${parents[$parenthash]}" -o "$game$ext" | |
else | |
echo "**Cannot extract, parent was not found**" | |
fi | |
fi | |
echo | |
done | |
echo "All done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment