* enabled Sublight, but has to be configured via system property sublight.user=name:pwd

This commit is contained in:
Reinhard Pointner 2012-07-16 09:58:18 +00:00
parent dfc9f118e8
commit 03d299c67b
4 changed files with 78 additions and 13 deletions

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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<String> session = new Holder<String>();
Holder<String> error = new Holder<String>();
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);

View File

@ -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();
}