From 4a95aaf0292b8546fbf70de66c8eab388114249c Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Fri, 6 Nov 2015 19:44:55 +0000 Subject: [PATCH] * update & enable OpenSubtitles GuessMovie RPC method again --- .../net/filebot/web/OpenSubtitlesClient.java | 25 ++++++++----------- .../net/filebot/web/OpenSubtitlesXmlRpc.java | 20 ++++++--------- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/source/net/filebot/web/OpenSubtitlesClient.java b/source/net/filebot/web/OpenSubtitlesClient.java index 84fbf5a2..e70e33b4 100644 --- a/source/net/filebot/web/OpenSubtitlesClient.java +++ b/source/net/filebot/web/OpenSubtitlesClient.java @@ -94,21 +94,18 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS @Override public List guess(String tag) throws Exception { - // !!! XML-RPC CURRENTLY METHOD BROKEN !!! - return emptyList(); + List subtitles = getCache().getSearchResult("guess", tag); + if (subtitles != null) { + return subtitles; + } - // List subtitles = getCache().getSearchResult("guess", tag); - // if (subtitles != null) { - // return subtitles; - // } - // - // // require login - // login(); - // - // subtitles = xmlrpc.guessMovie(singleton(tag)).getOrDefault(tag, emptyList()); - // - // getCache().putSearchResult("guess", tag, subtitles); - // return subtitles; + // require login + login(); + + subtitles = xmlrpc.guessMovie(singleton(tag)).getOrDefault(tag, emptyList()); + + getCache().putSearchResult("guess", tag, subtitles); + return subtitles; } @Override diff --git a/source/net/filebot/web/OpenSubtitlesXmlRpc.java b/source/net/filebot/web/OpenSubtitlesXmlRpc.java index 041e5756..09fd5805 100644 --- a/source/net/filebot/web/OpenSubtitlesXmlRpc.java +++ b/source/net/filebot/web/OpenSubtitlesXmlRpc.java @@ -233,31 +233,27 @@ public class OpenSubtitlesXmlRpc { return subHashMap; } - @Deprecated public Map> guessMovie(Collection tags) throws XmlRpcFault { Map> results = new HashMap>(); - Map response = invoke("GuessMovie", token, tags); + Map response = invoke("GuessMovieFromString", token, tags); Object payload = response.get("data"); if (payload instanceof Map) { - Map>> guessMovieData = (Map>>) payload; - + Map>> dataByTag = (Map>>) payload; for (String tag : tags) { - List value = new ArrayList<>(); - - List> matches = guessMovieData.get(tag); - if (matches != null) { - for (Map match : matches) { + List value = new ArrayList(); + Map> data = dataByTag.get(tag); + if (data != null) { + Map match = data.get("BestGuess"); + if (match != null) { String name = String.valueOf(match.get("MovieName")); String kind = String.valueOf(match.get("MovieKind")); int imdbid = Integer.parseInt(String.valueOf(match.get("IDMovieIMDB"))); int year = Integer.parseInt(String.valueOf(match.get("MovieYear"))); - int score = Integer.parseInt(String.valueOf(match.get("score"))); - value.add(new SubtitleSearchResult(imdbid, name, year, kind, score)); + value.add(new SubtitleSearchResult(imdbid, name, year, kind, -1)); } } - results.put(tag, value); } }