2020-10-02 07:55:56 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# AUTHOR: gotbletu (@gmail|twitter|youtube|github|lbry)
|
2021-03-18 09:32:04 +00:00
|
|
|
# https://www.youtube.com/user/gotbletu
|
2020-10-02 07:55:56 +00:00
|
|
|
|
|
|
|
# files extension to create initial new directory and m3u
|
2021-03-18 21:08:55 +00:00
|
|
|
EXT_INT="cue|gdi|chd|pbp|iso|dsk"
|
2020-10-02 07:55:56 +00:00
|
|
|
|
|
|
|
# BIN/CUE - Cue sheets files
|
|
|
|
# ISO - Standard ISO image files
|
|
|
|
# CCD/SUB/IMG/CUE - CloneCD image files
|
|
|
|
# IMG - Raw Disk Image File
|
|
|
|
# MDF/MDS - Media Descriptor File
|
|
|
|
# PBP - Playstation Portable files
|
|
|
|
# BIN/CUE/SBI - PAL copy protected games need a SBI Subchannel file (for PSX)
|
|
|
|
# GDI/BIN - Sega Dreamcast GD-ROM disc
|
|
|
|
# M3U - Playlist file
|
|
|
|
|
|
|
|
helpmsg() {
|
|
|
|
printf "%s\n" "desc: create m3u playlist for multi disc games [$EXT_INT]"
|
|
|
|
printf "%s\n" " e.g playstation, pc engine cd/turbografx cd, panasonic 3do,"
|
|
|
|
printf "%s\n" " sega dreamcast, sega saturn, sega cd/mega cd, ...etc"
|
|
|
|
printf "%s\n" "demo: https://youtu.be/Ye5cxCDB3yo"
|
|
|
|
printf "%s\n" "depend: coreutils findutils sed"
|
|
|
|
printf "\n"
|
|
|
|
printf "%s\n" "usage: ${0##*/} [options]"
|
|
|
|
printf "\n"
|
|
|
|
printf "%s\n" "options:"
|
|
|
|
printf "%s\n" " -d, --dir create directory and m3u playlist"
|
|
|
|
printf "%s\n" " from"
|
|
|
|
printf "%s\n" " Novastorm (USA) (Disc 1).bin"
|
|
|
|
printf "%s\n" " Novastorm (USA) (Disc 1).cue"
|
|
|
|
printf "%s\n" " Novastorm (USA) (Disc 2).bin"
|
|
|
|
printf "%s\n" " Novastorm (USA) (Disc 2).cue"
|
|
|
|
printf "%s\n" " Metal Gear Solid (USA) (Disc 1) (Rev 1).chd"
|
|
|
|
printf "%s\n" " Metal Gear Solid (USA) (Disc 2) (Rev 1).chd"
|
|
|
|
printf "%s\n" " to"
|
|
|
|
printf "%s\n" " Novastorm (USA).m3u"
|
|
|
|
printf "%s\n" " Metal Gear Solid (USA) (Rev 1).m3u"
|
|
|
|
printf "%s\n" " /Novastorm (USA)/Novastorm (USA) (Disc 1).bin"
|
|
|
|
printf "%s\n" " /Novastorm (USA)/Novastorm (USA) (Disc 1).cue"
|
|
|
|
printf "%s\n" " /Novastorm (USA)/Novastorm (USA) (Disc 2).bin"
|
|
|
|
printf "%s\n" " /Novastorm (USA)/Novastorm (USA) (Disc 2).cue"
|
|
|
|
printf "%s\n" " /Metal Gear Solid (USA) (Rev 1)/Metal Gear Solid (USA) (Disc 1) (Rev 1).chd"
|
|
|
|
printf "%s\n" " /Metal Gear Solid (USA) (Rev 1)/Metal Gear Solid (USA) (Disc 2) (Rev 1).chd"
|
|
|
|
printf "\n"
|
|
|
|
printf "%s\n" " -m, --m3u create m3u playlist only"
|
|
|
|
printf "%s\n" " from"
|
|
|
|
printf "%s\n" " Heart of Darkness (USA) (Disc 1).bin"
|
|
|
|
printf "%s\n" " Heart of Darkness (USA) (Disc 1).cue"
|
|
|
|
printf "%s\n" " Heart of Darkness (USA) (Disc 2).bin"
|
|
|
|
printf "%s\n" " Heart of Darkness (USA) (Disc 2).cue"
|
|
|
|
printf "%s\n" " Lunar 2 - Eternal Blue Complete (USA) (Disc 1).chd"
|
|
|
|
printf "%s\n" " Lunar 2 - Eternal Blue Complete (USA) (Disc 2).chd"
|
|
|
|
printf "%s\n" " Lunar 2 - Eternal Blue Complete (USA) (Disc 3).chd"
|
|
|
|
printf "%s\n" " to"
|
|
|
|
printf "%s\n" " Heart of Darkness (USA).m3u"
|
|
|
|
printf "%s\n" " Lunar 2 - Eternal Blue Complete (USA).m3u"
|
|
|
|
printf "\n"
|
|
|
|
printf "%s\n" " -h, --help display this help message"
|
|
|
|
printf "\n"
|
|
|
|
printf "%s\n" "Swap Disc: Retroarch > [Load Your Game] > Quick Menu > Disc Control"
|
|
|
|
}
|
|
|
|
if [ $# -lt 1 ]; then
|
|
|
|
helpmsg
|
|
|
|
exit 1
|
|
|
|
elif [ "$1" = -h ] || [ "$1" = --help ]; then
|
|
|
|
helpmsg
|
|
|
|
exit 0
|
|
|
|
elif [ "$1" = -d ] || [ "$1" = --dir ]; then
|
|
|
|
### TYPE 1: TitleOfGame (USA) (Disc 1).chd
|
|
|
|
#---------------------------------------------------------------------------------
|
2021-03-18 21:08:55 +00:00
|
|
|
find . -maxdepth 1 ! -iname '*.m3u' -type f -iname "*(Disc 1).*[$EXT_INT]" | while read -r line
|
2020-10-02 07:55:56 +00:00
|
|
|
do
|
|
|
|
# create new directory
|
|
|
|
# Heart of Darkness (USA) (Disc 1).chd --> Heart of Darkness (USA)
|
|
|
|
DIR_NAME="$(echo "${line%.*}" | sed 's@./@@g' | sed 's@ (Disc 1)@@g')"
|
|
|
|
DISC_NAME="$(echo "${line%.*}" | sed 's@./@@g' | sed 's@(Disc 1)@(Disc ?)@g')"
|
|
|
|
mkdir -vp "$DIR_NAME"
|
|
|
|
find . -maxdepth 1 ! -iname '*.m3u' -type f -iname "$DISC_NAME.*" -exec mv -n -- '{}' "$DIR_NAME" \;
|
|
|
|
# create m3u playlist
|
|
|
|
# /Heart of Darkness (USA)/Heart of Darkness (USA) (Disc 1).chd
|
|
|
|
# /Heart of Darkness (USA)/Heart of Darkness (USA) (Disc 2).chd
|
2021-03-18 21:08:55 +00:00
|
|
|
find "$DIR_NAME" ! -iname '*.m3u' -type f -iname "*.*[$EXT_INT]" | sed -e 's/^/\//' | sort > "$DIR_NAME".m3u
|
2020-10-02 07:55:56 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
### TYPE 2: AnotherTitleOfGame (USA) (Disc 1) (Rev 2).chd
|
|
|
|
#---------------------------------------------------------------------------------
|
2021-03-18 21:08:55 +00:00
|
|
|
find . -maxdepth 1 ! -iname '*.m3u' -type f -iname "*(Disc 1) *.*[$EXT_INT]" | while read -r line
|
2020-10-02 07:55:56 +00:00
|
|
|
do
|
|
|
|
# create new directory
|
|
|
|
# Metal Gear Solid (USA) (Disc 1) (Rev 1).chd --> Metal Gear Solid (USA) (Rev 1)
|
|
|
|
DIR_NAME="$(echo "${line%.*}" | sed 's@./@@g' | sed 's@ (Disc 1)@@g')"
|
|
|
|
DISC_NAME="$(echo "${line%.*}" | sed 's@./@@g' | sed 's@(Disc 1)@(Disc ?)@g')"
|
|
|
|
mkdir -vp "$DIR_NAME"
|
|
|
|
# move matching files to directory
|
|
|
|
find . -maxdepth 1 ! -iname '*.m3u' -type f -iname "$DISC_NAME.*" -exec mv -n -- '{}' "$DIR_NAME" \;
|
|
|
|
# create m3u playlist
|
|
|
|
# /Metal Gear Solid (USA) (Rev 1)/Metal Gear Solid (USA) (Disc 1) (Rev 1).chd
|
|
|
|
# /Metal Gear Solid (USA) (Rev 1)/Metal Gear Solid (USA) (Disc 2) (Rev 1).chd
|
2021-03-18 09:32:04 +00:00
|
|
|
# find "$DIR_NAME" -type f -iname "*.*[cue|gdi|chd|iso|pbp]" | sed -e 's/^/\//' | sort > "$DIR_NAME".m3u
|
2021-03-18 21:08:55 +00:00
|
|
|
find "$DIR_NAME" ! -iname '*.m3u' -type f -iname "*.*[$EXT_INT]" | sed -e 's/^/\//' | sort > "$DIR_NAME".m3u
|
2020-10-02 07:55:56 +00:00
|
|
|
done
|
2021-03-18 21:08:55 +00:00
|
|
|
|
|
|
|
### TYPE 3: AmstradMSXTitleOfGame (19xx)(Developer)(Disc 1 of 3).dsk
|
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
find . -maxdepth 1 ! -iname '*.m3u' -type f -iname "*(Disc 1 of ?).*[$EXT_INT]" | while read -r line
|
|
|
|
do
|
|
|
|
DIR_NAME="$(echo "${line%.*}" | sed 's@./@@g' | sed 's@(Disc 1 of .*)@@g')"
|
|
|
|
DISC_NAME="$(echo "${line%.*}" | sed 's@./@@g' | sed 's@(Disc 1 of .*)@@g')"
|
|
|
|
mkdir -vp "$DIR_NAME"
|
|
|
|
find . -maxdepth 1 ! -iname '*.m3u' -type f -iname "$DISC_NAME*.*" -exec mv -n -- '{}' "$DIR_NAME" \;
|
|
|
|
# create m3u playlist
|
|
|
|
# /Game (19xx)(Developer)/Game (19xx)(Developer)(Disc 1 of 3).dsk
|
|
|
|
# /Game (19xx)(Developer)/Game (19xx)(Developer)(Disc 2 of 3)(Data A).dsk
|
|
|
|
# /Game (19xx)(Developer)/Game (19xx)(Developer)(Disc 2 of 3)(Data B).dsk
|
|
|
|
find "$DIR_NAME" ! -iname '*.m3u' -type f -iname "*.*[$EXT_INT]" | sed -e 's/^/\//' | sort > "$DIR_NAME".m3u
|
|
|
|
done
|
|
|
|
|
2020-10-02 07:55:56 +00:00
|
|
|
elif [ "$1" = -m ] || [ "$1" = --m3u ]; then
|
|
|
|
### METHOD A: TitleOfGame (USA) (Disc 1).cue
|
|
|
|
#---------------------------------------------------------------------------------
|
2021-03-18 21:08:55 +00:00
|
|
|
find . -maxdepth 1 ! -iname '*.m3u' -type f -iname "*(Disc 1).*[$EXT_INT]" | while read -r line
|
2020-10-02 07:55:56 +00:00
|
|
|
do
|
|
|
|
# Heart of Darkness (USA) (Disc 1).chd --> Heart of Darkness (USA).m3u
|
|
|
|
FILE_NAME="$(echo "${line%.*}" | sed 's@./@@g' | sed 's@ (Disc 1)@@g')"
|
|
|
|
DISC_NAME="$(echo "${line%.*}" | sed 's@./@@g' | sed 's@(Disc 1)@(Disc ?)@g')"
|
2021-03-18 21:08:55 +00:00
|
|
|
find . -maxdepth 1 ! -iname '*.m3u' -type f -iname "$DISC_NAME.*[$EXT_INT]" | sed 's@./@@g' | sort > "$FILE_NAME".m3u
|
2020-10-02 07:55:56 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
### METHOD B: AnotherTitleOfGame (USA) (Disc 1) (Rev 2).cue
|
|
|
|
#---------------------------------------------------------------------------------
|
2021-03-18 21:08:55 +00:00
|
|
|
find . -maxdepth 1 ! -iname '*.m3u' -type f -iname "*(Disc 1) *.*[$EXT_INT]" | while read -r line
|
2020-10-02 07:55:56 +00:00
|
|
|
do
|
|
|
|
# Metal Gear Solid (USA) (Disc 1) (Rev 1).chd --> Metal Gear Solid (USA) (Rev 1).m3u
|
|
|
|
FILE_NAME="$(echo "${line%.*}" | sed 's@./@@g' | sed 's@ (Disc 1)@@g')"
|
|
|
|
DISC_NAME="$(echo "${line%.*}" | sed 's@./@@g' | sed 's@(Disc 1)@(Disc ?)@g')"
|
2021-03-18 21:08:55 +00:00
|
|
|
find . -maxdepth 1 ! -iname '*.m3u' -type f -iname "$DISC_NAME.*[$EXT_INT]" | sed 's@./@@g' | sort > "$FILE_NAME".m3u
|
|
|
|
done
|
|
|
|
|
|
|
|
### METHOD C: AmstradMSXTitleOfGame (19xx)(Developer)(Disc 1 of 3).dsk
|
|
|
|
# Game (19xx)(Developer)(Disc 1 of 3).dsk
|
|
|
|
# Game (19xx)(Developer)(Disc 2 of 3)(Data A).dsk
|
|
|
|
# Game (19xx)(Developer)(Disc 2 of 3)(Data B).dsk
|
|
|
|
# Game (19xx)(Developer).m3u
|
|
|
|
#---------------------------------------------------------------------------------
|
|
|
|
find . -maxdepth 1 ! -iname '*.m3u' -type f -iname "*(Disc 1 of ?).*[$EXT_INT]" | while read -r line
|
|
|
|
do
|
|
|
|
FILE_NAME="$(echo "${line%.*}" | sed 's@./@@g' | sed 's@(Disc 1 of .*)@@g')"
|
|
|
|
DISC_NAME="$(echo "${line%.*}" | sed 's@./@@g' | sed 's@(Disc 1 of .*)@@g')"
|
|
|
|
find . -maxdepth 1 ! -iname '*.m3u' -type f -iname "$DISC_NAME*.*[$EXT_INT]" | sed 's@./@@g' | sort > "$FILE_NAME".m3u
|
2020-10-02 07:55:56 +00:00
|
|
|
done
|
|
|
|
fi
|