use of com.biglybt.core.content.RelatedAttributeLookupListener 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();
}
}
});
}
Aggregations