Lines 1-84
Link Here
|
1 |
--- ripit.pl.orig Mon May 22 15:27:36 2000 |
1 |
--- ripit-orig.pl Sun Sep 23 14:12:08 2001 |
2 |
+++ ripit.pl Sun Sep 24 03:38:07 2000 |
2 |
+++ ripit.pl Sun Sep 23 14:12:09 2001 |
3 |
@@ -15,25 +15,32 @@ |
3 |
@@ -9,41 +9,43 @@ |
4 |
# --bitrate [rate] - Encode MP3 at this bitrate |
4 |
# Create an M3U file |
|
|
5 |
# |
6 |
# Options: |
7 |
-# [start_track] - rips from this track to last track |
8 |
-# --halt - powers off the machine when finished |
9 |
-# if your configuration supports it |
10 |
-# --bitrate [rate] - Encode MP3 at this bitrate |
11 |
+# [start_track] - rips from this track to last track |
12 |
+# --halt - powers off the machine when finished |
13 |
+# if your configuration supports it |
14 |
+# --bitrate [rate] - Encode MP3 at this bitrate |
5 |
# --year [year] - Tag MP3 with this year (included as CDDB |
15 |
# --year [year] - Tag MP3 with this year (included as CDDB |
6 |
# does not store this information) |
16 |
# does not store this information) |
7 |
-# --device - CDROM device to rip from |
17 |
-# --genre [genre] - Overrides CDDB genre, e.g. rock,funk |
8 |
+# --device - CDROM device to rip from |
18 |
-# --device [device] - CDROM device to rip from |
9 |
+# --numcpu - Number of parrallel encoders to run |
19 |
+# --genre [genre] - Overrides CDDB genre, e.g. rock,funk |
10 |
+# --outputdir - Directory in which to place MP3s |
20 |
+# --device [device] - CDROM device to rip from |
11 |
+# --cdripper - Which cdripper to use |
21 |
# --encopt [options] - Parameters to pass to encoder |
12 |
+# --encoder - Which encoder to use |
22 |
# --encoder [encoder] - Encoder to use, see below |
13 |
# |
23 |
# --cdripper [ripper] - Cdripper to use, see below |
14 |
# Version 1.8 22/05/00 - Simon Quinn |
24 |
# --cdopt [options] - Parameters to pass to cdripper |
15 |
# |
25 |
# --outputdir [dir] - Where MP3s should go |
16 |
# Usage: ripit.pl [--halt] [--bitrate rate] |
26 |
+# --numcpu [cpus] - Number of parallel encoders to run |
17 |
-# [--year year] [--device cddevice] [start_track] |
27 |
# |
18 |
+# [--year year] [--device cddevice] [--numcpu cpus] |
28 |
# Version 2.0 20/08/01 - Simon Quinn |
19 |
+# [--outputdir dir] [--cdripper ripper] [--encoder encoder] |
29 |
# |
20 |
+# [start_track] |
30 |
# Usage: ripit.pl [--halt] [--bitrate rate] [--year year] [--genre genre] |
|
|
31 |
-# [--device cddevice] [--encopt options] [--encoder encoder] |
32 |
+# [--device cddevice] [--encopt options] [--encoder encoder] |
33 |
# [--cdripper cdripper] [--cdopt options] [--outputdir dir] |
34 |
-# [start_track] |
35 |
+# [--numcpu cpus] [start_track] |
21 |
#################################################################### |
36 |
#################################################################### |
22 |
# |
37 |
# |
23 |
# User configurable variables |
38 |
# User configurable variables |
24 |
# |
39 |
# |
25 |
|
40 |
|
26 |
$cddev = "/dev/cdrom"; # CD Audio device |
41 |
$cddev = "/dev/cdrom"; # CD Audio device |
27 |
-$outputdir = "/dosc/cdrip/"; # Where the MP3s should go |
42 |
-$outputdir = "/tmp/cdrip/"; # Where the MP3s should go, |
28 |
+$outputdir = "/dosc/cdrip"; # Where the MP3s should go |
43 |
+$outputdir = "/tmp/cdrip/"; # Where the MP3s should go, |
|
|
44 |
# must have trailing / |
29 |
$bitrate = 160; # Bitrate for MP3s |
45 |
$bitrate = 160; # Bitrate for MP3s |
30 |
$encoder = 1; # 0 - Bladeenc, 1 - Lame, 2 - Gogo |
46 |
-$encoder = 0; # 0 - Lame, 1 - OggVorbis |
|
|
47 |
+$encoder = 0; # 0 - Lame, 1 - Gogo, 2 - OggVorbis |
31 |
$encopt = ""; # options for mp3 encoder |
48 |
$encopt = ""; # options for mp3 encoder |
32 |
$cdripper = 0; # 0 - cdparanoia, 1 - cdda2wav, |
49 |
$cdripper = 0; # 0 - dagrab, |
33 |
- # 2 - tosha, 3 - cdd |
50 |
# 1 - cdparanoia, 2 - cdda2wav, |
34 |
+ # 2 - tosha, 3 - cdd, 4 - dagrab |
51 |
# 3 - tosha, 4 - cdd |
35 |
$cdopt = ""; # options for cdaudio ripper |
52 |
$cdopt = ""; # options for cdaudio ripper |
36 |
+$numcpu = 1; # Number of parallel encoders to run |
53 |
+$numcpu = 1; # Number of parallel encoders to run |
37 |
|
54 |
|
38 |
$use_underscore = 0; # Use _ instead of spaces in filenames (1 yes, 0 no) |
55 |
$CDDB_HOST = "freedb.freedb.org"; # set cddb host |
39 |
|
56 |
$CDDB_PORT = 8880; # set cddb port |
40 |
@@ -53,6 +60,9 @@ |
57 |
@@ -77,6 +79,9 @@ |
41 |
require "flush.pl"; |
58 |
$nocddbinfo = 1; # Assume no CDDB info exists |
42 |
use Getopt::Long; |
59 |
$trackselection = ""; # Passed from command line |
43 |
|
60 |
|
44 |
+$ripper_died = 0; |
61 |
+$ripper_died = 0; |
45 |
+$SIG{HUP} = \&catch_hup; |
62 |
+$SIG{HUP} = \$catch_hup; |
46 |
+ |
63 |
+ |
47 |
# Initialise global variables |
64 |
#################################################### |
48 |
# |
65 |
# Do the following: |
49 |
$year = ""; # Year of Audio CD - written to MP3 tag |
66 |
# 1. Get command line parameters |
50 |
@@ -75,9 +85,19 @@ |
67 |
@@ -98,11 +103,16 @@ |
51 |
if ( ! &GetOptions("halt" => \$haltonfinish, |
68 |
"encoder=i" => \$encoder, |
52 |
"bitrate=i" => \$bitrate, |
69 |
"cdripper=i" => \$cdripper, |
53 |
"year=i" => \$year, |
70 |
"cdopt=s" => \$cdopt, |
54 |
- "device=s" => \$cddev) ) { |
71 |
- "outputdir=s" => \$outputdir ) ) { |
55 |
+ "device=s" => \$cddev, |
72 |
- print "Usage: ripit.pl [--halt] [--bitrate rate] [--year year] |
56 |
+ "numcpu=i" => \$numcpu, |
|
|
57 |
+ "outputdir=s" => \$outputdir, |
73 |
+ "outputdir=s" => \$outputdir, |
58 |
+ "cdripper=i" => \$cdripper, |
74 |
+ "numcpu=i" => \$numcpu ) ) { |
59 |
+ "cdopt=s" => \$cdopt, |
75 |
+ print " |
60 |
+ "encoder=i" => \$encoder, |
76 |
+Usage: ripit.pl [--halt] [--bitrate rate] [--year year] |
61 |
+ "encopt=s" => \$encopt) ) { |
77 |
[--device cddevice] [--encopt options] [--encoder encoder] |
62 |
print "Usage: ripit.pl [--halt] [--bitrate rate] [--year year] |
78 |
[--cdripper cdripper] [--cdopt options] [--outputdir dir] |
63 |
- [--device cddevice] [start_track]\n"; |
79 |
- [start_track]\n"; |
64 |
+ [--device cddevice] [--numcpu cpus] [--outputdir dir] |
80 |
+ [--numcpu cpus] [start_track] |
65 |
+ [--cdripper cdripper] [--encoder encoder] [start_track] |
81 |
+Rippers: 0 - dagrab, 1 - cdparanoia, 2 - cdda2wav, 3 - tosha, 4 - cdd |
66 |
+ CD Rippers: 0 - cdparanoia, 1 - cdda2wav, 2 - tosha, 3 - cdd, 4 - dagrab |
82 |
+Encoders: 0 - Lame, 1 - Gogo, 2 - OggVorbis |
67 |
+ Encoders: 0 - Bladeenc, 1 - Lame, 2 - Gogo\n"; |
83 |
+"; |
68 |
+ |
|
|
69 |
exit 1; |
84 |
exit 1; |
70 |
} |
85 |
} |
71 |
|
86 |
|
72 |
@@ -113,7 +133,7 @@ |
87 |
@@ -132,8 +142,8 @@ |
|
|
88 |
&create_dirs(); # Create directories MP3 files |
73 |
&rip_cd(); # Rip, Encode & Tag |
89 |
&rip_cd(); # Rip, Encode & Tag |
74 |
|
90 |
|
75 |
print "Waiting for MP3 Encoder to finish...\n"; |
91 |
-print "Waiting for MP3 Encoder to finish...\n"; |
76 |
-wait; |
92 |
-wait; |
77 |
+while (wait != -1) {}; |
93 |
+print "Waiting for MP3 Encoder(s) to finish...\n"; |
|
|
94 |
+while (wait != -1) {}; |
78 |
|
95 |
|
79 |
&create_m3u(); # Create the M3U file for the MP3 files |
96 |
&create_m3u(); # Create the M3U file for the MP3 files |
80 |
|
97 |
|
81 |
@@ -137,6 +157,10 @@ |
98 |
@@ -157,6 +167,10 @@ |
82 |
|
99 |
|
83 |
exit; |
100 |
exit; |
84 |
|
101 |
|
Lines 89-104
Link Here
|
89 |
# |
106 |
# |
90 |
# Create the track selection from the parameters passed |
107 |
# Create the track selection from the parameters passed |
91 |
# on the command line |
108 |
# on the command line |
92 |
@@ -286,7 +310,7 @@ |
109 |
@@ -336,31 +350,37 @@ |
93 |
# Directory created will be: /outputdir/Artist - Album/ |
|
|
94 |
# The value must end in / |
95 |
|
96 |
- $mp3dir = $outputdir.$artist." - ".$album."/"; |
97 |
+ $mp3dir = $outputdir."/".$artist." - ".$album."/"; |
98 |
|
99 |
if ($use_underscore == 1) { $mp3dir =~ s/ /_/g; } |
100 |
|
101 |
@@ -340,24 +364,29 @@ |
102 |
$riptrackname = &get_trackname($_, $tracklist[$_ - 1]); |
110 |
$riptrackname = &get_trackname($_, $tracklist[$_ - 1]); |
103 |
$riptrackno = $_; |
111 |
$riptrackno = $_; |
104 |
|
112 |
|
Lines 108-173
Link Here
|
108 |
|
116 |
|
109 |
# Choose the cdaudio ripper to use |
117 |
# Choose the cdaudio ripper to use |
110 |
if ($cdripper == 0) { |
118 |
if ($cdripper == 0) { |
|
|
119 |
if (system("dagrab -d $cddev -v $cdopt -f \"$riptrackname.rip\" $riptrackno")) { |
120 |
- &printflush(RIPLOG,"cdparanoia failed on $tracklist[$_ - 1]\n"); |
121 |
+ &printflush(RIPLOG,"dagrab failed on $tracklist[$_ - 1]\n"); |
122 |
+ kill 1, @encoders; |
123 |
die "dagrab failed on $tracklist[$_ - 1]"; |
124 |
} |
125 |
} |
126 |
elsif ($cdripper == 1) { |
111 |
if (system("cdparanoia -d $cddev $cdopt $riptrackno \"$riptrackname.rip\"")) { |
127 |
if (system("cdparanoia -d $cddev $cdopt $riptrackno \"$riptrackname.rip\"")) { |
112 |
&printflush(RIPLOG,"cdparanoia failed on $tracklist[$_ - 1]\n"); |
128 |
&printflush(RIPLOG,"cdparanoia failed on $tracklist[$_ - 1]\n"); |
113 |
+ kill 1, @encoders; |
129 |
+ kill 1, @encoders; |
114 |
die "cdparanoia failed on $tracklist[$_ - 1]"; |
130 |
die "cdparanoia failed on $tracklist[$_ - 1]"; |
115 |
} |
131 |
} |
116 |
} |
132 |
} |
117 |
elsif ($cdripper == 1) { |
133 |
elsif ($cdripper == 2) { |
118 |
- if (system("cdda2wav -D $cddev -Q -H $cdopt -t $riptrackno \"$riptrackname.rip\"")) { |
134 |
- if (system("cdda2wav -D $cddev -Q -H $cdopt -t $riptrackno \"$riptrackname.rip\"")) { |
119 |
+ if (system("cdda2wav -D $cddev -q -Q -H $cdopt -t $riptrackno - > \"$riptrackname.rip\"")) { |
135 |
+ if (system("cdda2wav -D $cddev -q -Q -H $cdopt -t $riptrackno \"$riptrackname.rip\"")) { |
120 |
&printflush(RIPLOG,"cdda2wav failed on $tracklist[$_ - 1]\n"); |
136 |
&printflush(RIPLOG,"cdda2wav failed on $tracklist[$_ - 1]\n"); |
121 |
+ kill 1, @encoders; |
137 |
+ kill 1, @encoders; |
122 |
die "cdda2wav failed on $tracklist[$_ - 1]"; |
138 |
die "cdda2wav failed on $tracklist[$_ - 1]"; |
123 |
} |
139 |
} |
124 |
} |
140 |
} |
125 |
elsif ($cdripper == 2) { |
141 |
elsif ($cdripper == 3) { |
126 |
if (system("tosha -d $cddev -f wav -t $riptrackno -o \"$riptrackname.rip\"")) { |
142 |
if (system("tosha -d $cddev -f wav -t $riptrackno -o \"$riptrackname.rip\"")) { |
127 |
&printflush(RIPLOG,"tosha failed on $tracklist[$_ - 1]\n"); |
143 |
- &printflush(RIPLOG,"tosha failed on $tracklist[$_ - 1]\n"); |
128 |
+ kill 1, @encoders; |
144 |
- die "tosha failed on $tracklist[$_ - 1]"; |
129 |
die "tosha failed on $tracklist[$_ - 1]"; |
145 |
+ &printflush(RIPLOG,"tosha failed on $tracklist[$_ - 1]\n"); |
|
|
146 |
+ kill 1, @encoders; |
147 |
+ die "tosha failed on $tracklist[$_ - 1]"; |
130 |
} |
148 |
} |
131 |
} |
149 |
} |
132 |
@@ -370,6 +399,13 @@ |
150 |
elsif ($cdripper == 4) { |
|
|
151 |
@@ -369,6 +389,7 @@ |
152 |
$cdd_dev =~ s/c$//; |
153 |
if (system("cdd -t $riptrackno -q -f $cdd_dev - 2>/dev/null | sox -t cdr -x - \"$riptrackname.rip\"")) { |
154 |
&printflush(RIPLOG,"cdd failed on $tracklist[$_ - 1]\n"); |
155 |
+ kill 1, @encoders; |
133 |
die "cdd failed on $tracklist[$_ - 1]"; |
156 |
die "cdd failed on $tracklist[$_ - 1]"; |
134 |
} |
157 |
} |
135 |
} |
158 |
} |
136 |
+ elsif ($cdripper == 4) { |
159 |
@@ -381,11 +402,13 @@ |
137 |
+ if (system("dagrab -d $cddev -f \"$riptrackname.rip\" $riptrackno")) { |
|
|
138 |
+ &printflush(RIPLOG,"dagrab failed on $tracklist[$_ - 1]\n"); |
139 |
+ kill 1, @encoders; |
140 |
+ die "dagrab failed on $tracklist[$_ - 1]"; |
141 |
+ } |
142 |
+ } |
143 |
else { |
144 |
die "No CD Ripper defined"; |
145 |
} |
146 |
@@ -379,11 +415,13 @@ |
147 |
rename "$riptrackname.rip","$riptrackname.wav"; |
160 |
rename "$riptrackname.rip","$riptrackname.wav"; |
148 |
|
161 |
|
149 |
&printflush(RIPLOG,"Rip complete $tracklist[$_ - 1]\n"); |
162 |
&printflush(RIPLOG,"Rip complete $tracklist[$_ - 1]\n"); |
150 |
+ } |
163 |
+ } |
151 |
|
164 |
|
152 |
# Start the Encoder in the background. but only once |
165 |
- # Start the Encoder in the background. but only once |
153 |
- if ($startenc == 0) { |
166 |
- if ($startenc == 0) { |
154 |
- $startenc = 1; |
167 |
- $startenc = 1; |
155 |
- unless (fork) { &enc_cd(); } |
168 |
- unless (fork) { &enc_cd(); } |
|
|
169 |
+ # Start the Encoder in the background. but only once per CPU |
156 |
+ if ($startenc < $numcpu) { |
170 |
+ if ($startenc < $numcpu) { |
157 |
+ sleep $startenc*5; |
171 |
+ sleep $startenc * 5; |
158 |
+ $startenc = $startenc + 1; |
172 |
+ $startenc = $startenc + 1; |
159 |
+ unless ($encoders[$startenc]=fork) { &enc_cd(); } |
173 |
+ unless ($encoders[$startenc]=fork) { &enc_cd(); } |
160 |
} |
174 |
} |
161 |
|
175 |
|
162 |
} |
176 |
} |
163 |
@@ -399,24 +437,25 @@ |
177 |
@@ -407,25 +430,33 @@ |
164 |
sub enc_cd { |
178 |
$riptrackno = $_; |
165 |
my($i,$x,$ncount,$enc); |
|
|
166 |
|
167 |
- |
168 |
foreach (@seltrack) { |
169 |
|
170 |
$riptrackname = &get_trackname($_, $tracklist[$_ - 1]); |
171 |
$ncount++; |
179 |
$ncount++; |
172 |
|
180 |
|
173 |
- print "\nMP3 Encoding track ".$ncount." of ".($#seltrack + 1)."\n"; |
181 |
- print "\nMP3 Encoding track ".$ncount." of ".($#seltrack + 1)."\n"; |
Lines 180-186
Link Here
|
180 |
+ while( ! -r "$riptrackname.wav" && ! -r "$riptrackname.mp3" ){ |
188 |
+ while( ! -r "$riptrackname.wav" && ! -r "$riptrackname.mp3" ){ |
181 |
$x++; |
189 |
$x++; |
182 |
if ($x > 179) { die "MP3 encoder waited 30 minutes before giving up"; } |
190 |
if ($x > 179) { die "MP3 encoder waited 30 minutes before giving up"; } |
183 |
+ if ($ripper_died) { die "CD Ripper seems to have died - exiting"; } |
191 |
+ if ($ripper_died) { die "CD Ripper seems to have died - exiting"; } |
184 |
sleep 10; |
192 |
sleep 10; |
185 |
} |
193 |
} |
186 |
|
194 |
|
Lines 190-220
Link Here
|
190 |
+ |
198 |
+ |
191 |
# Set the encoder we are going to use |
199 |
# Set the encoder we are going to use |
192 |
if ($encoder == 0) { |
200 |
if ($encoder == 0) { |
193 |
$enc = "bladeenc $encopt -QUIT -$bitrate \"$riptrackname.wav\" "; |
201 |
$enc = "lame $encopt -S -b $bitrate --tt \"$tracklist[$_ - 1]\" --ta \"$artist\" --tl \"$album\" --ty \"$year\" --tg \"$genre\" --tn $riptrackno --add-id3v2 \"$riptrackname.wav\" \"$riptrackname.mp3\""; |
194 |
@@ -427,6 +466,9 @@ |
202 |
} |
195 |
elsif ($encoder == 2) { |
203 |
elsif ($encoder == 1) { |
196 |
$enc = "gogo \"$riptrackname.wav\" \"$riptrackname.mp3\" $encopt -b $bitrate"; |
204 |
+ $enc = "gogo \"$riptrackname.wav\" \"$riptrackname.mp3\" $encopt -b $bitrate"; |
|
|
205 |
+ } |
206 |
+ elsif ($encoder == 2) { |
207 |
$enc = "oggenc $encopt -b $bitrate -t \"$tracklist[$_ - 1]\" -a \"$artist\" -l \"$album\" -d \"$year\" -N $riptrackno -o \"$riptrackname.ogg\" \"$riptrackname.wav\""; |
197 |
} |
208 |
} |
198 |
+ else { |
209 |
+ else { |
199 |
+ die "No Encoder defined"; |
210 |
+ die "No encoder defined"; |
200 |
+ } |
211 |
+ } |
201 |
|
212 |
|
202 |
if ( ! system("$enc >$enclog 2>&1 </dev/null")) { |
213 |
if ( ! system("$enc >$enclog 2>&1 </dev/null")) { |
203 |
|
214 |
|
204 |
@@ -443,6 +485,7 @@ |
215 |
@@ -438,7 +469,8 @@ |
205 |
&printflush(RIPLOG,"MP3 Encoder Failed on $tracklist[$_ - 1]\n"); |
216 |
&printflush(RIPLOG,"MP3 Encoder Failed on $tracklist[$_ - 1]\n"); |
206 |
die "MP3 Encoder Failed on $tracklist[$_ - 1]"; |
217 |
die "MP3 Encoder Failed on $tracklist[$_ - 1]"; |
207 |
} |
218 |
} |
|
|
219 |
- |
208 |
+ } |
220 |
+ } |
209 |
|
221 |
+ |
210 |
} |
222 |
} |
211 |
exit ; |
223 |
exit ; |
212 |
@@ -457,7 +500,7 @@ |
224 |
} |
|
|
225 |
@@ -452,10 +484,10 @@ |
213 |
$file="$artist.m3u"; |
226 |
$file="$artist.m3u"; |
214 |
if ($use_underscore == 1) { $file =~ s/ /_/g; } |
227 |
if ($use_underscore == 1) { $file =~ s/ /_/g; } |
215 |
|
228 |
|
216 |
- system("cd \"$mp3dir\" ; ls -rt *.mp3 >\"$file\""); |
229 |
- if($encoder == 1) { |
217 |
+ system("cd \"$mp3dir\" ; ls *.mp3 | sort >\"$file\""); |
230 |
- system("cd \"$mp3dir\" ; ls -rt *.ogg >\"$file\""); |
|
|
231 |
+ if($encoder == 2) { |
232 |
+ system("cd \"$mp3dir\" ; ls *.ogg | sort >\"$file\""); |
233 |
} |
234 |
else { |
235 |
- system("cd \"$mp3dir\" ; ls -rt *.mp3 >\"$file\""); |
236 |
+ system("cd \"$mp3dir\" ; ls *.mp3 | sort >\"$file\""); |
237 |
} |
218 |
} |
238 |
} |
219 |
|
|
|
220 |
# Writes the MP3 tag to the file. The standard is to use the |