mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-24 08:48: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()) {
|
if (!xmlrpc.isLoggedOn()) {
|
||||||
xmlrpc.login(username, password, "en");
|
xmlrpc.login(username, password, "en");
|
||||||
}
|
}
|
||||||
|
|
||||||
logoutTimer.set(10, TimeUnit.MINUTES, true);
|
logoutTimer.set(10, TimeUnit.MINUTES, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,20 +117,28 @@ public class OpenSubtitlesSubtitleDescriptor implements SubtitleDescriptor, Seri
|
|||||||
|
|
||||||
private static int DOWNLOAD_QUOTA = 1000;
|
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
|
@Override
|
||||||
public ByteBuffer fetch() throws Exception {
|
public ByteBuffer fetch() throws Exception {
|
||||||
if (DOWNLOAD_QUOTA <= 0) {
|
checkDownloadQuota();
|
||||||
throw new IOException("Download-Quota has been exceeded");
|
|
||||||
}
|
|
||||||
|
|
||||||
URLConnection c = new URL(getProperty(Property.SubDownloadLink)).openConnection();
|
URLConnection c = new URL(getProperty(Property.SubDownloadLink)).openConnection();
|
||||||
try (InputStream in = c.getInputStream()) {
|
try (InputStream in = c.getInputStream()) {
|
||||||
// check download quota
|
// check download quota
|
||||||
String quota = c.getHeaderField("Download-Quota");
|
String quota = c.getHeaderField("Download-Quota");
|
||||||
if (quota != null) {
|
if (quota != null) {
|
||||||
if ((DOWNLOAD_QUOTA = Integer.parseInt(quota)) <= 0) {
|
setAndCheckDownloadQuota(Integer.parseInt(quota));
|
||||||
throw new IOException("Download-Quota has been exceeded");
|
|
||||||
}
|
|
||||||
debug.finest(format("Download-Quota: %d", DOWNLOAD_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 {
|
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>();
|
List<OpenSubtitlesSubtitleDescriptor> subtitles = new ArrayList<OpenSubtitlesSubtitleDescriptor>();
|
||||||
Map<?, ?> response = invoke("SearchSubtitles", token, queryList);
|
Map<?, ?> response = invoke("SearchSubtitles", token, queryList);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user