diff --git a/source/net/sourceforge/filebot/WebServices.java b/source/net/sourceforge/filebot/WebServices.java index ebd75977..b9cb4ac3 100644 --- a/source/net/sourceforge/filebot/WebServices.java +++ b/source/net/sourceforge/filebot/WebServices.java @@ -11,6 +11,7 @@ import net.sourceforge.filebot.web.IMDbClient; import net.sourceforge.filebot.web.MovieIdentificationService; import net.sourceforge.filebot.web.OpenSubtitlesClient; import net.sourceforge.filebot.web.SerienjunkiesClient; +import net.sourceforge.filebot.web.SublightSubtitleClient; import net.sourceforge.filebot.web.SubsceneSubtitleClient; import net.sourceforge.filebot.web.SubtitleProvider; import net.sourceforge.filebot.web.TMDbClient; @@ -37,6 +38,7 @@ public final class WebServices { // subtitle dbs public static final OpenSubtitlesClient OpenSubtitles = new OpenSubtitlesClient(String.format("%s %s", getApplicationName(), getApplicationVersion())); public static final SubsceneSubtitleClient Subscene = new SubsceneSubtitleClient(); + public static final SublightSubtitleClient Sublight = new SublightSubtitleClient(); // fanart.tv public static final FanartTV FanartTV = new FanartTV(Settings.getApplicationProperty("fanart.tv.apikey")); @@ -53,12 +55,12 @@ public final class WebServices { public static SubtitleProvider[] getSubtitleProviders() { - return new SubtitleProvider[] { OpenSubtitles, Subscene }; + return new SubtitleProvider[] { OpenSubtitles, Sublight, Subscene }; } public static VideoHashSubtitleService[] getVideoHashSubtitleServices() { - return new VideoHashSubtitleService[] { OpenSubtitles }; + return new VideoHashSubtitleService[] { OpenSubtitles, Sublight }; } @@ -89,4 +91,27 @@ public final class WebServices { throw new UnsupportedOperationException(); } + + /** + * Initialize client settings from system properties + */ + static { + String[] osdbLogin = getLogin(System.getProperty("osdb.user")); + OpenSubtitles.setUser(osdbLogin[0], osdbLogin[1]); + + String[] sublightClientLogin = getLogin(System.getProperty("sublight.client")); + Sublight.setClient(sublightClientLogin[0], sublightClientLogin[1]); + + String[] sublightUserLogin = getLogin(System.getProperty("sublight.user")); + Sublight.setUser(sublightUserLogin[0], sublightUserLogin[1]); + } + + + private static String[] getLogin(String login) { + if (login == null) + return new String[] { "", "" }; + + return login.split(":", 2); + } + } diff --git a/source/net/sourceforge/filebot/web/OpenSubtitlesClient.java b/source/net/sourceforge/filebot/web/OpenSubtitlesClient.java index 49565d90..c9f2a19c 100644 --- a/source/net/sourceforge/filebot/web/OpenSubtitlesClient.java +++ b/source/net/sourceforge/filebot/web/OpenSubtitlesClient.java @@ -43,12 +43,21 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS private final OpenSubtitlesXmlRpc xmlrpc; + private String username = ""; + private String password = ""; + public OpenSubtitlesClient(String useragent) { this.xmlrpc = new OpenSubtitlesXmlRpc(useragent); } + public void setUser(String username, String password) { + this.username = username; + this.password = password; + } + + @Override public String getName() { return "OpenSubtitles"; @@ -255,7 +264,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS protected synchronized void login() throws Exception { if (!xmlrpc.isLoggedOn()) { - xmlrpc.loginAnonymous(); + xmlrpc.login(username, password, "en"); } logoutTimer.set(10, TimeUnit.MINUTES, true); diff --git a/source/net/sourceforge/filebot/web/SublightSubtitleClient.java b/source/net/sourceforge/filebot/web/SublightSubtitleClient.java index b99f3c05..302aaa88 100644 --- a/source/net/sourceforge/filebot/web/SublightSubtitleClient.java +++ b/source/net/sourceforge/filebot/web/SublightSubtitleClient.java @@ -7,7 +7,9 @@ import static java.util.Collections.*; import java.io.File; import java.io.IOException; +import java.math.BigInteger; import java.net.URI; +import java.security.MessageDigest; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -50,17 +52,13 @@ public class SublightSubtitleClient implements SubtitleProvider, VideoHashSubtit private final ClientInfo clientInfo = new ClientInfo(); + private String username; + private String passwordHash; + private SublightSoap webservice; - private String session; - public SublightSubtitleClient(String clientIdentity, String apikey) { - clientInfo.setClientId(clientIdentity); - clientInfo.setApiKey(apikey); - } - - @Override public String getName() { return "Sublight"; @@ -356,7 +354,35 @@ public class SublightSubtitleClient implements SubtitleProvider, VideoHashSubtit } + public synchronized void setClient(String id, String key) { + clientInfo.setClientId(id); + clientInfo.setApiKey(key); + + } + + + public synchronized void setUser(String username, String password) { + this.username = username; + this.passwordHash = getPasswordHash(password); + } + + + public String getPasswordHash(String password) { + try { + MessageDigest digest = MessageDigest.getInstance("MD5"); + digest.update(password.getBytes("UTF-16LE")); + return String.format("%032x", new BigInteger(1, digest.digest())); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected synchronized void login() throws WebServiceException { + if (clientInfo.getClientId() == null || clientInfo.getClientId().isEmpty()) { + throw new IllegalStateException("Sublight login has not been configured"); + } + if (webservice == null) { // lazy initialize because all the JAX-WS class loading can take quite some time webservice = new Sublight().getSublightSoap(); @@ -370,7 +396,11 @@ public class SublightSubtitleClient implements SubtitleProvider, VideoHashSubtit Holder session = new Holder(); Holder error = new Holder(); - webservice.logInAnonymous4(clientInfo, args, session, null, error); + if (username == null || username.isEmpty()) { + webservice.logInAnonymous4(clientInfo, args, session, null, error); + } else { + webservice.logIn6(username, passwordHash, clientInfo, args, session, null, null, null, null, error); + } // abort if something went wrong checkError(error); diff --git a/test/net/sourceforge/filebot/web/SublightSubtitleClientTest.java b/test/net/sourceforge/filebot/web/SublightSubtitleClientTest.java index b0c995b1..45e04da0 100644 --- a/test/net/sourceforge/filebot/web/SublightSubtitleClientTest.java +++ b/test/net/sourceforge/filebot/web/SublightSubtitleClientTest.java @@ -18,12 +18,13 @@ import net.sublight.webservice.Subtitle; public class SublightSubtitleClientTest { - private static SublightSubtitleClient client = new SublightSubtitleClient(null, null); // BROKEN SINCE SUBLIGHT RESTRICTED API ACCESS + private static SublightSubtitleClient client = new SublightSubtitleClient(); @BeforeClass public static void login() { - // login manually + client.setClient("SublightCmd", "12c72276-b95f-4144-bb2a-879775c71437"); + client.setUser("filebot-test", "correcthorsebatterystaple"); client.login(); }