Search in sources :

Example 1 with ContentException

use of com.biglybt.core.content.ContentException in project BiglyBT by BiglySoftware.

the class SBC_TagDiscovery method startScan.

private void startScan() {
    try {
        mon_scansRemaining.enter();
        if (scansRemaining > 0) {
            return;
        }
    } finally {
        mon_scansRemaining.exit();
    }
    CoreFactory.addCoreRunningListener(new CoreRunningListener() {

        @Override
        public void coreRunning(Core core) {
            GlobalManager gm = core.getGlobalManager();
            try {
                try {
                    mon_scansRemaining.enter();
                    scansRemaining = 0;
                } finally {
                    mon_scansRemaining.exit();
                }
                RelatedContentManager rcm = RelatedContentManager.getSingleton();
                List<DownloadManager> dms = gm.getDownloadManagers();
                for (final DownloadManager dm : dms) {
                    if (tv == null) {
                        return;
                    }
                    TOTorrent torrent = dm.getTorrent();
                    if (torrent == null) {
                        continue;
                    }
                    try {
                        final byte[] hash = torrent.getHash();
                        try {
                            mon_scansRemaining.enter();
                            scansRemaining++;
                            if (vitalityImage != null && scansRemaining == 1) {
                                vitalityImage.setVisible(true);
                            }
                            if (soTitle != null) {
                                soTitle.setText(MessageText.getString("tag.discovery.view.heading") + " : Scanning " + scansRemaining);
                            }
                        } finally {
                            mon_scansRemaining.exit();
                        }
                        try {
                            rcm.lookupAttributes(hash, dm.getDownloadState().getNetworks(), new RelatedAttributeLookupListener() {

                                @Override
                                public void tagFound(String tag, String network) {
                                    if (DEBUG) {
                                        System.out.println("Tag Search: Found Tag " + tag + " for " + dm.getDisplayName());
                                    }
                                    if (tv == null) {
                                        return;
                                    }
                                    String key = Base32.encode(hash) + tag;
                                    TagManager tm = TagManagerFactory.getTagManager();
                                    TagType tt_manual = tm.getTagType(TagType.TT_DOWNLOAD_MANUAL);
                                    List<Tag> existingDMTags = tt_manual.getTagsForTaggable(dm);
                                    for (Tag existingTag : existingDMTags) {
                                        if (existingTag.getTagName(true).equalsIgnoreCase(tag)) {
                                            return;
                                        }
                                    }
                                    synchronized (mapTagDiscoveries) {
                                        if (!mapTagDiscoveries.containsKey(key)) {
                                            TagDiscovery tagDiscovery = new TagDiscovery(tag, network, dm.getDisplayName(), hash);
                                            mapTagDiscoveries.put(key, tagDiscovery);
                                            ViewTitleInfoManager.refreshTitleInfo(SBC_TagDiscovery.this);
                                            tv.addDataSource(tagDiscovery);
                                        }
                                    }
                                }

                                @Override
                                public void lookupStart() {
                                    if (DEBUG) {
                                        System.out.println("Tag Search: Start" + " for " + dm.getDisplayName());
                                    }
                                }

                                @Override
                                public void lookupFailed(ContentException error) {
                                    if (DEBUG) {
                                        System.out.println("Tag Search: Failed " + error.getMessage() + " for " + dm.getDisplayName());
                                    }
                                }

                                @Override
                                public void lookupComplete() {
                                    decreaseScansRemaining();
                                    if (DEBUG) {
                                        System.out.println("Tag Search: Complete" + " for " + dm.getDisplayName());
                                    }
                                }
                            });
                        } catch (Throwable e) {
                            // can get here if the scan never gets kicked off (dht unavailable for network etc)
                            decreaseScansRemaining();
                        }
                    } catch (TOTorrentException e) {
                        e.printStackTrace();
                    }
                }
            } catch (ContentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });
}
Also used : RelatedContentManager(com.biglybt.core.content.RelatedContentManager) ContentException(com.biglybt.core.content.ContentException) RelatedAttributeLookupListener(com.biglybt.core.content.RelatedAttributeLookupListener) DownloadManager(com.biglybt.core.download.DownloadManager) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) GlobalManager(com.biglybt.core.global.GlobalManager) TOTorrent(com.biglybt.core.torrent.TOTorrent) CoreRunningListener(com.biglybt.core.CoreRunningListener) List(java.util.List) Core(com.biglybt.core.Core)

Aggregations

Core (com.biglybt.core.Core)1 CoreRunningListener (com.biglybt.core.CoreRunningListener)1 ContentException (com.biglybt.core.content.ContentException)1 RelatedAttributeLookupListener (com.biglybt.core.content.RelatedAttributeLookupListener)1 RelatedContentManager (com.biglybt.core.content.RelatedContentManager)1 DownloadManager (com.biglybt.core.download.DownloadManager)1 GlobalManager (com.biglybt.core.global.GlobalManager)1 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)1 List (java.util.List)1