1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-24 08:48:51 -05:00

* fix various ID3Lookup issues

This commit is contained in:
Reinhard Pointner 2015-11-06 09:15:37 +00:00
parent 8d94a66338
commit e80c9d855a

View File

@ -5,7 +5,6 @@ import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Scanner;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -38,45 +37,31 @@ public class ID3Lookup implements MusicIdentificationService {
} }
try { try {
String artist = mediaInfo.get(StreamKind.General, 0, "Performer"); // artist and song title information is required
String title = mediaInfo.get(StreamKind.General, 0, "Title"); String artist = getString(mediaInfo, "Performer");
String album = mediaInfo.get(StreamKind.General, 0, "Album"); String title = getString(mediaInfo, "Title");
// extra info if available if (artist != null && title != null) {
String albumArtist = null, trackTitle = null; // all other properties are optional
SimpleDate albumReleaseDate = null; String album = getString(mediaInfo, "Album");
Integer mediumIndex = null, mediumCount = null, trackIndex = null, trackCount = null; String albumArtist = getString(mediaInfo, "Album/Performer");
String trackTitle = null;
SimpleDate albumReleaseDate = null;
Integer mediumIndex = null;
Integer mediumCount = null;
Integer trackIndex = getInteger(mediaInfo, "Track/Position");
Integer trackCount = getInteger(mediaInfo, "Track/Position_Total");
String mbid = null;
try { Integer year = getInteger(mediaInfo, "Recorded_Date");
albumArtist = mediaInfo.get(StreamKind.General, 0, "Album/Performer"); if (year != null) {
} catch (Exception e) { albumReleaseDate = new SimpleDate(year, 1, 1);
// ignore }
}
try { info.put(f, new AudioTrack(artist, title, album, albumArtist, trackTitle, albumReleaseDate, mediumIndex, mediumCount, trackIndex, trackCount, mbid));
int year = new Scanner(mediaInfo.get(StreamKind.General, 0, "Recorded_Date")).useDelimiter("\\D+").nextInt();
albumReleaseDate = new SimpleDate(year, 1, 1);
} catch (Exception e) {
// ignore
}
try {
trackIndex = Integer.parseInt(mediaInfo.get(StreamKind.General, 0, "Track/Position"));
} catch (Exception e) {
// ignore
}
try {
trackCount = Integer.parseInt(mediaInfo.get(StreamKind.General, 0, "Track/Position_Total"));
} catch (Exception e) {
// ignore
}
if (artist.length() > 0 && title.length() > 0 && album.length() > 0) {
info.put(f, new AudioTrack(artist, title, album, albumArtist, trackTitle, albumReleaseDate, mediumIndex, mediumCount, trackIndex, trackCount, null));
} }
} catch (Throwable e) { } catch (Throwable e) {
Logger.getLogger(ID3Lookup.class.getName()).log(Level.WARNING, e.getMessage(), e); Logger.getLogger(ID3Lookup.class.getName()).log(Level.WARNING, e.toString());
} finally { } finally {
mediaInfo.close(); mediaInfo.close();
} }
@ -84,4 +69,25 @@ public class ID3Lookup implements MusicIdentificationService {
return info; return info;
} }
private String getString(MediaInfo mediaInfo, String field) {
String value = mediaInfo.get(StreamKind.General, 0, field).trim();
if (value.length() > 0) {
return value;
}
return null;
}
private Integer getInteger(MediaInfo mediaInfo, String field) {
String value = getString(mediaInfo, field);
if (value != null) {
try {
return new Integer(value);
} catch (Exception e) {
Logger.getLogger(ID3Lookup.class.getName()).log(Level.WARNING, e.toString());
}
}
return null;
}
} }