* added some sanity checks regarding release year

This commit is contained in:
Reinhard Pointner 2012-02-18 09:26:17 +00:00
parent 7968580281
commit 3c8d6b5395
1 changed files with 3 additions and 3 deletions

View File

@ -71,10 +71,10 @@ public class IMDbClient implements MovieIdentificationService {
if (name.startsWith("\""))
continue;
String year = node.getNextSibling().getTextContent().replaceAll("[\\p{Punct}\\p{Space}]+", "").trim(); // remove non-number characters
String year = node.getNextSibling().getTextContent().replaceAll("[\\p{Punct}\\p{Space}]+", ""); // remove non-number characters
String href = getAttribute("href", node);
results.add(new Movie(name, Integer.parseInt(year), getImdbId(href)));
results.add(new Movie(name, Pattern.matches("\\d{4}", year) ? Integer.parseInt(year) : -1, getImdbId(href)));
} catch (Exception e) {
// ignore illegal movies (TV Shows, Videos, Video Games, etc)
}
@ -97,7 +97,7 @@ public class IMDbClient implements MovieIdentificationService {
String name = selectString("//H1/text()", dom);
String year = new Scanner(selectString("//H1//SPAN", dom)).useDelimiter("\\D+").next();
String url = selectString("//LINK[@rel='canonical']/@href", dom);
return new Movie(name, Integer.parseInt(year), getImdbId(url));
return new Movie(name, Pattern.matches("\\d{4}", year) ? Integer.parseInt(year) : -1, getImdbId(url));
} catch (Exception e) {
// ignore, we probably got redirected to an error page
return null;