Search in sources :

Example 16 with Torrent

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);
}
Also used : Torrent(com.biglybt.pif.torrent.Torrent)

Example 17 with Torrent

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) {
        }
    });
}
Also used : Torrent(com.biglybt.pif.torrent.Torrent)

Example 18 with Torrent

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);
}
Also used : DownloadManagerListener(com.biglybt.pif.download.DownloadManagerListener) TagProperty(com.biglybt.core.tag.TagFeatureProperties.TagProperty) Torrent(com.biglybt.pif.torrent.Torrent) TOTorrent(com.biglybt.core.torrent.TOTorrent) PluginEventListener(com.biglybt.pif.PluginEventListener) PluginInterface(com.biglybt.pif.PluginInterface) TagType(com.biglybt.core.tag.TagType) TagManager(com.biglybt.core.tag.TagManager) TOTorrent(com.biglybt.core.torrent.TOTorrent) Tag(com.biglybt.core.tag.Tag) TagFeatureProperties(com.biglybt.core.tag.TagFeatureProperties) PluginEvent(com.biglybt.pif.PluginEvent) Download(com.biglybt.pif.download.Download)

Example 19 with Torrent

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);
}
Also used : Torrent(com.biglybt.pif.torrent.Torrent)

Example 20 with Torrent

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;
}
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) TagDownload(com.biglybt.core.tag.TagDownload)

Aggregations

Torrent (com.biglybt.pif.torrent.Torrent)41 Download (com.biglybt.pif.download.Download)16 TOTorrent (com.biglybt.core.torrent.TOTorrent)13 URL (java.net.URL)12 PluginInterface (com.biglybt.pif.PluginInterface)7 DownloadManager (com.biglybt.core.download.DownloadManager)6 TorrentAttribute (com.biglybt.pif.torrent.TorrentAttribute)5 File (java.io.File)5 Tag (com.biglybt.core.tag.Tag)4 InetSocketAddress (java.net.InetSocketAddress)4 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)3 PEPeerManager (com.biglybt.core.peer.PEPeerManager)3 TrackerTorrent (com.biglybt.pif.tracker.TrackerTorrent)3 TorrentImpl (com.biglybt.pifimpl.local.torrent.TorrentImpl)3 RPException (com.biglybt.pifimpl.remote.RPException)3 RPReply (com.biglybt.pifimpl.remote.RPReply)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ParameterListener (com.biglybt.core.config.ParameterListener)2 PEPeer (com.biglybt.core.peer.PEPeer)2