* added OpenSubtitles xmlrpc methods: TryUploadSubtitles, UploadSubtitles, DetectLanguage, CheckSubHash, CheckMovieHash

This commit is contained in:
Reinhard Pointner 2009-07-13 13:02:04 +00:00
parent b4f9a3ed24
commit 48cac46fef
3 changed files with 391 additions and 142 deletions

View File

@ -21,46 +21,46 @@ import net.sourceforge.tuned.FileUtilities;
*/ */
public class OpenSubtitlesSubtitleDescriptor implements SubtitleDescriptor { public class OpenSubtitlesSubtitleDescriptor implements SubtitleDescriptor {
private final Map<Property, String> properties;
public static enum Property { public static enum Property {
IDSubMovieFile,
MovieHash,
MovieByteSize,
MovieTimeMS,
MovieFrames,
IDSubtitleFile,
SubFileName,
SubActualCD,
SubSize,
SubHash,
IDSubtitle, IDSubtitle,
UserID, IDSubtitleFile,
SubLanguageID, IDSubMovieFile,
SubFormat,
SubSumCD,
SubAuthorComment,
SubAddDate,
SubBad,
SubRating,
SubDownloadsCnt,
MovieReleaseName,
IDMovie, IDMovie,
IDMovieImdb, IDMovieImdb,
SubFileName,
SubFormat,
SubHash,
SubSize,
MovieHash,
MovieByteSize,
MovieName, MovieName,
MovieNameEng, MovieNameEng,
MovieYear, MovieYear,
MovieReleaseName,
MovieTimeMS,
MovieImdbRating, MovieImdbRating,
UserNickName, SubLanguageID,
ISO639, ISO639,
LanguageName, LanguageName,
UserID,
UserNickName,
SubAddDate,
SubAuthorComment,
SubComments,
SubDownloadsCnt,
SubRating,
SubBad,
SubActualCD,
SubSumCD,
MatchedBy,
SubtitlesLink,
SubDownloadLink, SubDownloadLink,
ZipDownloadLink; ZipDownloadLink;
public static <V> EnumMap<Property, V> asEnumMap(Map<String, V> stringMap) { public static <V> EnumMap<Property, V> asEnumMap(Map<String, V> stringMap) {
EnumMap<Property, V> enumMap = new EnumMap<Property, V>(Property.class); EnumMap<Property, V> enumMap = new EnumMap<Property, V>(Property.class);
// copy entry set to enum map
for (Entry<String, V> entry : stringMap.entrySet()) { for (Entry<String, V> entry : stringMap.entrySet()) {
try { try {
enumMap.put(Property.valueOf(entry.getKey()), entry.getValue()); enumMap.put(Property.valueOf(entry.getKey()), entry.getValue());
@ -74,8 +74,11 @@ public class OpenSubtitlesSubtitleDescriptor implements SubtitleDescriptor {
} }
private final Map<Property, String> properties;
public OpenSubtitlesSubtitleDescriptor(Map<Property, String> properties) { public OpenSubtitlesSubtitleDescriptor(Map<Property, String> properties) {
this.properties = new EnumMap<Property, String>(properties); this.properties = properties;
} }
@ -107,6 +110,16 @@ public class OpenSubtitlesSubtitleDescriptor implements SubtitleDescriptor {
} }
public String getMovieHash() {
return getProperty(Property.MovieHash);
}
public long getMovieByteSize() {
return Long.parseLong(getProperty(Property.MovieByteSize));
}
@Override @Override
public ByteBuffer fetch() throws Exception { public ByteBuffer fetch() throws Exception {
URL resource = new URL(getProperty(Property.SubDownloadLink)); URL resource = new URL(getProperty(Property.SubDownloadLink));

View File

@ -5,19 +5,20 @@ package net.sourceforge.filebot.web;
import static java.util.Collections.*; import static java.util.Collections.*;
import static net.sourceforge.tuned.StringUtilities.*; import static net.sourceforge.tuned.StringUtilities.*;
import java.io.UnsupportedEncodingException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Scanner; import java.util.Scanner;
import java.util.logging.Level; import java.util.Map.Entry;
import java.util.logging.Logger; import java.util.zip.DeflaterInputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import redstone.xmlrpc.XmlRpcClient; import redstone.xmlrpc.XmlRpcClient;
import redstone.xmlrpc.XmlRpcException; import redstone.xmlrpc.XmlRpcException;
@ -25,15 +26,12 @@ import redstone.xmlrpc.XmlRpcFault;
import redstone.xmlrpc.util.Base64; import redstone.xmlrpc.util.Base64;
import net.sourceforge.filebot.web.OpenSubtitlesSubtitleDescriptor.Property; import net.sourceforge.filebot.web.OpenSubtitlesSubtitleDescriptor.Property;
import net.sourceforge.tuned.ByteBufferInputStream;
import net.sourceforge.tuned.ByteBufferOutputStream;
/**
* Client for the OpenSubtitles XML-RPC API.
*/
public class OpenSubtitlesXmlRpc { public class OpenSubtitlesXmlRpc {
private final String url = "http://www.opensubtitles.org/xml-rpc";
private final String useragent; private final String useragent;
private String token; private String token;
@ -46,8 +44,6 @@ public class OpenSubtitlesXmlRpc {
/** /**
* Login as anonymous user * Login as anonymous user
*
* @throws XmlRpcFault
*/ */
public void loginAnonymous() throws XmlRpcFault { public void loginAnonymous() throws XmlRpcFault {
login("", ""); login("", "");
@ -57,9 +53,8 @@ public class OpenSubtitlesXmlRpc {
/** /**
* Login as user and use English as language * Login as user and use English as language
* *
* @param username * @param username username (blank for anonymous user)
* @param password * @param password password (blank for anonymous user)
* @throws XmlRpcFault
*/ */
public void login(String username, String password) throws XmlRpcFault { public void login(String username, String password) throws XmlRpcFault {
login(username, password, "en"); login(username, password, "en");
@ -72,40 +67,33 @@ public class OpenSubtitlesXmlRpc {
* *
* @param username username (blank for anonymous user) * @param username username (blank for anonymous user)
* @param password password (blank for anonymous user) * @param password password (blank for anonymous user)
* @param language <a * @param language ISO639 2-letter codes as language and later communication will be done in this language if
* href="http://en.wikipedia.org/wiki/List_of_ISO_639-2_codes">ISO639</a> * applicable (error codes and so on).
* 2-letter codes as language and later communication will be done in this
* language if applicable (error codes and so on).
*/ */
@SuppressWarnings("unchecked")
public synchronized void login(String username, String password, String language) throws XmlRpcFault { public synchronized void login(String username, String password, String language) throws XmlRpcFault {
Map<String, String> response = (Map<String, String>) invoke("LogIn", username, password, language, useragent); Map<?, ?> response = invoke("LogIn", username, password, language, useragent);
checkStatus(response.get("status"));
token = response.get("token"); // set session token
token = response.get("token").toString();
} }
/** /**
* This will logout user (ends session id). Good call this function is before ending * This will logout user (ends session id). Call this function is before closing the client program.
* (closing) clients program.
*
* @throws XmlRpcFault
*/ */
public synchronized void logout() throws XmlRpcFault { public synchronized void logout() throws XmlRpcFault {
try { try {
invoke("LogOut", token); invoke("LogOut", token);
} catch (XmlRpcFault e) {
// anonymous users will always get a 401 Unauthorized when trying to logout // anonymous users will always get an 401 Unauthorized when trying to logout,
// do not check status for logout response // so we ignore the status of the logout response
// checkStatus(response.get("status"));
} finally { } finally {
token = null; token = null;
} }
} }
public synchronized boolean isLoggedOn() { public boolean isLoggedOn() {
return token != null; return token != null;
} }
@ -117,35 +105,19 @@ public class OpenSubtitlesXmlRpc {
public List<OpenSubtitlesSubtitleDescriptor> searchSubtitles(int imdbid, String... sublanguageids) throws XmlRpcFault { public List<OpenSubtitlesSubtitleDescriptor> searchSubtitles(int imdbid, String... sublanguageids) throws XmlRpcFault {
return searchSubtitles(null, null, imdbid, sublanguageids); return searchSubtitles(singleton(Query.forImdbId(imdbid, sublanguageids)));
}
public List<OpenSubtitlesSubtitleDescriptor> searchSubtitles(String moviehash, long moviebytesize, String... sublanguageids) throws XmlRpcFault {
return searchSubtitles(moviehash, moviebytesize, null, sublanguageids);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected List<OpenSubtitlesSubtitleDescriptor> searchSubtitles(String moviehash, Long moviebytesize, Integer imdbid, String... sublanguageids) throws XmlRpcFault { public List<OpenSubtitlesSubtitleDescriptor> searchSubtitles(Collection<Query> queryList) throws XmlRpcFault {
ParameterMap query = new ParameterMap(4); Map<?, ?> response = invoke("SearchSubtitles", token, queryList);
// put parameters, but ignore null or empty values
query.put("moviehash", moviehash);
query.put("moviebytesize", moviebytesize);
query.put("imdbid", imdbid);
query.put("sublanguageid", join(sublanguageids, ","));
Map<String, List<Map<String, String>>> response = (Map<String, List<Map<String, String>>>) invoke("SearchSubtitles", token, singletonList(query));
List<Map<String, String>> subtitleData = (List<Map<String, String>>) response.get("data");
List<OpenSubtitlesSubtitleDescriptor> subtitles = new ArrayList<OpenSubtitlesSubtitleDescriptor>(); List<OpenSubtitlesSubtitleDescriptor> subtitles = new ArrayList<OpenSubtitlesSubtitleDescriptor>();
try { for (Map<String, String> propertyMap : subtitleData) {
for (Map<String, String> subtitleData : response.get("data")) { subtitles.add(new OpenSubtitlesSubtitleDescriptor(Property.asEnumMap(propertyMap)));
subtitles.add(new OpenSubtitlesSubtitleDescriptor(Property.asEnumMap(subtitleData)));
}
} catch (ClassCastException e) {
// error response, no subtitles, ignore
} }
return subtitles; return subtitles;
@ -154,42 +126,115 @@ public class OpenSubtitlesXmlRpc {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public List<MovieDescriptor> searchMoviesOnIMDB(String query) throws XmlRpcFault { public List<MovieDescriptor> searchMoviesOnIMDB(String query) throws XmlRpcFault {
Map<String, List<Map<String, String>>> response = (Map<String, List<Map<String, String>>>) invoke("SearchMoviesOnIMDB", token, query); Map<?, ?> response = invoke("SearchMoviesOnIMDB", token, query);
List<Map<String, String>> movieData = (List<Map<String, String>>) response.get("data");
List<MovieDescriptor> movies = new ArrayList<MovieDescriptor>(); List<MovieDescriptor> movies = new ArrayList<MovieDescriptor>();
for (Map<String, String> movie : response.get("data")) { for (Map<String, String> movie : movieData) {
try { // get non-aka title (aka titles are separated by Â)
// get non-aka title (aka titles are separated by Â) Scanner titleScanner = new Scanner(movie.get("title")).useDelimiter("\u00C2");
Scanner titleScanner = new Scanner(movie.get("title")).useDelimiter("\u00C2");
movies.add(new MovieDescriptor(titleScanner.next().trim(), Integer.parseInt(movie.get("id"))));
movies.add(new MovieDescriptor(titleScanner.next(), Integer.parseInt(movie.get("id"))));
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, e.getMessage(), e);
}
} }
return movies; return movies;
} }
public TryUploadResponse tryUploadSubtitles(SubFile subtitle) throws XmlRpcFault {
return tryUploadSubtitles(singleton(subtitle));
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Collection<String> detectLanguage(String text) throws XmlRpcFault { public TryUploadResponse tryUploadSubtitles(Collection<SubFile> subtitles) throws XmlRpcFault {
try { Map<String, SubFile> struct = new HashMap<String, SubFile>();
// base64 encoded text
String parameter = new String(Base64.encode(text.getBytes("utf-8"))); // put cd1, cd2, ...
for (SubFile cd : subtitles) {
Map<String, Map<String, String>> response = (Map<String, Map<String, String>>) invoke("DetectLanguage", token, new Object[] { parameter }); struct.put(String.format("cd%d", struct.size() + 1), cd);
if (response.containsKey("data")) {
return response.get("data").values();
}
return Collections.emptySet();
} catch (UnsupportedEncodingException e) {
// will not happen
throw new RuntimeException(e);
} }
Map<?, ?> response = invoke("TryUploadSubtitles", token, struct);
boolean uploadRequired = response.get("alreadyindb").equals("0");
Map<String, String> subtitleData = (Map<String, String>) response.get("data");
return new TryUploadResponse(uploadRequired, Property.asEnumMap(subtitleData));
}
public URI uploadSubtitles(BaseInfo baseInfo, SubFile subtitle) throws XmlRpcFault {
return uploadSubtitles(baseInfo, singleton(subtitle));
}
public URI uploadSubtitles(BaseInfo baseInfo, Collection<SubFile> subtitles) throws XmlRpcFault {
Map<String, Object> struct = new HashMap<String, Object>();
// put cd1, cd2, ...
for (SubFile cd : subtitles) {
struct.put(String.format("cd%d", struct.size() + 1), cd);
}
// put baseinfo
struct.put("baseinfo", baseInfo);
Map<?, ?> response = invoke("UploadSubtitles", token, struct);
// subtitle link
return URI.create(response.get("data").toString());
}
@SuppressWarnings("unchecked")
public List<String> detectLanguage(ByteBuffer data) throws XmlRpcFault {
// compress and base64 encode
String parameter = encodeData(data);
Map<String, Map<String, String>> response = (Map<String, Map<String, String>>) invoke("DetectLanguage", token, singleton(parameter));
List<String> languages = new ArrayList<String>(2);
if (response.containsKey("data")) {
languages.addAll(response.get("data").values());
}
return languages;
}
@SuppressWarnings("unchecked")
public Map<String, Integer> checkSubHash(Collection<String> hashes) throws XmlRpcFault {
Map<?, ?> response = invoke("CheckSubHash", token, hashes);
Map<String, ?> subHashData = (Map<String, ?>) response.get("data");
Map<String, Integer> subHashMap = new HashMap<String, Integer>();
for (Entry<String, ?> entry : subHashData.entrySet()) {
// non-existing subtitles are represented as Integer 0, not String "0"
subHashMap.put(entry.getKey(), Integer.parseInt(entry.getValue().toString()));
}
return subHashMap;
}
@SuppressWarnings("unchecked")
public Map<String, Map<Property, String>> checkMovieHash(Collection<String> hashes) throws XmlRpcFault {
Map<?, ?> response = invoke("CheckMovieHash", token, hashes);
Map<String, ?> movieHashData = (Map<String, ?>) response.get("data");
Map<String, Map<Property, String>> movieHashMap = new HashMap<String, Map<Property, String>>();
for (Entry<String, ?> entry : movieHashData.entrySet()) {
// empty associative arrays are deserialized as array, not as map
if (entry.getValue() instanceof Map) {
movieHashMap.put(entry.getKey(), Property.asEnumMap((Map<String, String>) entry.getValue()));
}
}
return movieHashMap;
} }
@ -212,24 +257,52 @@ public class OpenSubtitlesXmlRpc {
} }
@SuppressWarnings("unchecked") public void noOperation() throws XmlRpcFault {
public boolean noOperation() { invoke("NoOperation", token);
}
protected Map<?, ?> invoke(String method, Object... arguments) throws XmlRpcFault {
try { try {
Map<String, String> response = (Map<String, String>) invoke("NoOperation", token); XmlRpcClient rpc = new XmlRpcClient(getXmlRpcUrl(), false);
checkStatus(response.get("status"));
return true; Map<?, ?> response = (Map<?, ?>) rpc.invoke(method, arguments);
} catch (Exception e) { checkResponse(response);
return false;
return response;
} catch (XmlRpcFault e) {
// invalidate session token if session has expired
if (e.getErrorCode() == 406)
token = null;
// rethrow exception
throw e;
} }
} }
private Object invoke(String method, Object... arguments) throws XmlRpcFault { protected URL getXmlRpcUrl() {
try { try {
XmlRpcClient rpc = new XmlRpcClient(url, false); return new URL("http://www.opensubtitles.org/xml-rpc");
return rpc.invoke(method, arguments);
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
// will never happen
throw new RuntimeException(e);
}
}
protected static String encodeData(ByteBuffer data) {
try {
DeflaterInputStream compressedDataStream = new DeflaterInputStream(new ByteBufferInputStream(data));
// compress data
ByteBufferOutputStream buffer = new ByteBufferOutputStream(data.remaining());
buffer.transferFully(compressedDataStream);
// base64 encode
return new String(Base64.encode(buffer.getByteArray()));
} catch (IOException e) {
// will never happen
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
@ -241,42 +314,144 @@ public class OpenSubtitlesXmlRpc {
* @param status status code and message (e.g. 200 OK, 401 Unauthorized, ...) * @param status status code and message (e.g. 200 OK, 401 Unauthorized, ...)
* @throws XmlRpcFault thrown if status code is not OK * @throws XmlRpcFault thrown if status code is not OK
*/ */
private void checkStatus(String status) throws XmlRpcFault { protected static void checkResponse(Map<?, ?> response) throws XmlRpcFault {
if (status.equals("200 OK")) String status = (String) response.get("status");
// if there is no status at all, assume everything was OK
if (status == null || status.equals("200 OK")) {
return; return;
}
Matcher m = Pattern.compile("(\\d+).*").matcher(status); try {
throw new XmlRpcFault(new Scanner(status).nextInt(), status);
if (!m.matches()) } catch (NoSuchElementException e) {
throw new XmlRpcException("Illegal status code: " + status); throw new XmlRpcException("Illegal status code: " + status);
}
throw new XmlRpcFault(Integer.parseInt(m.group(1)), status);
} }
private static class ParameterMap extends HashMap<String, String> { public static final class Query extends HashMap<String, Object> {
public ParameterMap(int initialCapacity) { private Query(String imdbid, String... sublanguageids) {
super(initialCapacity); put("imdbid", imdbid);
put("sublanguageid", join(sublanguageids, ","));
} }
@Override private Query(String moviehash, String moviebytesize, String... sublanguageids) {
public String put(String key, String value) { put("moviehash", moviehash);
if (value != null && !value.isEmpty()) { put("moviebytesize", moviebytesize);
return super.put(key, value); put("sublanguageid", join(sublanguageids, ","));
}
return null;
} }
public String put(String key, Object value) { public static Query forHash(String moviehash, long moviebytesize, String... sublanguageids) {
if (value != null) { return new Query(moviehash, Long.toString(moviebytesize), sublanguageids);
return put(key, value.toString()); }
}
return null; public static Query forImdbId(int imdbid, String... sublanguageids) {
return new Query(Integer.toString(imdbid), sublanguageids);
}
}
public static final class BaseInfo extends HashMap<String, Object> {
public void setIDMovieImdb(int imdb) {
put("idmovieimdb", Integer.toString(imdb));
}
public void setSubLanguageID(String sublanguageid) {
put("sublanguageid", sublanguageid);
}
public void setMovieReleaseName(String moviereleasename) {
put("moviereleasename", moviereleasename);
}
public void setMovieAka(String movieaka) {
put("movieaka", movieaka);
}
public void setSubAuthorComment(String subauthorcomment) {
put("subauthorcomment", subauthorcomment);
}
}
public static final class SubFile extends HashMap<String, Object> {
public void setSubHash(String subhash) {
put("subhash", subhash);
}
public void setSubFileName(String subfilename) {
put("subfilename", subfilename);
}
public void setMovieHash(String moviehash) {
put("moviehash", moviehash);
}
public void setMovieByteSize(long moviebytesize) {
put("moviebytesize", Long.toString(moviebytesize));
}
public void setMovieTimeMS(int movietimems) {
put("movietimems", movietimems);
}
public void setMovieFrames(int movieframes) {
put("movieframes", movieframes);
}
public void setMovieFPS(double moviefps) {
put("moviefps", moviefps);
}
public void setMovieFileName(String moviefilename) {
put("moviefilename", moviefilename);
}
public void setSubContent(ByteBuffer data) {
put("subcontent", encodeData(data));
}
}
public static final class TryUploadResponse {
private final boolean uploadRequired;
private final Map<Property, String> subtitleData;
private TryUploadResponse(boolean uploadRequired, Map<Property, String> subtitleData) {
this.uploadRequired = uploadRequired;
this.subtitleData = subtitleData;
}
public boolean isUploadRequired() {
return uploadRequired;
}
public Map<Property, String> getSubtitleData() {
return subtitleData;
} }
} }

View File

@ -2,15 +2,21 @@
package net.sourceforge.filebot.web; package net.sourceforge.filebot.web;
import static java.util.Collections.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.List; import java.util.List;
import java.util.Map;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import net.sourceforge.filebot.web.OpenSubtitlesSubtitleDescriptor.Property;
import net.sourceforge.filebot.web.OpenSubtitlesXmlRpc.Query;
public class OpenSubtitlesXmlRpcTest { public class OpenSubtitlesXmlRpcTest {
@ -56,8 +62,9 @@ public class OpenSubtitlesXmlRpcTest {
OpenSubtitlesSubtitleDescriptor sample = list.get(75); OpenSubtitlesSubtitleDescriptor sample = list.get(75);
assertTrue(sample.getName().startsWith("Wonderfalls")); assertEquals("\"Wonderfalls\"", sample.getProperty(Property.MovieName));
assertEquals("Hungarian", sample.getLanguageName()); assertEquals("Hungarian", sample.getProperty(Property.LanguageName));
assertEquals("imdbid", sample.getProperty(Property.MatchedBy));
// check size // check size
assertTrue(list.size() > 70); assertTrue(list.size() > 70);
@ -65,8 +72,62 @@ public class OpenSubtitlesXmlRpcTest {
@Test @Test
public void getSubtitleListMovieHash() { public void getSubtitleListMovieHash() throws Exception {
//TODO not implemented yet List<OpenSubtitlesSubtitleDescriptor> list = xmlrpc.searchSubtitles(singleton(Query.forHash("2bba5c34b007153b", 717565952, "eng")));
OpenSubtitlesSubtitleDescriptor sample = list.get(0);
assertEquals("firefly.s01e01.serenity.pilot.dvdrip.xvid.srt", sample.getProperty(Property.SubFileName));
assertEquals("English", sample.getProperty(Property.LanguageName));
assertEquals("moviehash", sample.getProperty(Property.MatchedBy));
}
@Test
public void checkSubHash() throws Exception {
Map<String, Integer> subHashMap = xmlrpc.checkSubHash(singleton("e12715f466ee73c86694b7ab9f311285"));
assertEquals("247060", subHashMap.values().iterator().next().toString());
assertTrue(1 == subHashMap.size());
}
@Test
public void checkSubHashInvalid() throws Exception {
Map<String, Integer> subHashMap = xmlrpc.checkSubHash(singleton("0123456789abcdef0123456789abcdef"));
assertEquals("0", subHashMap.values().iterator().next().toString());
assertTrue(1 == subHashMap.size());
}
@Test
public void checkMovieHash() throws Exception {
Map<String, Map<Property, String>> movieHashMap = xmlrpc.checkMovieHash(singleton("2bba5c34b007153b"));
Map<Property, String> movie = movieHashMap.values().iterator().next();
assertEquals("\"Firefly\"", movie.get(Property.MovieName));
assertEquals("2002", movie.get(Property.MovieYear));
}
@Test
public void checkMovieHashInvalid() throws Exception {
Map<String, Map<Property, String>> movieHashMap = xmlrpc.checkMovieHash(singleton("0123456789abcdef"));
// no movie info
assertTrue(movieHashMap.isEmpty());
}
@Test
public void detectLanguage() throws Exception {
String text = "Only those that are prepared to fire should be fired at.";
List<String> languages = xmlrpc.detectLanguage(Charset.forName("utf-8").encode(text));
assertEquals("eng", languages.get(0));
assertTrue(1 == languages.size());
} }