Search in sources :

Example 21 with TOTorrent

use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.

the class DisplayFormatters method formatHashFails.

public static String formatHashFails(DownloadManager download_manager) {
    TOTorrent torrent = download_manager.getTorrent();
    if (torrent != null) {
        long bad = download_manager.getStats().getHashFailBytes();
        // size can exceed int so ensure longs used in multiplication
        long count = bad / (long) torrent.getPieceLength();
        String result = count + " ( " + formatByteCountToKiBEtc(bad) + " )";
        return result;
    }
    return "";
}
Also used : TOTorrent(com.biglybt.core.torrent.TOTorrent)

Example 22 with TOTorrent

use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.

the class TrackerWebPageResponseImpl method writeTorrent.

@Override
public void writeTorrent(TrackerTorrent tracker_torrent) throws IOException {
    try {
        TRHostTorrent host_torrent = ((TrackerTorrentImpl) tracker_torrent).getHostTorrent();
        TOTorrent torrent = host_torrent.getTorrent();
        // make a copy of the torrent
        TOTorrent torrent_to_send = TOTorrentFactory.deserialiseFromMap(torrent.serialiseToMap());
        // remove any non-standard stuff (e.g. resume data)
        torrent_to_send.removeAdditionalProperties();
        if (!TorrentUtils.isDecentralised(torrent_to_send)) {
            URL[][] url_sets = TRTrackerUtils.getAnnounceURLs();
            if (host_torrent.getStatus() != TRHostTorrent.TS_PUBLISHED && url_sets.length > 0) {
                if (COConfigurationManager.getBooleanParameter("Tracker Host Add Our Announce URLs")) {
                    String protocol = torrent_to_send.getAnnounceURL().getProtocol();
                    for (int i = 0; i < url_sets.length; i++) {
                        URL[] urls = url_sets[i];
                        if (urls[0].getProtocol().equalsIgnoreCase(protocol)) {
                            torrent_to_send.setAnnounceURL(urls[0]);
                            torrent_to_send.getAnnounceURLGroup().setAnnounceURLSets(new TOTorrentAnnounceURLSet[0]);
                            for (int j = 1; j < urls.length; j++) {
                                TorrentUtils.announceGroupsInsertLast(torrent_to_send, new URL[] { urls[j] });
                            }
                            break;
                        }
                    }
                }
            }
        }
        baos.write(BEncoder.encode(torrent_to_send.serialiseToMap()));
        setContentType("application/x-bittorrent");
    } catch (TOTorrentException e) {
        Debug.printStackTrace(e);
        throw (new IOException(e.toString()));
    }
}
Also used : TOTorrentException(com.biglybt.core.torrent.TOTorrentException) TOTorrent(com.biglybt.core.torrent.TOTorrent) TRHostTorrent(com.biglybt.core.tracker.host.TRHostTorrent) URL(java.net.URL)

Example 23 with TOTorrent

use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.

the class TorrentDownloaderImpl method downloadSupport.

private Torrent downloadSupport(ResourceDownloader downloader) throws TorrentException {
    InputStream is = null;
    try {
        is = downloader.download();
        TOTorrent torrent = TOTorrentFactory.deserialiseFromBEncodedInputStream(is);
        if (encoding_requested) {
            manager.tryToSetTorrentEncoding(torrent, requested_encoding);
        } else {
            if (set_encoding) {
                manager.tryToSetDefaultTorrentEncoding(torrent);
            }
        }
        return (new TorrentImpl(torrent));
    } catch (TorrentException e) {
        throw (e);
    } catch (ResourceDownloaderException e) {
        throw (new TorrentException(e));
    } catch (Throwable e) {
        throw (new TorrentException("TorrentDownloader: download fails", e));
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                Debug.printStackTrace(e);
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException) TOTorrent(com.biglybt.core.torrent.TOTorrent) IOException(java.io.IOException) TorrentException(com.biglybt.pif.torrent.TorrentException)

Example 24 with TOTorrent

use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.

the class DataSourceUtils method getTorrent.

public static TOTorrent getTorrent(Object ds) {
    if (ds instanceof TOTorrent) {
        return (TOTorrent) ds;
    }
    if (ds instanceof DownloadManager) {
        TOTorrent torrent = ((DownloadManager) ds).getTorrent();
        if (torrent != null) {
            return torrent;
        }
    }
    if (ds instanceof ActivitiesEntry) {
        TOTorrent torrent = ((ActivitiesEntry) ds).getTorrent();
        if (torrent == null) {
            // getDM will check hash as well
            DownloadManager dm = getDM(ds);
            if (dm != null) {
                torrent = dm.getTorrent();
            }
        }
        return torrent;
    }
    if (ds instanceof TranscodeFile) {
        TranscodeFile tf = (TranscodeFile) ds;
        try {
            DiskManagerFileInfo file = tf.getSourceFile();
            if (file != null) {
                Download download = file.getDownload();
                if (download != null) {
                    Torrent torrent = download.getTorrent();
                    if (torrent != null) {
                        return PluginCoreUtils.unwrap(torrent);
                    }
                }
            }
        } catch (Throwable e) {
        }
    }
    if (ds instanceof TranscodeJob) {
        TranscodeJob tj = (TranscodeJob) ds;
        try {
            DiskManagerFileInfo file = tj.getFile();
            if (file != null) {
                Download download = tj.getFile().getDownload();
                if (download != null) {
                    Torrent torrent = download.getTorrent();
                    if (torrent != null) {
                        return PluginCoreUtils.unwrap(torrent);
                    }
                }
            }
        } catch (DownloadException e) {
        }
    }
    if (ds instanceof ISelectedContent) {
        return ((ISelectedContent) ds).getTorrent();
    }
    if (ds instanceof String) {
        String hash = (String) ds;
        try {
            GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
            DownloadManager dm = gm.getDownloadManager(new HashWrapper(Base32.decode(hash)));
            if (dm != null) {
                return dm.getTorrent();
            }
        } catch (Exception e) {
        // ignore
        }
    }
    DownloadManager dm = getDM(ds);
    if (dm != null) {
        return dm.getTorrent();
    }
    return null;
}
Also used : TOTorrent(com.biglybt.core.torrent.TOTorrent) Torrent(com.biglybt.pif.torrent.Torrent) DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) ISelectedContent(com.biglybt.ui.selectedcontent.ISelectedContent) DownloadManager(com.biglybt.core.download.DownloadManager) DownloadException(com.biglybt.pif.download.DownloadException) TranscodeJob(com.biglybt.core.devices.TranscodeJob) ActivitiesEntry(com.biglybt.activities.ActivitiesEntry) GlobalManager(com.biglybt.core.global.GlobalManager) HashWrapper(com.biglybt.core.util.HashWrapper) TOTorrent(com.biglybt.core.torrent.TOTorrent) DownloadException(com.biglybt.pif.download.DownloadException) TranscodeFile(com.biglybt.core.devices.TranscodeFile) Download(com.biglybt.pif.download.Download)

Example 25 with TOTorrent

use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.

the class PlayUtils method canPlayDS.

public static boolean canPlayDS(Object ds, int file_index, boolean block_for_accuracy) {
    if (ds == null) {
        return false;
    }
    try {
        if (!block_for_accuracy) {
            tls_non_block_indicator.get()[0]++;
        }
        if (ds instanceof com.biglybt.core.disk.DiskManagerFileInfo) {
            com.biglybt.core.disk.DiskManagerFileInfo fi = (com.biglybt.core.disk.DiskManagerFileInfo) ds;
            return canPlayDS(fi.getDownloadManager(), fi.getIndex(), block_for_accuracy);
        }
        DownloadManager dm = DataSourceUtils.getDM(ds);
        if (dm != null) {
            return canPlay(dm, file_index);
        }
        TOTorrent torrent = DataSourceUtils.getTorrent(ds);
        if (torrent != null) {
            return canPlay(torrent, file_index);
        }
        if (ds instanceof ActivitiesEntry) {
            return ((ActivitiesEntry) ds).isPlayable(block_for_accuracy);
        }
        return false;
    } finally {
        if (!block_for_accuracy) {
            tls_non_block_indicator.get()[0]--;
        }
    }
}
Also used : DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) ActivitiesEntry(com.biglybt.activities.ActivitiesEntry) TOTorrent(com.biglybt.core.torrent.TOTorrent)

Aggregations

TOTorrent (com.biglybt.core.torrent.TOTorrent)123 DownloadManager (com.biglybt.core.download.DownloadManager)34 File (java.io.File)32 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)29 URL (java.net.URL)25 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)15 TOTorrentFile (com.biglybt.core.torrent.TOTorrentFile)13 IOException (java.io.IOException)13 GlobalManager (com.biglybt.core.global.GlobalManager)10 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)10 Torrent (com.biglybt.pif.torrent.Torrent)9 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)8 TOTorrentAnnounceURLSet (com.biglybt.core.torrent.TOTorrentAnnounceURLSet)8 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)8 List (java.util.List)8 Map (java.util.Map)7 Core (com.biglybt.core.Core)6 DiskManagerFileInfoSet (com.biglybt.core.disk.DiskManagerFileInfoSet)6 Download (com.biglybt.pif.download.Download)6 TorrentImpl (com.biglybt.pifimpl.local.torrent.TorrentImpl)6