-
Notifications
You must be signed in to change notification settings - Fork 0
/
psxrip.sh
executable file
·222 lines (191 loc) · 5.93 KB
/
psxrip.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/env bash
#
# This is a script to create a .bin image with corresponding .cue out of your
# PSX game discs as backup and/or for usage with emulators.
#
# Run-time requirements: cdrdao
#
# This script is partly based upon the "wesnoth-optipng" script from the
# Battle for Wesnoth team.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or,
# at your option any later version. This program is distributed in the
# hope that it will be useful, but WITHOUT ANY WARRANTY.
CONFIG_FILE="${HOME}/.config/psxrip.conf"
PSXDIR="${HOME}/psxrip"
DRIVE="/dev/cdrom"
SUBCHAN=true
USE_RAW_DRIVER=false
SLOWRIP=true
UMOUNT=true
EJECT_ON_DONE=true
########################
### Support Function ###
########################
report_absent_tool()
{
echo "$1 is not present in PATH. $(basename ${0}) requires it in order to work properly."
if [ -n "$2" ]; then
echo "You can obtain $1 at <${2}>."
fi
exit -1
}
print_help()
{
cat << EOSTREAM
Script for ripping PSX game discs into .bin files with corresponding .cue files.
Usage:
$(basename ${0}) [{--outputdir} <value>] [{--drive} <value>] [--disable-subchan] [--use-raw-driver] [{--help|-h}] [--slow-rip] ][filename]
The parameter [filename] is mandatory. Without it, the script will abort. Plain
spaces in the filename are prohibited!
Available switches:
--drive Define the device to be used. If this parameter is not
provided, /dev/cdrom will be used.
--help / -h Displays this help text.
--disable-subchan Don't extract subchannel data. Subchannel data might be
required for some PSX copy protection though it *could* create
problems. Retry with this parameter set if any problems occur
when trying to use the resulting image.
--outputdir Define the folder in which the resulting image should be saved.
If the folder does not exist, it will be created. If no
--outputdir parameter is given, the folder ~/psxrip will be
used.
--enable-fast-rip Runs CD-ROM reader at full speed to get a faster rip but lower
quality
(Not Recommended)
--use-raw-driver Uses generic-mmc-raw instead of generic-mmc:0x20000 driver
(Not Recommended) Here for legacy reasons.
--disable-umount Disables automatic unmount of mounted DRIVE if mount is detected.
--disable-eject Disables CD-ROM eject on a successful rip
This tool requires cdrdao (http://cdrdao.sourceforge.net/) to be installed and
available in PATH.
EOSTREAM
}
### Get min CD-Rom read speed ###
function get-cdr-min-speed {
CDROM_MIN_SPEED=$(CDR_DEVICE=${DRIVE} wodim -prcap |egrep 'Current[[:space:]]+read[[:space:]]+'|sed -r 's/^.*CD[[:space:]]+([[:digit:]]+)x.*$/\1/')
echo $CDROM_MIN_SPEED
return 0
}
if [ -e "${HOME}/.config/psxrip" ] ; then
source "${CONFIG_FILE}"
fi
# go through provided parameters
while [ "${1}" != "" ]; do
if [ "${1}" = "--drive" ]; then
DRIVE=$2
shift 2
elif [ "${1}" = "--outputdir" ]; then
PSXDIR=$2
shift 2
elif [ "${1}" = "--disable-subchan" ]; then
SUBCHAN="false"
shift 1
elif [ "${1}" = "--help" ] || [ "${1}" = "-h" ]; then
print_help
exit 0
elif [ "${1}" = "--enable-fast-rip" ] ; then
SLOWRIP=false
shift 1
elif [ "${1}" = "--use-raw-driver" ] ; then
USE_RAW_DRIVER=true
shift 1
elif [ "${1}" = "--disable-umount" ] ; then
UMOUNT=false
shift
elif [ "${1}" = "--disable-eject" ] ; then
EJECT_ON_DONE=false
shift 1
elif [ "${2}" != "" ] ; then
echo "ERROR: Inval id usage. Displaying help:"
echo ""
print_help
exit -1
else
IMAGENAME=$1
shift
fi
done
#input checking
if [ ! -e "${DRIVE}" ] ; then
echo "Optical drive ${DRIVE} not found" 1>&2
exit 2
fi
# check for required dependencies
which cdrdao &> /dev/null ||
report_absent_tool cdrdao 'http://cdrdao.sourceforge.net/'
# output recognized parameters
echo "Program "$(basename ${0})" called. The following parameters will be used for"
echo "creating an image of a PSX disc:"
echo "Folder for saving images: "$PSXDIR
echo "Drive used for reading the image: "$DRIVE
echo "Resulting filenames: "$PSXDIR"/"$IMAGENAME"[.bin|.cue]"
if [ "$NOSUBCHAN" = "true" ]; then
echo "Not extracting subchan data."
else
echo "Extracting subchan data."
fi
echo ""
# check if imagename is defined
if [ "$IMAGENAME" = "" ]; then
echo "ERROR: Invalid usage. Found no name for resulting image. Displaying help:"
echo ""
print_help
exit -1
fi
# create dir for resulting image if it does not exist yet
if ! [ -d "$PSXDIR" ]; then
echo "outputdir not found, creating folder: "$PSXDIR
echo ""
mkdir -p $PSXDIR
if [ $? -ne 0 ] ; then
echo "Failed to create ${PSXDIR}" 1>&2
exit 2
fi
fi
# Check device mount status
mount|egrep --quiet "${DRIVE}\ on"
if [ $? -eq 0 ] ; then
if ($UMOUNT) ; then
umount "${DRIVE}"
if [ $? -eq 0 ] ; then
echo "Unmounted ${DRIVE}"
else
echo "Failed to unmount ${DRIVE}" 1>&2
exit 2
fi
else
echo "${DRIVE} is mounted. Please unmount." 1>&2
exit 2
fi
fi
echo "starting ripping the disc"
echo ""
# final commandline for reading the disc and creating the image
if [ "$SUBCHAN" = "true" ]; then
SUBCHANSTR='--read-subchan rw_raw'
fi
if ($SLOWRIP) ; then
CDR_SPEED=2
READ_SPEED_STR="--rspeed ${CDR_SPEED}"
echo "Setting CD-ROM drive to slow speed (${CDR_SPEED}x) for ripping"
fi
if ($USE_RAW_DRIVER) ; then
DRIVER="generic-mmc-raw"
else
DRIVER="generic-mmc:0x20000"
fi
cdrdao read-cd -v 3 $READ_SPEED_STR --read-raw --datafile "$PSXDIR/$IMAGENAME.bin" --device "$DRIVE" --driver "$DRIVER" ${SUBCHANSTR} "$PSXDIR/$IMAGENAME.toc"
if [ $? -ne 0 ] ; then
echo "Failed to dump PSX image" 1>&2
exit 2
fi
echo "Generating CUE file"
toc2cue "$PSXDIR/$IMAGENAME.toc" "$PSXDIR/$IMAGENAME.cue"
if [ $? -ne 0 ] ; then
echo "Failed to convert toc to cue" 1>&2
exit 2
fi
($EJECT_ON_DONE) && eject "${DRIVE}"
exit 0