mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-24 00:38:52 -05:00
Fail gracefully when doing ID3 lookups
This commit is contained in:
parent
e193e60d9f
commit
1a0fd86ba5
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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,40 +34,39 @@ 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)) {
|
||||||
if (!mediaInfo.open(f)) {
|
try {
|
||||||
throw new IOException("MediaInfo failed to open file: " + f);
|
if (!mediaInfo.open(f)) {
|
||||||
}
|
throw new MediaInfoException("Failed to read media info: " + 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user