1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-08-13 17:03:45 -04:00

* only allow 1 single concurrent connection at any time (to reduce abuse)

This commit is contained in:
Reinhard Pointner 2014-10-28 16:13:04 +00:00
parent f7436eee9e
commit f14aa89625
3 changed files with 13 additions and 6 deletions

View File

@ -290,7 +290,7 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
try {
if (osdbUser.getText().length() > 0 && osdbPass.getPassword().length > 0) {
OpenSubtitlesClient osdb = new OpenSubtitlesClient(String.format("%s %s", getApplicationName(), getApplicationVersion()));
OpenSubtitlesClient osdb = new OpenSubtitlesClient(String.format("%s v%s", getApplicationName(), getApplicationVersion()));
osdb.setUser(osdbUser.getText(), new String(osdbPass.getPassword()));
osdb.login();
}

View File

@ -55,7 +55,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
private String password = "";
public OpenSubtitlesClient(String useragent) {
this.xmlrpc = new OpenSubtitlesXmlRpcWithRetry(useragent, 2, 3000);
this.xmlrpc = new OpenSubtitlesXmlRpcWithRetryAndFloodLimit(useragent, 2, 3000);
}
public synchronized void setUser(String username, String password) {
@ -674,15 +674,16 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
return null;
}
}
protected static class OpenSubtitlesXmlRpcWithRetry extends OpenSubtitlesXmlRpc {
protected static class OpenSubtitlesXmlRpcWithRetryAndFloodLimit extends OpenSubtitlesXmlRpc {
private final Object lock = new Object();
private int retryCountLimit;
private long retryWaitTime;
public OpenSubtitlesXmlRpcWithRetry(String useragent, int retryCountLimit, long retryWaitTime) {
public OpenSubtitlesXmlRpcWithRetryAndFloodLimit(String useragent, int retryCountLimit, long retryWaitTime) {
super(useragent);
this.retryCountLimit = retryCountLimit;
this.retryWaitTime = retryWaitTime;
@ -695,7 +696,11 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
if (i > 0) {
Thread.sleep(retryWaitTime);
}
return super.invoke(method, arguments);
// only allow 1 single concurrent connection at any time (to reduce abuse)
synchronized (lock) {
return super.invoke(method, arguments);
}
} catch (XmlRpcException e) {
IOException ioException = ExceptionUtilities.findCause(e, IOException.class);
if (ioException == null || i >= 0 && i >= retryCountLimit) {

View File

@ -112,6 +112,7 @@ public class OpenSubtitlesXmlRpc {
}
@SuppressWarnings("unchecked")
@Deprecated
public List<Movie> searchMoviesOnIMDB(String query) throws XmlRpcFault {
Map<?, ?> response = invoke("SearchMoviesOnIMDB", token, query);
@ -265,6 +266,7 @@ public class OpenSubtitlesXmlRpc {
}
@SuppressWarnings("unchecked")
@Deprecated
public Movie getIMDBMovieDetails(int imdbid) throws XmlRpcFault {
Map<?, ?> response = invoke("GetIMDBMovieDetails", token, imdbid);