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

* make OpenSubtitlesClient fault tolerant via automatic retries

* try for exact matches in internal movie index first before running a query
This commit is contained in:
Reinhard Pointner 2014-01-06 20:41:59 +00:00
parent fede643336
commit f902b04dee
2 changed files with 38 additions and 3 deletions

View File

@ -234,8 +234,8 @@ def detectSeriesName(files, locale = Locale.ENGLISH) {
return names == null || names.isEmpty() ? null : names.toList()[0]
}
def detectMovie(File movieFile, strict = true, queryLookupService = TheMovieDB, hashLookupService = OpenSubtitles, locale = Locale.ENGLISH) {
def movies = MediaDetection.detectMovie(movieFile, hashLookupService, queryLookupService, locale, strict)
def detectMovie(File file, strict = true, queryLookupService = TheMovieDB, hashLookupService = OpenSubtitles, locale = Locale.ENGLISH) {
def movies = MediaDetection.matchMovieName([file.name, file.parentFile.name], true, 0) ?: MediaDetection.detectMovie(file, hashLookupService, queryLookupService, locale, strict)
return movies == null || movies.isEmpty() ? null : movies.toList()[0]
}

View File

@ -38,8 +38,10 @@ import net.sourceforge.filebot.web.OpenSubtitlesXmlRpc.BaseInfo;
import net.sourceforge.filebot.web.OpenSubtitlesXmlRpc.Query;
import net.sourceforge.filebot.web.OpenSubtitlesXmlRpc.SubFile;
import net.sourceforge.filebot.web.OpenSubtitlesXmlRpc.TryUploadResponse;
import net.sourceforge.tuned.ExceptionUtilities;
import net.sourceforge.tuned.Timer;
import redstone.xmlrpc.XmlRpcException;
import redstone.xmlrpc.XmlRpcFault;
/**
* SubtitleClient for OpenSubtitles.
@ -52,7 +54,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
private String password = "";
public OpenSubtitlesClient(String useragent) {
this.xmlrpc = new OpenSubtitlesXmlRpc(useragent);
this.xmlrpc = new OpenSubtitlesXmlRpcWithRetry(useragent, 2, 3000);
}
public synchronized void setUser(String username, String password) {
@ -576,4 +578,37 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
}
protected static class OpenSubtitlesXmlRpcWithRetry extends OpenSubtitlesXmlRpc {
private int retryCountLimit;
private long retryWaitTime;
public OpenSubtitlesXmlRpcWithRetry(String useragent, int retryCountLimit, long retryWaitTime) {
super(useragent);
this.retryCountLimit = retryCountLimit;
this.retryWaitTime = retryWaitTime;
}
@Override
protected Map<?, ?> invoke(String method, Object... arguments) throws XmlRpcFault {
for (int i = 0; retryCountLimit < 0 || i <= retryCountLimit; i++) {
try {
if (i > 0) {
Thread.sleep(retryWaitTime);
}
return super.invoke(method, arguments);
} catch (XmlRpcFault | XmlRpcException e) {
IOException ioException = ExceptionUtilities.findCause(e, IOException.class);
if (ioException == null || i >= 0 && i >= retryCountLimit) {
throw e;
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
return null; // can't happen
}
}
}