1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-17 06:45:06 -05:00

* better error messages when anti-leech limits are reached

This commit is contained in:
Reinhard Pointner 2012-07-13 05:00:27 +00:00
parent 9effd7cc6d
commit 8fd4576ff4

View File

@ -2,6 +2,7 @@
package net.sourceforge.filebot.web; package net.sourceforge.filebot.web;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -9,6 +10,7 @@ import java.util.EnumMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import java.util.zip.ZipException;
import net.sourceforge.tuned.ByteBufferOutputStream; import net.sourceforge.tuned.ByteBufferOutputStream;
import net.sourceforge.tuned.FileUtilities; import net.sourceforge.tuned.FileUtilities;
@ -130,12 +132,19 @@ public class OpenSubtitlesSubtitleDescriptor implements SubtitleDescriptor {
@Override @Override
public ByteBuffer fetch() throws Exception { public ByteBuffer fetch() throws Exception {
URL resource = new URL(getProperty(Property.SubDownloadLink)); URL resource = new URL(getProperty(Property.SubDownloadLink));
InputStream stream = new GZIPInputStream(resource.openStream()); InputStream stream = resource.openStream();
try { try {
ByteBufferOutputStream buffer = new ByteBufferOutputStream(getLength()); ByteBufferOutputStream buffer = new ByteBufferOutputStream(getLength());
// read all // extract gzipped subtitle on-the-fly
try {
stream = new GZIPInputStream(stream);
} catch (ZipException e) {
throw new IOException(String.format("%s: anti-leech limit may have been reached", e.getMessage()));
}
// fully download
buffer.transferFully(stream); buffer.transferFully(stream);
return buffer.getByteBuffer(); return buffer.getByteBuffer();