mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-23 16:28:51 -05:00
Check Download-Quota HTTP header when downloading subtitles and abort if quota has been reached.
This commit is contained in:
parent
c79896f827
commit
e4e5c01cd7
@ -391,7 +391,6 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
|
||||
if (!xmlrpc.isLoggedOn()) {
|
||||
xmlrpc.login(username, password, "en");
|
||||
}
|
||||
|
||||
logoutTimer.set(10, TimeUnit.MINUTES, true);
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -91,6 +91,9 @@ public class OpenSubtitlesXmlRpc {
|
||||
}
|
||||
|
||||
public List<OpenSubtitlesSubtitleDescriptor> searchSubtitles(Collection<Query> queryList) throws XmlRpcFault {
|
||||
// abort immediately if download quota has been exceeded
|
||||
OpenSubtitlesSubtitleDescriptor.checkDownloadQuota();
|
||||
|
||||
List<OpenSubtitlesSubtitleDescriptor> subtitles = new ArrayList<OpenSubtitlesSubtitleDescriptor>();
|
||||
Map<?, ?> response = invoke("SearchSubtitles", token, queryList);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user