1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-24 08:48: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 class MediaInfoException extends RuntimeException {
public MediaInfoException(String message) {
super(message);
}
public MediaInfoException(LinkageError e) { public MediaInfoException(LinkageError e) {
super(getLinkageErrorMessage(e), e); super(getLinkageErrorMessage(e), e);
} }

View File

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