Wrote a wrapper around the id3 tag program.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@618 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2002-03-03 05:25:10 +00:00
parent bb29ba4bfd
commit 3d2574dd59
2 changed files with 96 additions and 0 deletions
@@ -0,0 +1,77 @@
//
// $Id: ID3Tagger.java,v 1.1 2002/03/03 05:25:09 mdb Exp $
package robodj.convert;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.util.StreamUtils;
/**
* A tagger implementation that uses 'id3' to do it's job.
*/
public class ID3Tagger
{
// documentation inherited
public void idTrack (String target, String artist, String album,
String title, int trackNo)
throws ConvertException
{
String[] cmdarray = new String[] {
"id3", "-t", title, "-a", artist, "-A", album,
"-T", Integer.toString(trackNo), target };
try {
Runtime rt = Runtime.getRuntime();
Process ripproc = rt.exec(cmdarray);
InputStream in = ripproc.getErrorStream();
String output = StreamUtils.streamAsString(in);
// check the return value of the process
try {
int retval = ripproc.waitFor();
if (retval != 0) {
// ship off the error output from id3
throw new ConvertException(
"id3 failed: " + output);
}
} 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);
}
}
public static void main (String[] args)
{
ID3Tagger tagger = new ID3Tagger();
if (args.length < 5) {
System.err.println("Usage: ID3Tagger target artist album " +
"title trackNo");
System.exit(-1);
}
int trackNo = 0;
try {
trackNo = Integer.parseInt(args[4]);
} catch (NumberFormatException nfe) {
System.err.println("Invalid track number: " + args[4]);
System.exit(-1);
}
try {
tagger.idTrack(args[0], args[1], args[2], args[3], trackNo);
} catch (ConvertException ce) {
ce.printStackTrace(System.err);
}
}
}
@@ -0,0 +1,19 @@
//
// $Id: Tagger.java,v 1.1 2002/03/03 05:25:10 mdb Exp $
package robodj.convert;
/**
* The tagger interface is used to set the ID3 tags in MP3 files.
*/
public interface Tagger
{
/**
* Sets the ID3 tags for the specified target MP3 file for the
* supplied information: artist, album name, track title and track
* number.
*/
public void idTrack (String target, String artist, String album,
String title, int trackNo)
throws ConvertException;
}