use of com.biglybt.pif.torrent.Torrent in project BiglyBT by BiglySoftware.
the class BuddyPluginTracker method okToTrack.
protected boolean okToTrack(Download d) {
Torrent t = d.getTorrent();
if (t == null) {
return (false);
}
String[] networks = d.getListAttribute(ta_networks);
boolean ok = false;
for (String net : networks) {
if (net == AENetworkClassifier.AT_PUBLIC) {
ok = true;
}
}
if (!ok) {
return (false);
}
if (t.isPrivate()) {
DownloadAnnounceResult announce = d.getLastAnnounceResult();
if (announce == null || announce.getResponseType() != DownloadAnnounceResult.RT_SUCCESS || announce.getPeers() == null || announce.getPeers().length < 2) {
return (false);
}
}
int state = d.getState();
return (state != Download.ST_ERROR && state != Download.ST_STOPPING && state != Download.ST_STOPPED);
}
use of com.biglybt.pif.torrent.Torrent in project BiglyBT by BiglySoftware.
the class BuddyPluginTracker method downloadAdded.
@Override
public void downloadAdded(final Download download) {
Torrent t = download.getTorrent();
if (t == null) {
return;
}
if (t.isPrivate()) {
download.addTrackerListener(new DownloadTrackerListener() {
@Override
public void scrapeResult(DownloadScrapeResult result) {
}
@Override
public void announceResult(DownloadAnnounceResult result) {
if (okToTrack(download)) {
trackDownload(download);
} else {
untrackDownload(download);
}
}
}, false);
}
if (okToTrack(download)) {
trackDownload(download);
}
download.addListener(new DownloadListener() {
@Override
public void stateChanged(Download download, int old_state, int new_state) {
if (okToTrack(download)) {
trackDownload(download);
} else {
untrackDownload(download);
}
}
@Override
public void positionChanged(Download download, int oldPosition, int newPosition) {
}
});
}
use of com.biglybt.pif.torrent.Torrent in project BiglyBT by BiglySoftware.
the class BuddyPluginBeta method startup.
protected void startup() {
plugin_interface.addEventListener(new PluginEventListener() {
@Override
public void handleEvent(PluginEvent ev) {
int type = ev.getType();
if (type == PluginEvent.PEV_PLUGIN_OPERATIONAL) {
pluginAdded((PluginInterface) ev.getValue());
} else if (type == PluginEvent.PEV_PLUGIN_NOT_OPERATIONAL) {
pluginRemoved((PluginInterface) ev.getValue());
}
}
});
PluginInterface[] plugins = plugin_interface.getPluginManager().getPlugins(true);
for (PluginInterface pi : plugins) {
if (pi.getPluginState().isOperational()) {
pluginAdded(pi);
}
}
boolean check_all = COConfigurationManager.getBooleanParameter("azbuddy.dchat.autotracker.scan", true);
COConfigurationManager.setParameter("azbuddy.dchat.autotracker.scan", false);
plugin_interface.getDownloadManager().addListener(new DownloadManagerListener() {
private Set<String> checked = new HashSet<>();
@Override
public void downloadAdded(Download download) {
if (COConfigurationManager.getBooleanParameter(ConfigKeys.Tag.BCFG_TRACKER_AUTO_TAG_INTERESTING_TRACKERS)) {
Torrent torrent = download.getTorrent();
if (torrent != null) {
TOTorrent to_torrent = PluginCoreUtils.unwrap(download.getTorrent());
if (TorrentUtils.isReallyPrivate(to_torrent)) {
Set<String> hosts = TorrentUtils.getUniqueTrackerHosts(to_torrent);
if (hosts.size() == 1) {
String tracker = DNSUtils.getInterestingHostSuffix(hosts.iterator().next());
if (tracker != null && !checked.contains(tracker)) {
checked.add(tracker);
try {
String config_key = "azbuddy.dchat.autotracker.host." + Base32.encode(tracker.getBytes("UTF-8"));
boolean done = COConfigurationManager.getBooleanParameter(config_key, false);
if (!done) {
COConfigurationManager.setParameter(config_key, true);
String chat_key = "Tracker: " + tracker;
ChatInstance chat = getChat(AENetworkClassifier.AT_PUBLIC, chat_key);
chat.setFavourite(true);
BuddyPluginUI.openChat(chat);
TagManager tm = TagManagerFactory.getTagManager();
if (tm.isEnabled()) {
TagType tt = tm.getTagType(TagType.TT_DOWNLOAD_MANUAL);
Tag tag = tt.getTag(tracker, true);
if (tag == null) {
tag = tt.createTag(tracker, false);
tag.setPublic(false);
tt.addTag(tag);
TagFeatureProperties tfp = (TagFeatureProperties) tag;
TagProperty tp = tfp.getProperty(TagFeatureProperties.PR_TRACKERS);
tp.setStringList(new String[] { tracker });
}
}
}
} catch (Throwable e) {
}
}
}
}
}
}
}
@Override
public void downloadRemoved(Download download) {
}
}, check_all);
}
use of com.biglybt.pif.torrent.Torrent in project BiglyBT by BiglySoftware.
the class ExternalSeedPlugin method addSeed.
public List<ExternalSeedPeer> addSeed(Download download, Map config) {
Torrent torrent = download.getTorrent();
List<ExternalSeedPeer> peers = new ArrayList<>();
if (torrent != null) {
for (int i = 0; i < factories.length; i++) {
ExternalSeedReader[] x = factories[i].getSeedReaders(this, download, config);
for (int j = 0; j < x.length; j++) {
ExternalSeedReader reader = x[j];
ExternalSeedPeer peer = new ExternalSeedPeer(this, download, reader);
peers.add(peer);
}
}
addPeers(download, peers);
}
return (peers);
}
use of com.biglybt.pif.torrent.Torrent 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;
}
Aggregations