* handle invalid / not-existing imdb ids from nfo files gracefully

This commit is contained in:
Reinhard Pointner 2012-07-25 01:40:11 +00:00
parent d143e3feb5
commit a95b983e73
3 changed files with 27 additions and 12 deletions

View File

@ -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<File> remainingFiles = new ArrayList<File>();
for (File file : movieMatchFiles) {
if (!movieByFile.containsKey(file)) {
if (movieByFile.get(file) == null) {
remainingFiles.add(file);
}
}

View File

@ -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);
}
}

View File

@ -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;
}