* @Date: 29.06.2009
*/
public class CUEParser {
public void parse(List<Track> list, Track file, LineNumberReader cueStream, boolean embedded) {
try {
CueSheet cueSheet = CueParser.parse(cueStream);
List<FileData> datas = cueSheet.getFileData();
String cueLocation = file.getTrackData().getFile().getAbsolutePath();
if (datas.size() > 0) {
for (FileData fileData : datas) {
if (!embedded) {
String parent = file.getTrackData().getFile().getParent();
File referencedFile = new File(parent, fileData.getFile());
if (!referencedFile.exists())
continue;
AudioFileReader reader = TrackIO.getAudioFileReader(referencedFile.getName());
if (reader == null) break;
file = reader.read(referencedFile);
}
int size = fileData.getTrackData().size();
for (int i = 0; i < size; i++) {
TrackData trackData = fileData.getTrackData().get(i);
Track track = file.copy();
track.getTrackData().setCueEmbedded(embedded);
if (!embedded)
track.getTrackData().setCueLocation(cueLocation);
String album = trackData.getMetaData(CueSheet.MetaDataField.ALBUMTITLE);
if (album.length() > 0)
track.getTrackData().setTagFieldValues(FieldKey.ALBUM, album);
String artist = trackData.getPerformer();
track.getTrackData().setTagFieldValues(FieldKey.ARTIST, artist != null && artist.length() > 0 ? artist : cueSheet.getPerformer());
track.getTrackData().setTagFieldValues(FieldKey.ALBUM_ARTIST, cueSheet.getPerformer());
track.getTrackData().setTagFieldValues(FieldKey.COMMENT, cueSheet.getComment());
track.getTrackData().setTagFieldValues(FieldKey.TITLE, trackData.getTitle());
String year = trackData.getMetaData(CueSheet.MetaDataField.YEAR);
if (year.length() > 0)
track.getTrackData().setTagFieldValues(FieldKey.YEAR, year);
track.getTrackData().setTagFieldValues(FieldKey.TRACK, String.valueOf(trackData.getNumber()));