diff --git a/source/net/sourceforge/filebot/ui/rename/MovieHashMatcher.java b/source/net/sourceforge/filebot/ui/rename/MovieHashMatcher.java index 73b808d2..f0836725 100644 --- a/source/net/sourceforge/filebot/ui/rename/MovieHashMatcher.java +++ b/source/net/sourceforge/filebot/ui/rename/MovieHashMatcher.java @@ -118,6 +118,11 @@ class MovieHashMatcher implements AutoCompleteMatcher { try { Movie movie = grepMovie(nfo, service, locale); + // ignore illegal nfos + if (movie == null) { + continue; + } + if (nfoFiles.contains(nfo)) { movieByFile.put(nfo, movie); } @@ -153,7 +158,7 @@ class MovieHashMatcher implements AutoCompleteMatcher { List remainingFiles = new ArrayList(); for (File file : movieMatchFiles) { - if (!movieByFile.containsKey(file)) { + if (movieByFile.get(file) == null) { remainingFiles.add(file); } } diff --git a/source/net/sourceforge/filebot/web/IMDbClient.java b/source/net/sourceforge/filebot/web/IMDbClient.java index fbed96f3..39397a93 100644 --- a/source/net/sourceforge/filebot/web/IMDbClient.java +++ b/source/net/sourceforge/filebot/web/IMDbClient.java @@ -23,6 +23,8 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Scanner; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -112,7 +114,7 @@ public class IMDbClient implements MovieIdentificationService { protected Movie scrapeMovie(Document dom, Locale locale) { try { String header = selectString("//H1", dom).toUpperCase(); - if (header.contains("(VG)") || header.contains("(V)")) // ignore video games and videos + if (header.contains("(VG)")) // ignore video games and videos return null; String name = selectString("//H1/A/text()", dom).replaceAll("\\s+", " ").trim(); @@ -136,7 +138,7 @@ public class IMDbClient implements MovieIdentificationService { } } } catch (Exception e) { - e.printStackTrace(); + Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to grep localized name: " + name); } } diff --git a/source/net/sourceforge/filebot/web/TMDbClient.java b/source/net/sourceforge/filebot/web/TMDbClient.java index fbe64bd3..62535d0d 100644 --- a/source/net/sourceforge/filebot/web/TMDbClient.java +++ b/source/net/sourceforge/filebot/web/TMDbClient.java @@ -7,6 +7,7 @@ import static java.util.Collections.*; import static net.sourceforge.filebot.web.WebRequest.*; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.Serializable; import java.net.URL; @@ -98,11 +99,12 @@ public class TMDbClient implements MovieIdentificationService { @Override public Movie getMovieDescriptor(int imdbid, Locale locale) throws IOException { - MovieInfo info = getMovieInfo(String.format("tt%07d", imdbid), locale, false); - if (info != null) { + try { + MovieInfo info = getMovieInfo(String.format("tt%07d", imdbid), locale, false); return new Movie(info.getName(), info.getReleased().getYear(), info.getImdbId(), info.getId()); + } catch (FileNotFoundException e) { + return null; } - return null; } @@ -235,14 +237,16 @@ public class TMDbClient implements MovieIdentificationService { @Override protected ByteBuffer fetchData(URL url, long lastModified) throws IOException { - if (limit != null) { - try { + try { + if (limit != null) { limit.acquirePermit(); - } catch (InterruptedException e) { - throw new RuntimeException(e); } + return super.fetchData(url, lastModified); + } catch (FileNotFoundException e) { + return ByteBuffer.allocate(0); + } catch (InterruptedException e) { + throw new RuntimeException(e); } - return super.fetchData(url, lastModified); } @@ -252,7 +256,11 @@ public class TMDbClient implements MovieIdentificationService { } }; - return (JSONObject) JSONValue.parse(json.get()); + JSONObject object = (JSONObject) JSONValue.parse(json.get()); + if (object == null || object.isEmpty()) { + throw new FileNotFoundException("Resource not found: " + url); + } + return object; }