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:
parent
9effd7cc6d
commit
8fd4576ff4
@ -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;
|
||||||
@ -73,69 +75,76 @@ public class OpenSubtitlesSubtitleDescriptor implements SubtitleDescriptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private final Map<Property, String> properties;
|
private final Map<Property, String> properties;
|
||||||
|
|
||||||
|
|
||||||
public OpenSubtitlesSubtitleDescriptor(Map<Property, String> properties) {
|
public OpenSubtitlesSubtitleDescriptor(Map<Property, String> properties) {
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getProperty(Property key) {
|
public String getProperty(Property key) {
|
||||||
return properties.get(key);
|
return properties.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
return getProperty(Property.SubFileName);
|
return getProperty(Property.SubFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return FileUtilities.getNameWithoutExtension(getProperty(Property.SubFileName));
|
return FileUtilities.getNameWithoutExtension(getProperty(Property.SubFileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getLanguageName() {
|
public String getLanguageName() {
|
||||||
return getProperty(Property.LanguageName);
|
return getProperty(Property.LanguageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return getProperty(Property.SubFormat);
|
return getProperty(Property.SubFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getLength() {
|
public long getLength() {
|
||||||
return Long.parseLong(getProperty(Property.SubSize));
|
return Long.parseLong(getProperty(Property.SubSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getMovieHash() {
|
public String getMovieHash() {
|
||||||
return getProperty(Property.MovieHash);
|
return getProperty(Property.MovieHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public long getMovieByteSize() {
|
public long getMovieByteSize() {
|
||||||
return Long.parseLong(getProperty(Property.MovieByteSize));
|
return Long.parseLong(getProperty(Property.MovieByteSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@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();
|
||||||
@ -144,13 +153,13 @@ public class OpenSubtitlesSubtitleDescriptor implements SubtitleDescriptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return getProperty(Property.IDSubtitle).hashCode();
|
return getProperty(Property.IDSubtitle).hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object object) {
|
public boolean equals(Object object) {
|
||||||
if (object instanceof OpenSubtitlesSubtitleDescriptor) {
|
if (object instanceof OpenSubtitlesSubtitleDescriptor) {
|
||||||
@ -161,7 +170,7 @@ public class OpenSubtitlesSubtitleDescriptor implements SubtitleDescriptor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%s [%s]", getName(), getLanguageName());
|
return String.format("%s [%s]", getName(), getLanguageName());
|
||||||
|
Loading…
Reference in New Issue
Block a user