diff --git a/source/net/sourceforge/filebot/ui/rename/MovieHashMatcher.java b/source/net/sourceforge/filebot/ui/rename/MovieHashMatcher.java index 5545f58f..fba2949b 100644 --- a/source/net/sourceforge/filebot/ui/rename/MovieHashMatcher.java +++ b/source/net/sourceforge/filebot/ui/rename/MovieHashMatcher.java @@ -71,7 +71,7 @@ class MovieHashMatcher implements AutoCompleteMatcher { movie = grabMovieName(movieFiles[i], locale, autodetect, movie); if (movie != null) { - Analytics.trackEvent(service.getName(), "SearchMovie", movie.getName(), 1); + Analytics.trackEvent(service.getName(), "SearchMovie", movie.toString(), 1); } } diff --git a/source/net/sourceforge/filebot/web/OpenSubtitlesXmlRpc.java b/source/net/sourceforge/filebot/web/OpenSubtitlesXmlRpc.java index aface689..168ba2cc 100644 --- a/source/net/sourceforge/filebot/web/OpenSubtitlesXmlRpc.java +++ b/source/net/sourceforge/filebot/web/OpenSubtitlesXmlRpc.java @@ -131,17 +131,22 @@ public class OpenSubtitlesXmlRpc { Pattern pattern = Pattern.compile("(.+)[(](\\d{4})([/]I+)?[)]"); for (Map movie : movieData) { - // match movie name and movie year from search result - Matcher matcher = pattern.matcher(movie.get("title")); - - if (matcher.find()) { + try { + String imdbid = movie.get("id"); + if (!imdbid.matches("\\d{1,7}")) + throw new IllegalArgumentException("Illegal IMDbID"); + + // match movie name and movie year from search result + Matcher matcher = pattern.matcher(movie.get("title")); + if (!matcher.find()) + throw new IllegalArgumentException("Illegal title"); + String name = matcher.group(1).trim(); int year = Integer.parseInt(matcher.group(2)); - int imdbid = Integer.parseInt(movie.get("id")); - movies.add(new Movie(name, year, imdbid)); - } else { - Logger.getLogger(OpenSubtitlesXmlRpc.class.getName()).log(Level.WARNING, "Error parsing title: " + movie); + movies.add(new Movie(name, year, Integer.parseInt(imdbid))); + } catch (Exception e) { + Logger.getLogger(OpenSubtitlesXmlRpc.class.getName()).log(Level.WARNING, String.format("Ignore movie %s: %s", movie, e.getMessage())); } } diff --git a/test/net/sourceforge/filebot/web/OpenSubtitlesXmlRpcTest.java b/test/net/sourceforge/filebot/web/OpenSubtitlesXmlRpcTest.java index 3acaa037..f51172a7 100644 --- a/test/net/sourceforge/filebot/web/OpenSubtitlesXmlRpcTest.java +++ b/test/net/sourceforge/filebot/web/OpenSubtitlesXmlRpcTest.java @@ -44,6 +44,15 @@ public class OpenSubtitlesXmlRpcTest { } + @Test(expected = IndexOutOfBoundsException.class) + public void searchOST() throws Exception { + List list = xmlrpc.searchMoviesOnIMDB("Linkin.Park.New.Divide.1280-720p.Transformers.Revenge.of.the.Fallen.ost"); + + // seek to OST entry, expect to fail + for (int i = 0; !list.get(i).getName().contains("Linkin.Park"); i++); + } + + @Test public void getSubtitleListEnglish() throws Exception { List list = xmlrpc.searchSubtitles(361256, "eng");