Search in sources :

Example 1 with ExternalSeedHTTPDownloaderRange

use of com.biglybt.plugin.extseed.util.ExternalSeedHTTPDownloaderRange 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);
            }
        }
    }
}
Also used : ExternalSeedHTTPDownloaderRange(com.biglybt.plugin.extseed.util.ExternalSeedHTTPDownloaderRange) TOTorrentFile(com.biglybt.core.torrent.TOTorrentFile) TorrentImpl(com.biglybt.pifimpl.local.torrent.TorrentImpl) TOTorrent(com.biglybt.core.torrent.TOTorrent) ExternalSeedHTTPDownloaderLinear(com.biglybt.plugin.extseed.util.ExternalSeedHTTPDownloaderLinear) URL(java.net.URL)

Example 2 with ExternalSeedHTTPDownloaderRange

use of com.biglybt.plugin.extseed.util.ExternalSeedHTTPDownloaderRange in project BiglyBT by BiglySoftware.

the class ExternalSeedReaderWebSeed method readData.

@Override
protected void readData(int piece_number, int piece_offset, int length, ExternalSeedHTTPDownloaderListener listener) throws ExternalSeedException {
    long piece_end = piece_offset + length - 1;
    String str = url_prefix + "&piece=" + piece_number + "&ranges=" + piece_offset + "-" + piece_end;
    setReconnectDelay(RECONNECT_DEFAULT, false);
    ExternalSeedHTTPDownloader http_downloader = null;
    try {
        http_downloader = new ExternalSeedHTTPDownloaderRange(new URL(str), getUserAgent());
        if (supports_503) {
            http_downloader.downloadSocket(length, listener, isTransient());
        } else {
            http_downloader.download(length, listener, isTransient());
        }
    } catch (ExternalSeedException ese) {
        if (http_downloader.getLastResponse() == 503 && http_downloader.getLast503RetrySecs() >= 0) {
            int retry_secs = http_downloader.getLast503RetrySecs();
            setReconnectDelay(retry_secs * 1000, true);
            throw (new ExternalSeedException("Server temporarily unavailable, retrying in " + retry_secs + " seconds"));
        } else {
            throw (ese);
        }
    } catch (MalformedURLException e) {
        throw (new ExternalSeedException("URL encode fails", e));
    }
}
Also used : ExternalSeedHTTPDownloaderRange(com.biglybt.plugin.extseed.util.ExternalSeedHTTPDownloaderRange) ExternalSeedHTTPDownloader(com.biglybt.plugin.extseed.util.ExternalSeedHTTPDownloader) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) ExternalSeedException(com.biglybt.plugin.extseed.ExternalSeedException)

Aggregations

ExternalSeedHTTPDownloaderRange (com.biglybt.plugin.extseed.util.ExternalSeedHTTPDownloaderRange)2 URL (java.net.URL)2 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 TOTorrentFile (com.biglybt.core.torrent.TOTorrentFile)1 TorrentImpl (com.biglybt.pifimpl.local.torrent.TorrentImpl)1 ExternalSeedException (com.biglybt.plugin.extseed.ExternalSeedException)1 ExternalSeedHTTPDownloader (com.biglybt.plugin.extseed.util.ExternalSeedHTTPDownloader)1 ExternalSeedHTTPDownloaderLinear (com.biglybt.plugin.extseed.util.ExternalSeedHTTPDownloaderLinear)1 MalformedURLException (java.net.MalformedURLException)1