1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-23 16:28:51 -05:00

Fail gracefully when doing ID3 lookups

This commit is contained in:
Reinhard Pointner 2016-03-10 06:47:51 +00:00
parent e193e60d9f
commit 1a0fd86ba5
2 changed files with 37 additions and 32 deletions

View File

@ -4,6 +4,10 @@ import com.sun.jna.Platform;
public class MediaInfoException extends RuntimeException {
public MediaInfoException(String message) {
super(message);
}
public MediaInfoException(LinkageError e) {
super(getLinkageErrorMessage(e), e);
}

View File

@ -1,10 +1,11 @@
package net.filebot.web;
import static net.filebot.Logging.*;
import static net.filebot.MediaTypes.*;
import static net.filebot.util.FileUtilities.*;
import static net.filebot.util.StringUtilities.*;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
@ -15,6 +16,7 @@ import javax.swing.Icon;
import net.filebot.ResourceManager;
import net.filebot.mediainfo.MediaInfo;
import net.filebot.mediainfo.MediaInfo.StreamKind;
import net.filebot.mediainfo.MediaInfoException;
public class ID3Lookup implements MusicIdentificationService {
@ -32,40 +34,39 @@ public class ID3Lookup implements MusicIdentificationService {
public Map<File, AudioTrack> lookup(Collection<File> files) throws Exception {
Map<File, AudioTrack> info = new LinkedHashMap<File, AudioTrack>();
MediaInfo mediaInfo = new MediaInfo();
for (File f : files) {
if (!mediaInfo.open(f)) {
throw new IOException("MediaInfo failed to open file: " + f);
}
try {
// artist and song title information is required
String artist = getString(mediaInfo, "Performer", "Composer");
String title = getString(mediaInfo, "Title", "Track");
if (artist != null && title != null) {
// all other properties are optional
String album = getString(mediaInfo, "Album");
String albumArtist = getString(mediaInfo, "Album/Performer");
String trackTitle = getString(mediaInfo, "Track");
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;
Integer year = getInteger(mediaInfo, "Recorded_Date");
if (year != null) {
albumReleaseDate = new SimpleDate(year, 1, 1);
try (MediaInfo mediaInfo = new MediaInfo()) {
for (File f : filter(files, AUDIO_FILES, VIDEO_FILES)) {
try {
if (!mediaInfo.open(f)) {
throw new MediaInfoException("Failed to read media info: " + f);
}
info.put(f, new AudioTrack(artist, title, album, albumArtist, trackTitle, albumReleaseDate, mediumIndex, mediumCount, trackIndex, trackCount, mbid));
// artist and song title information is required
String artist = getString(mediaInfo, "Performer", "Composer");
String title = getString(mediaInfo, "Title", "Track");
if (artist != null && title != null) {
// all other properties are optional
String album = getString(mediaInfo, "Album");
String albumArtist = getString(mediaInfo, "Album/Performer");
String trackTitle = getString(mediaInfo, "Track");
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;
Integer year = getInteger(mediaInfo, "Recorded_Date");
if (year != null) {
albumReleaseDate = new SimpleDate(year, 1, 1);
}
info.put(f, new AudioTrack(artist, title, album, albumArtist, trackTitle, albumReleaseDate, mediumIndex, mediumCount, trackIndex, trackCount, mbid));
}
} catch (Throwable e) {
debug.warning(e.getMessage());
}
} catch (Throwable e) {
debug.log(Level.WARNING, e.toString());
} finally {
mediaInfo.close();
}
}