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 "";
}
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()));
}
}
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);
}
}
}
}
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;
}
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]--;
}
}
}
Aggregations