Last active
October 18, 2022 07:09
-
-
Save manero6/418f9232919f2e29d640cd4758ebb4e1 to your computer and use it in GitHub Desktop.
Create .m3u playlist for multi-disc games (unzip .bin/.cue, create .chd files, create .m3u playlist)
This file contains hidden or 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
#!/bin/bash | |
IFS=$'\n' | |
ARGUMENTS=$# | |
GAME_ZIP="$1" | |
GAME_NOZIP="${GAME_ZIP%.zip}" | |
GAME_NODISC="${GAME_NOZIP% *isc*}" | |
GAME_DIR=$GAME_NODISC | |
DISC=1 | |
ctrl_c () { | |
echo -e "\n\e[1;31mAborting.\e[0m" | |
exit 130 | |
} | |
check_arguments () { | |
if [ $ARGUMENTS = 1 ] | |
then | |
if [[ "$GAME_ZIP" == *.zip ]] | |
then | |
echo -e "\e[1mGame file:\e[0m" | |
echo "=> $GAME_ZIP" | |
else | |
echo -e "\e[1;31mPlease provide a .zip file. Aborting.\e[0m" | |
exit 1 | |
fi | |
elif [ $ARGUMENTS = 0 ] | |
then | |
echo -e "\e[1;31mPlease provide one .zip file. Aborting.\e[0m" | |
exit 1 | |
else | |
echo -e "\e[1;31mPlease provide no more than one .zip file. Aborting.\e[0m" | |
exit 1 | |
fi | |
} | |
get_games () { | |
echo -e "\e[1mRelated files:\e[0m" | |
for i in $GAME_NODISC*.zip | |
do | |
echo "=> Disc $DISC: \"$i\"" | |
((DISC++)) | |
GAMES+=("$i") | |
GAMES_NOZIP+=("${i%.zip}") | |
done | |
} | |
make_dir () { | |
if [ ! -d "$GAME_DIR" ] | |
then | |
echo -e "\e[1mCreating \"$GAME_DIR\" folder:\e[0m" | |
mkdir "$GAME_DIR" && \ | |
printf "=> " && realpath $GAME_DIR | |
else | |
echo -e "\e[1;31mDirectory \"$GAME_DIR\" already exist. Aborting.\e[0m" | |
exit 1 | |
fi | |
} | |
extract_zip () { | |
echo -e "\e[1mExtracting .zip files into \"$GAME_DIR\":\e[0m" | |
for i in ${GAMES[@]} | |
do | |
echo "=> Extracting \"$i\"" | |
7z x "$i" -o$GAME_DIR 1>/dev/null | |
done | |
} | |
create_chd () { | |
echo -e "\e[1mCreating .chd files:\e[0m" | |
for i in ${GAMES_NOZIP[@]} | |
do | |
echo "=> Creating \"$i.chd\"" | |
chdman createcd -i $GAME_DIR/$i.cue -o $GAME_DIR/$i.chd 1>/dev/null | |
done | |
} | |
create_m3u () { | |
echo -e "\e[1mCreating .m3u playlist:\e[0m" | |
for i in ${GAMES_NOZIP[@]} | |
do | |
echo "=> Appending \"$i.chd\"" | |
echo $i.chd >> $GAME_DIR/$GAME_NODISC.m3u | |
done | |
} | |
cleanup () { | |
echo -e "\e[1mRemoving .bin and .cue files:\e[0m" | |
for i in ${GAMES_NOZIP[@]} | |
do | |
echo "=> Removing \"$i.bin\"" | |
if rm $GAME_DIR/$i.bin 2>/dev/null | |
then | |
: | |
else | |
echo -e "\e[1;31mNo \"$i.bin\" found!\e[0m" | |
echo -e "\e[1mRemoving other .bin files:\e[0m" | |
for games in $GAME_DIR/*.bin | |
do | |
game=`basename $games` | |
echo -e "=> Removing \"$game\"" | |
rm $games | |
done | |
fi | |
echo "=> Removing \"$i.cue\"" | |
rm $GAME_DIR/$i.cue | |
done | |
} | |
main () { | |
trap ctrl_c SIGINT | |
check_arguments | |
get_games | |
for i in make_dir \ | |
extract_zip \ | |
create_chd \ | |
create_m3u \ | |
cleanup | |
do | |
if $i | |
then | |
echo -e "\e[1;32m=> Done\e[0m" | |
else | |
echo -e "\n\e[1;31mAborting\e[0m" | |
exit 1 | |
fi | |
done | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Before:
After:
Usage: