* try to grab more optional ID3 tags if available

This commit is contained in:
Reinhard Pointner 2013-12-18 15:42:42 +00:00
parent bed1e7246f
commit 1c46ed1809
2 changed files with 39 additions and 7 deletions

View File

@ -604,7 +604,7 @@ public class MediaBindingBean {
@Define("pn")
public Integer getPartCount() {
if (infoObject instanceof AudioTrack)
return getMusic().getTrackCount();
return getMusic().getTrackCount() != null ? getMusic().getTrackCount() : Integer.parseInt(getMediaInfo(StreamKind.General, 0, "Track/Position_Total"));
if (infoObject instanceof MoviePart)
return ((MoviePart) infoObject).getPartCount();

View File

@ -4,6 +4,9 @@ import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Icon;
@ -33,13 +36,42 @@ public class ID3Lookup implements MusicIdentificationService {
throw new IOException("MediaInfo failed to open file: " + f);
}
String artist = mediaInfo.get(StreamKind.General, 0, "Performer");
String title = mediaInfo.get(StreamKind.General, 0, "Title");
String album = mediaInfo.get(StreamKind.General, 0, "Album");
mediaInfo.close();
try {
String artist = mediaInfo.get(StreamKind.General, 0, "Performer");
String title = mediaInfo.get(StreamKind.General, 0, "Title");
String album = mediaInfo.get(StreamKind.General, 0, "Album");
if (artist.length() > 0 && title.length() > 0 && album.length() > 0) {
info.put(f, new AudioTrack(artist, title, album));
// extra info if available
String albumArtist = null, trackTitle = null;
Date albumReleaseDate = null;
Integer mediumIndex = null, mediumCount = null, trackIndex = null, trackCount = null;
try {
int year = new Scanner(mediaInfo.get(StreamKind.General, 0, "Recorded_Date")).useDelimiter("\\D+").nextInt();
albumReleaseDate = new Date(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));
}
} catch (Throwable e) {
Logger.getLogger(ID3Lookup.class.getName()).log(Level.WARNING, e.getMessage(), e);
} finally {
mediaInfo.close();
}
}