* handle invalid / not-existing imdb ids from nfo files gracefully
This commit is contained in:
parent
d143e3feb5
commit
a95b983e73
|
@ -118,6 +118,11 @@ class MovieHashMatcher implements AutoCompleteMatcher {
|
||||||
try {
|
try {
|
||||||
Movie movie = grepMovie(nfo, service, locale);
|
Movie movie = grepMovie(nfo, service, locale);
|
||||||
|
|
||||||
|
// ignore illegal nfos
|
||||||
|
if (movie == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (nfoFiles.contains(nfo)) {
|
if (nfoFiles.contains(nfo)) {
|
||||||
movieByFile.put(nfo, movie);
|
movieByFile.put(nfo, movie);
|
||||||
}
|
}
|
||||||
|
@ -153,7 +158,7 @@ class MovieHashMatcher implements AutoCompleteMatcher {
|
||||||
List<File> remainingFiles = new ArrayList<File>();
|
List<File> remainingFiles = new ArrayList<File>();
|
||||||
|
|
||||||
for (File file : movieMatchFiles) {
|
for (File file : movieMatchFiles) {
|
||||||
if (!movieByFile.containsKey(file)) {
|
if (movieByFile.get(file) == null) {
|
||||||
remainingFiles.add(file);
|
remainingFiles.add(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
@ -112,7 +114,7 @@ public class IMDbClient implements MovieIdentificationService {
|
||||||
protected Movie scrapeMovie(Document dom, Locale locale) {
|
protected Movie scrapeMovie(Document dom, Locale locale) {
|
||||||
try {
|
try {
|
||||||
String header = selectString("//H1", dom).toUpperCase();
|
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;
|
return null;
|
||||||
|
|
||||||
String name = selectString("//H1/A/text()", dom).replaceAll("\\s+", " ").trim();
|
String name = selectString("//H1/A/text()", dom).replaceAll("\\s+", " ").trim();
|
||||||
|
@ -136,7 +138,7 @@ public class IMDbClient implements MovieIdentificationService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to grep localized name: " + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import static java.util.Collections.*;
|
||||||
import static net.sourceforge.filebot.web.WebRequest.*;
|
import static net.sourceforge.filebot.web.WebRequest.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
@ -98,12 +99,13 @@ public class TMDbClient implements MovieIdentificationService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Movie getMovieDescriptor(int imdbid, Locale locale) throws IOException {
|
public Movie getMovieDescriptor(int imdbid, Locale locale) throws IOException {
|
||||||
|
try {
|
||||||
MovieInfo info = getMovieInfo(String.format("tt%07d", imdbid), locale, false);
|
MovieInfo info = getMovieInfo(String.format("tt%07d", imdbid), locale, false);
|
||||||
if (info != null) {
|
|
||||||
return new Movie(info.getName(), info.getReleased().getYear(), info.getImdbId(), info.getId());
|
return new Movie(info.getName(), info.getReleased().getYear(), info.getImdbId(), info.getId());
|
||||||
}
|
} catch (FileNotFoundException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -235,15 +237,17 @@ public class TMDbClient implements MovieIdentificationService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuffer fetchData(URL url, long lastModified) throws IOException {
|
protected ByteBuffer fetchData(URL url, long lastModified) throws IOException {
|
||||||
if (limit != null) {
|
|
||||||
try {
|
try {
|
||||||
|
if (limit != null) {
|
||||||
limit.acquirePermit();
|
limit.acquirePermit();
|
||||||
|
}
|
||||||
|
return super.fetchData(url, lastModified);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
return ByteBuffer.allocate(0);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.fetchData(url, lastModified);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue