use of com.biglybt.plugin.extseed.util.ExternalSeedHTTPDownloaderLinear in project BiglyBT by BiglySoftware.
the class ExternalSeedReaderGetRight method setupDownloaders.
private void setupDownloaders() {
synchronized (this) {
if (http_downloaders != null) {
return;
}
TOTorrent to_torrent = ((TorrentImpl) getTorrent()).getTorrent();
String ua = getUserAgent();
if (to_torrent.isSimpleTorrent()) {
http_downloaders = new ExternalSeedHTTPDownloader[] { linear_download ? new ExternalSeedHTTPDownloaderLinear(url, ua) : new ExternalSeedHTTPDownloaderRange(url, ua) };
downloader_offsets = new long[] { 0 };
downloader_lengths = new long[] { to_torrent.getSize() };
} else {
TOTorrentFile[] files = to_torrent.getFiles();
http_downloaders = new ExternalSeedHTTPDownloader[files.length];
downloader_offsets = new long[files.length];
downloader_lengths = new long[files.length];
long offset = 0;
// encoding is a problem, assume ISO-8859-1
String base_url = url.toString();
if (base_url.endsWith("/")) {
base_url = base_url.substring(0, base_url.length() - 1);
}
try {
base_url += "/" + URLEncoder.encode(new String(to_torrent.getName(), "ISO-8859-1"), "ISO-8859-1").replaceAll("\\+", "%20");
for (int i = 0; i < files.length; i++) {
TOTorrentFile file = files[i];
long length = file.getLength();
String file_url_str = base_url;
byte[][] bits = file.getPathComponents();
for (int j = 0; j < bits.length; j++) {
file_url_str += "/" + URLEncoder.encode(new String(bits[j], "ISO-8859-1"), "ISO-8859-1").replaceAll("\\+", "%20");
}
http_downloaders[i] = linear_download ? new ExternalSeedHTTPDownloaderLinear(new URL(file_url_str), ua) : new ExternalSeedHTTPDownloaderRange(new URL(file_url_str), ua);
downloader_offsets[i] = offset;
downloader_lengths[i] = length;
offset += length;
}
} catch (Throwable e) {
Debug.out(e);
}
}
}
}
Aggregations