Fixed up the ripping process as well as progress reporting. Made progress
reporting work for the cdparanoia ripper. git-svn-id: https://samskivert.googlecode.com/svn/trunk@37 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: CDParanoiaRipper.java,v 1.4 2000/12/10 07:01:24 mdb Exp $
|
// $Id: CDParanoiaRipper.java,v 1.5 2001/02/06 08:18:00 mdb Exp $
|
||||||
|
|
||||||
package robodj.convert;
|
package robodj.convert;
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ public class CDParanoiaRipper implements Ripper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ripTrack (int index, String target,
|
public void ripTrack (TrackInfo[] info, int index, String target,
|
||||||
ConversionProgressListener listener)
|
ConversionProgressListener listener)
|
||||||
throws ConvertException
|
throws ConvertException
|
||||||
{
|
{
|
||||||
@@ -116,6 +116,14 @@ public class CDParanoiaRipper implements Ripper
|
|||||||
cmd.append(" ").append(index); // add track number
|
cmd.append(" ").append(index); // add track number
|
||||||
cmd.append(" ").append(target); // add output file name
|
cmd.append(" ").append(target); // add output file name
|
||||||
|
|
||||||
|
// we'll need this for later
|
||||||
|
RE regex;
|
||||||
|
try {
|
||||||
|
regex = new RE("^##: -?\\d+ \\[(\\S+)\\] @ (\\d+)");
|
||||||
|
} catch (REException ree) {
|
||||||
|
throw new ConvertException("Can't compile regexp?! " + ree);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// fork off a cdparanoia process to read the TOC
|
// fork off a cdparanoia process to read the TOC
|
||||||
Runtime rt = Runtime.getRuntime();
|
Runtime rt = Runtime.getRuntime();
|
||||||
@@ -125,9 +133,41 @@ public class CDParanoiaRipper implements Ripper
|
|||||||
BufferedInputStream bin = new BufferedInputStream(in);
|
BufferedInputStream bin = new BufferedInputStream(in);
|
||||||
DataInputStream din = new DataInputStream(bin);
|
DataInputStream din = new DataInputStream(bin);
|
||||||
|
|
||||||
// read output from the subprocess and chuck it for now
|
// read output from the subprocess
|
||||||
while (din.readLine() != null) {
|
String out;
|
||||||
// la la la
|
|
||||||
|
// figure out what our progress boundaries are
|
||||||
|
long tstart = info[index-1].offset * MAGIC_FACTOR;
|
||||||
|
long tlength = info[index-1].length * MAGIC_FACTOR;
|
||||||
|
int lastReported = 0;
|
||||||
|
|
||||||
|
while ((out = din.readLine()) != null) {
|
||||||
|
// if they don't care about the output then neither do we
|
||||||
|
if (listener == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse the output
|
||||||
|
REMatch match = regex.getMatch(out);
|
||||||
|
if (match != null) {
|
||||||
|
String action = match.toString(1);
|
||||||
|
long offset = -1L;
|
||||||
|
try {
|
||||||
|
offset = Long.parseLong(match.toString(2));
|
||||||
|
} catch (NumberFormatException nfe) {
|
||||||
|
// System.err.println("Malformed position info: " + out);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int pctDone = (int)(100 * (offset - tstart) / tlength);
|
||||||
|
if (pctDone - lastReported >= 1) {
|
||||||
|
listener.updateProgress(pctDone);
|
||||||
|
lastReported = pctDone;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// System.out.println("Couldn't match: " + out);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check the return value of the process
|
// check the return value of the process
|
||||||
@@ -146,9 +186,15 @@ public class CDParanoiaRipper implements Ripper
|
|||||||
"ripper process to exit.");
|
"ripper process to exit.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if everything was successful, report completion
|
||||||
|
listener.updateProgress(100);
|
||||||
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new ConvertException(
|
throw new ConvertException(
|
||||||
"Error communicating with ripper:\n" + ioe);
|
"Error communicating with ripper:\n" + ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cdparanoia reports length in sectors and progress in
|
||||||
|
protected static final int MAGIC_FACTOR = 1176;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: ConversionProgressListener.java,v 1.1 2000/10/30 22:21:11 mdb Exp $
|
// $Id: ConversionProgressListener.java,v 1.2 2001/02/06 08:18:00 mdb Exp $
|
||||||
|
|
||||||
package robodj.convert;
|
package robodj.convert;
|
||||||
|
|
||||||
@@ -18,5 +18,5 @@ public interface ConversionProgressListener
|
|||||||
* herein will be mapped to a global progress indication by the
|
* herein will be mapped to a global progress indication by the
|
||||||
* calling software (in the case of converting an entire CD).
|
* calling software (in the case of converting an entire CD).
|
||||||
*/
|
*/
|
||||||
public void updateProgress (float percentComplete);
|
public void updateProgress (int percentComplete);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: RipTest.java,v 1.2 2000/10/30 22:21:11 mdb Exp $
|
// $Id: RipTest.java,v 1.3 2001/02/06 08:18:00 mdb Exp $
|
||||||
|
|
||||||
package robodj.convert;
|
package robodj.convert;
|
||||||
|
|
||||||
@@ -79,8 +79,26 @@ public class RipTest
|
|||||||
System.out.println("Matched no tracks?!");
|
System.out.println("Matched no tracks?!");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// finally try the CDDB lookup
|
// try the CDDB lookup
|
||||||
lookupCDDB("us.cddb.com", info);
|
lookupCDDB("us.cddb.com", info);
|
||||||
|
|
||||||
|
// rip a track, for fun
|
||||||
|
int track = 2;
|
||||||
|
System.out.println("Ripping track " + track +
|
||||||
|
" [" + info[track-1].offset +
|
||||||
|
", " + info[track-1].length + "]...");
|
||||||
|
|
||||||
|
// report our progress
|
||||||
|
ConversionProgressListener listener =
|
||||||
|
new ConversionProgressListener() {
|
||||||
|
public void updateProgress (int percentDone)
|
||||||
|
{
|
||||||
|
System.out.println("Percent done: " +
|
||||||
|
percentDone + "%");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ripper.ripTrack(info, track, "/tmp/track" + track + ".wav",
|
||||||
|
listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: Ripper.java,v 1.2 2000/10/30 22:21:11 mdb Exp $
|
// $Id: Ripper.java,v 1.3 2001/02/06 08:18:00 mdb Exp $
|
||||||
|
|
||||||
package robodj.convert;
|
package robodj.convert;
|
||||||
|
|
||||||
@@ -46,6 +46,8 @@ public interface Ripper
|
|||||||
* notification, it should communicate it to the supplied progress
|
* notification, it should communicate it to the supplied progress
|
||||||
* listener. The track should be ripped in WAV format.
|
* listener. The track should be ripped in WAV format.
|
||||||
*
|
*
|
||||||
|
* @param info the track info as returned by
|
||||||
|
* <code>getTrackInfo</code>. This is necessary to compute progress.
|
||||||
* @param index the track number of the track to rip (starting at 1
|
* @param index the track number of the track to rip (starting at 1
|
||||||
* since CDs start counting tracks at 1).
|
* since CDs start counting tracks at 1).
|
||||||
* @param target the path to the file into which the track should be
|
* @param target the path to the file into which the track should be
|
||||||
@@ -58,7 +60,7 @@ public interface Ripper
|
|||||||
* trying to rip the specified track (like lack of access to the CDROM
|
* trying to rip the specified track (like lack of access to the CDROM
|
||||||
* device or any other errors).
|
* device or any other errors).
|
||||||
*/
|
*/
|
||||||
public void ripTrack (int index, String target,
|
public void ripTrack (TrackInfo[] info, int index, String target,
|
||||||
ConversionProgressListener listener)
|
ConversionProgressListener listener)
|
||||||
throws ConvertException;
|
throws ConvertException;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user