Last active
April 10, 2022 21:04
-
-
Save J-Swift/052cf3142395ad40d5573408079ad0fb to your computer and use it in GitHub Desktop.
Helper to batch convert redump psx bin/cue to chd
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
function _do_next_chd_print_header() { | |
local -r text="${1}" | |
echo | |
echo '################################################################################' | |
echo "# ${text}" | |
echo '################################################################################' | |
echo | |
} | |
function _do_next_chd_notify_completion() { | |
echo "Done." | |
} | |
function _do_next_chd_remove_dir() { | |
local -r chd_path="${1}" | |
local -r dir_path="$( echo "${chd_path}" | sed 's/\.cue\.chd//' )" | |
local -r base_dir_path="$( basename "${dir_path}" )" | |
local -r multi_disc_dir_path="$( echo "${chd_path}" | sed 's/\.cue\.chd//' | sed -E 's/ \(Disc [1-5]\)//' )" | |
local -r multi_disc_full_path="${multi_disc_dir_path}/${base_dir_path}" | |
if [ -d "${dir_path}" ]; then | |
echo "REMOVING: ${dir_path}" | |
rm -rf "${dir_path}" | |
elif [ -d "${multi_disc_full_path}" ]; then | |
echo "REMOVING: ${multi_disc_full_path}" | |
rm -rf "${multi_disc_full_path}" | |
if [ ! "$(ls -A "${multi_disc_dir_path}")" ]; then | |
echo "REMOVING EMPTY DIR: ${multi_disc_dir_path}" | |
rm -rf "${multi_disc_dir_path}" | |
fi | |
fi | |
} | |
function do_next_chd() { | |
local -r num_to_do=${1:-50} | |
local -r mount_point="/Volumes/media/raspi_roms_mount/psx" | |
local -r chdman_cmd=/Users/jimmy/bin/chdman_v5_mame0211 | |
_do_next_chd_print_header 'Converting' | |
find "${mount_point}" -name "*.cue" | head -$num_to_do | tr "\n" "\0" | xargs -0 -I {} sh -c '$0 createcd -f -i "${1}" -o "${1}".chd; echo --------------' $chdman_cmd "{}" | |
_do_next_chd_notify_completion | |
_do_next_chd_print_header 'Moving' | |
find "${mount_point}" -name "*.cue.chd" -print0 | xargs -0 -I {} mv $( basename {} ) "${mount_point}"/ | |
_do_next_chd_notify_completion | |
_do_next_chd_print_header 'Removing old directories' | |
export -f _do_next_chd_remove_dir | |
find "${mount_point}" -name "*.cue.chd" -print0 | xargs -0 -I {} sh -c '_do_next_chd_remove_dir "{}"' | |
_do_next_chd_notify_completion | |
_do_next_chd_print_header 'Renaming' | |
rename 's/.cue.chd/.chd/' "${mount_point}"/*.cue.chd | |
_do_next_chd_notify_completion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment