Added encoder interface, fixed more stuff up.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@8 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// $Id: CDParanoiaRipper.java,v 1.1 2000/10/30 21:08:53 mdb Exp $
|
// $Id: CDParanoiaRipper.java,v 1.2 2000/10/30 22:21:11 mdb Exp $
|
||||||
|
|
||||||
package robodj.rip;
|
package robodj.convert;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -13,8 +13,20 @@ import gnu.regexp.*;
|
|||||||
*/
|
*/
|
||||||
public class CDParanoiaRipper implements Ripper
|
public class CDParanoiaRipper implements Ripper
|
||||||
{
|
{
|
||||||
public TrackInfo[] getTrackInfo () throws RipException
|
public TrackInfo[] getTrackInfo ()
|
||||||
|
throws ConvertException
|
||||||
{
|
{
|
||||||
|
// an input line that we're interested in looks something like
|
||||||
|
// this:
|
||||||
|
//
|
||||||
|
// 1. 17980 [03:59.55] 0 [00:00.00] no no 2
|
||||||
|
RE regex;
|
||||||
|
try {
|
||||||
|
regex = new RE("^\\s*\\d+\\.\\s+(\\d+)\\s\\[\\S*\\]\\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();
|
||||||
@@ -28,13 +40,6 @@ public class CDParanoiaRipper implements Ripper
|
|||||||
StringBuffer input = new StringBuffer();
|
StringBuffer input = new StringBuffer();
|
||||||
ArrayList flist = new ArrayList();
|
ArrayList flist = new ArrayList();
|
||||||
|
|
||||||
// an input line that we're interested in looks something like
|
|
||||||
// this:
|
|
||||||
//
|
|
||||||
// 1. 17980 [03:59.55] 0 [00:00.00] no no 2
|
|
||||||
RE regex =
|
|
||||||
new RE("^\\s*\\d+\\.\\s+(\\d+)\\s\\[\\S*\\]\\s+(\\d+)");
|
|
||||||
|
|
||||||
while ((inline = din.readLine()) != null) {
|
while ((inline = din.readLine()) != null) {
|
||||||
// skip blank lines and lines that are in the header
|
// skip blank lines and lines that are in the header
|
||||||
if (inline.trim().length() == 0 ||
|
if (inline.trim().length() == 0 ||
|
||||||
@@ -43,8 +48,6 @@ public class CDParanoiaRipper implements Ripper
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// System.out.println("Matching: " + inline);
|
|
||||||
|
|
||||||
// keep track of all of the input in case we need to
|
// keep track of all of the input in case we need to
|
||||||
// report an error later
|
// report an error later
|
||||||
input.append(inline).append("\n");
|
input.append(inline).append("\n");
|
||||||
@@ -62,14 +65,14 @@ public class CDParanoiaRipper implements Ripper
|
|||||||
int retval = tocproc.waitFor();
|
int retval = tocproc.waitFor();
|
||||||
if (retval != 0) {
|
if (retval != 0) {
|
||||||
// ship off the error output from cdparanoia
|
// ship off the error output from cdparanoia
|
||||||
throw new RipException(input.toString());
|
throw new ConvertException(input.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
// why we were interrupted I can only speculate, but we'll
|
// why we were interrupted I can only speculate, but we'll
|
||||||
// go ahead and freak out anyway
|
// go ahead and freak out anyway
|
||||||
throw new RipException("Interrupted while waiting for " +
|
throw new ConvertException("Interrupted while waiting for " +
|
||||||
"cdparanoia process to exit.");
|
"cdparanoia process to exit.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse the frame offsets and stick them in an array
|
// parse the frame offsets and stick them in an array
|
||||||
@@ -88,20 +91,63 @@ public class CDParanoiaRipper implements Ripper
|
|||||||
frames[i].offset += 2 * RipUtil.FRAMES_PER_SECOND;
|
frames[i].offset += 2 * RipUtil.FRAMES_PER_SECOND;
|
||||||
|
|
||||||
} catch (NumberFormatException nfe) {
|
} catch (NumberFormatException nfe) {
|
||||||
throw new RipException("Bogus frame value for track " +
|
throw new ConvertException(
|
||||||
(i+1) + ": " + nfe.getMessage() +
|
"Bogus frame value for track " + (i+1) + ": " +
|
||||||
"\n\n" + input);
|
nfe.getMessage() + "\n\n" + input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return frames;
|
return frames;
|
||||||
|
|
||||||
} catch (REException ree) {
|
} catch (IOException ioe) {
|
||||||
throw new RipException("Can't compile regular expression?! " +
|
throw new ConvertException(
|
||||||
ree);
|
"Error communicating with ripper:\n" + ioe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ripTrack (int index, String target,
|
||||||
|
RipProgressListener listener)
|
||||||
|
throws ConvertException
|
||||||
|
{
|
||||||
|
StringBuffer cmd = new StringBuffer("cdparanoia");
|
||||||
|
cmd.append(" -w"); // request output in WAV format
|
||||||
|
cmd.append(" -e"); // request progress information to stderr
|
||||||
|
cmd.append(" ").append(index); // add track number
|
||||||
|
cmd.append(" ").append(target); // add output file name
|
||||||
|
|
||||||
|
try {
|
||||||
|
// fork off a cdparanoia process to read the TOC
|
||||||
|
Runtime rt = Runtime.getRuntime();
|
||||||
|
Process ripproc = rt.exec(cmd.toString());
|
||||||
|
|
||||||
|
InputStream in = ripproc.getErrorStream();
|
||||||
|
BufferedInputStream bin = new BufferedInputStream(in);
|
||||||
|
DataInputStream din = new DataInputStream(bin);
|
||||||
|
|
||||||
|
// read output from the subprocess and chuck it for now
|
||||||
|
while (din.readLine() != null) {
|
||||||
|
// la la la
|
||||||
|
}
|
||||||
|
|
||||||
|
// check the return value of the process
|
||||||
|
try {
|
||||||
|
int retval = ripproc.waitFor();
|
||||||
|
if (retval != 0) {
|
||||||
|
// ship off the error output from cdparanoia
|
||||||
|
throw new ConvertException(
|
||||||
|
"Ripper failed: " + retval);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
// why we were interrupted I can only speculate, but we'll
|
||||||
|
// go ahead and freak out anyway
|
||||||
|
throw new ConvertException("Interrupted while waiting for " +
|
||||||
|
"ripper process to exit.");
|
||||||
|
}
|
||||||
|
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
throw new RipException("Error talking to rip process: " + ioe);
|
throw new ConvertException(
|
||||||
|
"Error communicating with ripper:\n" + ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
//
|
||||||
|
// $Id: ConversionProgressListener.java,v 1.1 2000/10/30 22:21:11 mdb Exp $
|
||||||
|
|
||||||
|
package robodj.convert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This interface is used to communicate ripping progress from a ripper or
|
||||||
|
* encoder implementation to code using the conversion services (and
|
||||||
|
* hopefully ultimately to the end user).
|
||||||
|
*/
|
||||||
|
public interface ConversionProgressListener
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Informs the listener that the converter has completed the specified
|
||||||
|
* percentage of the conversion process. The percentage should reflect
|
||||||
|
* only the conversion being performed by the converter at that time
|
||||||
|
* (ripping or converting a single track). The information provided
|
||||||
|
* herein will be mapped to a global progress indication by the
|
||||||
|
* calling software (in the case of converting an entire CD).
|
||||||
|
*/
|
||||||
|
public void updateProgress (float percentComplete);
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
//
|
||||||
|
// $Id: ConvertException.java,v 1.1 2000/10/30 22:21:11 mdb Exp $
|
||||||
|
|
||||||
|
package robodj.convert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A convert exception can be thrown to indicate that some problem was
|
||||||
|
* encountered during some part of the conversion process (ripping or
|
||||||
|
* encoding).
|
||||||
|
*/
|
||||||
|
public class ConvertException extends Exception
|
||||||
|
{
|
||||||
|
public ConvertException (String message)
|
||||||
|
{
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// $Id: Encoder.java,v 1.1 2000/10/30 22:21:11 mdb Exp $
|
||||||
|
|
||||||
|
package robodj.convert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The encoder interface is used to manipulate particular MP3 encoding
|
||||||
|
* software in the ways needed by the RoboDJ system.
|
||||||
|
*/
|
||||||
|
public interface Encoder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Instructs the encoder to encode the specified track.
|
||||||
|
*
|
||||||
|
* @param source the path to the source file that should be encoded.
|
||||||
|
* @param dest the path to the destination file which should be
|
||||||
|
* created by the encoder.
|
||||||
|
* @param listener a callback object that should be called to
|
||||||
|
* communicate encoding progress. If the listener parameter is null,
|
||||||
|
* the caller doesn't want to hear about progress (shame on them).
|
||||||
|
*
|
||||||
|
* @exception ConvertException can be thrown if anything fails during
|
||||||
|
* the encoding process.
|
||||||
|
*/
|
||||||
|
public void encodeTrack (String source, String dest,
|
||||||
|
ConversionProgressListener listener)
|
||||||
|
throws ConvertException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
//
|
||||||
|
// $Id: L3Encoder.java,v 1.1 2000/10/30 22:21:11 mdb Exp $
|
||||||
|
|
||||||
|
package robodj.convert;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An encoder implementation that uses the Fraunhofer-IIS L3ENC mp3
|
||||||
|
* encoding program.
|
||||||
|
*/
|
||||||
|
public class L3Encoder implements Encoder
|
||||||
|
{
|
||||||
|
public void encodeTrack (String source, String dest,
|
||||||
|
ConversionProgressListener listener)
|
||||||
|
throws ConvertException
|
||||||
|
{
|
||||||
|
StringBuffer cmd = new StringBuffer("l3enc");
|
||||||
|
cmd.append(" ").append(source); // add input file name
|
||||||
|
cmd.append(" ").append(dest); // add output file name
|
||||||
|
cmd.append(" -br 128000"); // request 128kbps encoding
|
||||||
|
|
||||||
|
try {
|
||||||
|
// fork off a cdparanoia process to read the TOC
|
||||||
|
Runtime rt = Runtime.getRuntime();
|
||||||
|
Process encproc = rt.exec(cmd.toString());
|
||||||
|
|
||||||
|
InputStream in = encproc.getErrorStream();
|
||||||
|
BufferedInputStream bin = new BufferedInputStream(in);
|
||||||
|
DataInputStream din = new DataInputStream(bin);
|
||||||
|
|
||||||
|
// read output from the subprocess and chuck it for now
|
||||||
|
while (din.readLine() != null) {
|
||||||
|
// la la la
|
||||||
|
}
|
||||||
|
|
||||||
|
// check the return value of the process
|
||||||
|
try {
|
||||||
|
int retval = encproc.waitFor();
|
||||||
|
if (retval != 0) {
|
||||||
|
// ship off the error output from cdparanoia
|
||||||
|
throw new ConvertException(
|
||||||
|
"Encoder failed: " + retval);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
// why we were interrupted I can only speculate, but we'll
|
||||||
|
// go ahead and freak out anyway
|
||||||
|
throw new ConvertException("Interrupted while waiting for " +
|
||||||
|
"encoder process to exit.");
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
throw new ConvertException(
|
||||||
|
"Error communicating with encoder:\n" + ioe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,14 @@
|
|||||||
#
|
#
|
||||||
# $Id: Makefile,v 1.1 2000/10/30 21:08:53 mdb Exp $
|
# $Id: Makefile,v 1.2 2000/10/30 22:21:11 mdb Exp $
|
||||||
|
|
||||||
ROOT = ../..
|
ROOT = ../..
|
||||||
|
|
||||||
SRCS = \
|
SRCS = \
|
||||||
CDParanoiaRipper.java \
|
CDParanoiaRipper.java \
|
||||||
RipException.java \
|
ConversionProgressListener.java \
|
||||||
|
ConvertException.java \
|
||||||
|
Encoder.java \
|
||||||
|
L3Encoder.java \
|
||||||
RipTest.java \
|
RipTest.java \
|
||||||
RipUtil.java \
|
RipUtil.java \
|
||||||
Ripper.java \
|
Ripper.java \
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
//
|
|
||||||
// $Id: RipException.java,v 1.1 2000/10/30 21:08:53 mdb Exp $
|
|
||||||
|
|
||||||
package robodj.rip;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A rip exception can be thrown to indicate that some problem was
|
|
||||||
* encountered during some part of the ripping process.
|
|
||||||
*/
|
|
||||||
public class RipException extends Exception
|
|
||||||
{
|
|
||||||
public RipException (String message)
|
|
||||||
{
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// $Id: RipTest.java,v 1.1 2000/10/30 21:08:53 mdb Exp $
|
// $Id: RipTest.java,v 1.2 2000/10/30 22:21:11 mdb Exp $
|
||||||
|
|
||||||
package robodj.rip;
|
package robodj.convert;
|
||||||
|
|
||||||
import com.samskivert.net.cddb.*;
|
import com.samskivert.net.cddb.*;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// $Id: RipUtil.java,v 1.1 2000/10/30 21:08:53 mdb Exp $
|
// $Id: RipUtil.java,v 1.2 2000/10/30 22:21:11 mdb Exp $
|
||||||
|
|
||||||
package robodj.rip;
|
package robodj.convert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class contains utility functions related to ripping.
|
* This class contains utility functions related to ripping.
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
//
|
//
|
||||||
// $Id: Ripper.java,v 1.1 2000/10/30 21:08:53 mdb Exp $
|
// $Id: Ripper.java,v 1.2 2000/10/30 22:21:11 mdb Exp $
|
||||||
|
|
||||||
package robodj.rip;
|
package robodj.convert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ripper interface is used to manipulate a particular piece of CD
|
* The ripper interface is used to manipulate particular CD ripping
|
||||||
* ripping software in the ways needed by the RoboDJ system.
|
* software in the ways needed by the RoboDJ system.
|
||||||
*/
|
*/
|
||||||
public interface Ripper
|
public interface Ripper
|
||||||
{
|
{
|
||||||
@@ -33,9 +33,32 @@ public interface Ripper
|
|||||||
* seconds to do its job or it will be declared delinquent and
|
* seconds to do its job or it will be declared delinquent and
|
||||||
* ignored.
|
* ignored.
|
||||||
*
|
*
|
||||||
* @exception RipException can be thrown if some problem occurs trying
|
* @exception ConvertException can be thrown if some problem occurs
|
||||||
* to read the CD table of contents (like lack of access to the CDROM
|
* trying to read the CD table of contents (like lack of access to the
|
||||||
|
* CDROM device or any other errors).
|
||||||
|
*/
|
||||||
|
public TrackInfo[] getTrackInfo ()
|
||||||
|
throws ConvertException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instructs the ripper to rip the track with the supplied index into
|
||||||
|
* the file specified by target. If the ripper supports progress
|
||||||
|
* notification, it should communicate it to the supplied progress
|
||||||
|
* listener. The track should be ripped in WAV format.
|
||||||
|
*
|
||||||
|
* @param index the track number of the track to rip (starting at 1
|
||||||
|
* since CDs start counting tracks at 1).
|
||||||
|
* @param target the path to the file into which the track should be
|
||||||
|
* ripped.
|
||||||
|
* @param listener a callback object that should be called to
|
||||||
|
* communicate ripping progress. If the listener parameter is null,
|
||||||
|
* the caller doesn't want to hear about progress (shame on them).
|
||||||
|
*
|
||||||
|
* @exception ConvertException can be thrown if some problem occurs
|
||||||
|
* trying to rip the specified track (like lack of access to the CDROM
|
||||||
* device or any other errors).
|
* device or any other errors).
|
||||||
*/
|
*/
|
||||||
public TrackInfo[] getTrackInfo () throws RipException;
|
public void ripTrack (int index, String target,
|
||||||
|
ConversionProgressListener listener)
|
||||||
|
throws ConvertException;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user