diff --git a/source/net/filebot/web/OpenSubtitlesClient.java b/source/net/filebot/web/OpenSubtitlesClient.java index 23d99162..1a0ec2a8 100644 --- a/source/net/filebot/web/OpenSubtitlesClient.java +++ b/source/net/filebot/web/OpenSubtitlesClient.java @@ -391,7 +391,6 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS if (!xmlrpc.isLoggedOn()) { xmlrpc.login(username, password, "en"); } - logoutTimer.set(10, TimeUnit.MINUTES, true); } diff --git a/source/net/filebot/web/OpenSubtitlesSubtitleDescriptor.java b/source/net/filebot/web/OpenSubtitlesSubtitleDescriptor.java index 3391e1da..b7720099 100644 --- a/source/net/filebot/web/OpenSubtitlesSubtitleDescriptor.java +++ b/source/net/filebot/web/OpenSubtitlesSubtitleDescriptor.java @@ -117,20 +117,28 @@ public class OpenSubtitlesSubtitleDescriptor implements SubtitleDescriptor, Seri private static int DOWNLOAD_QUOTA = 1000; + public static synchronized void checkDownloadQuota() throws IllegalStateException { + if (DOWNLOAD_QUOTA <= 0) { + throw new IllegalStateException("Download-Quota has been exceeded"); + } + } + + private static synchronized void setAndCheckDownloadQuota(int quota) throws IllegalStateException { + DOWNLOAD_QUOTA = quota; + checkDownloadQuota(); + } + @Override public ByteBuffer fetch() throws Exception { - if (DOWNLOAD_QUOTA <= 0) { - throw new IOException("Download-Quota has been exceeded"); - } + checkDownloadQuota(); URLConnection c = new URL(getProperty(Property.SubDownloadLink)).openConnection(); try (InputStream in = c.getInputStream()) { // check download quota String quota = c.getHeaderField("Download-Quota"); if (quota != null) { - if ((DOWNLOAD_QUOTA = Integer.parseInt(quota)) <= 0) { - throw new IOException("Download-Quota has been exceeded"); - } + setAndCheckDownloadQuota(Integer.parseInt(quota)); + debug.finest(format("Download-Quota: %d", DOWNLOAD_QUOTA)); } diff --git a/source/net/filebot/web/OpenSubtitlesXmlRpc.java b/source/net/filebot/web/OpenSubtitlesXmlRpc.java index 320915cc..2a370272 100644 --- a/source/net/filebot/web/OpenSubtitlesXmlRpc.java +++ b/source/net/filebot/web/OpenSubtitlesXmlRpc.java @@ -91,6 +91,9 @@ public class OpenSubtitlesXmlRpc { } public List searchSubtitles(Collection queryList) throws XmlRpcFault { + // abort immediately if download quota has been exceeded + OpenSubtitlesSubtitleDescriptor.checkDownloadQuota(); + List subtitles = new ArrayList(); Map response = invoke("SearchSubtitles", token, queryList);