use of com.biglybt.pif.download.DownloadScrapeResult in project BiglyBT by BiglySoftware.
the class BuddyPluginViewBetaChat method dropDownload.
private void dropDownload(Download download, DropAccepter accepter) {
String magnet = UrlUtils.getMagnetURI(download, 80);
// we can go a bit over MAX_MSG_LENGTH as underlying limit is a fair bit higher
magnet = trimMagnet(magnet, MAX_MSG_CHUNK_LENGTH);
magnet += "&xl=" + download.getTorrentSize();
DownloadScrapeResult scrape = download.getLastScrapeResult();
if (scrape != null && scrape.getResponseType() == DownloadScrapeResult.RT_SUCCESS) {
int seeds = scrape.getSeedCount();
int leechers = scrape.getNonSeedCount();
if (seeds != -1) {
magnet += "&_s=" + seeds;
}
if (leechers != -1) {
magnet += "&_l=" + leechers;
}
}
long added = PluginCoreUtils.unwrap(download).getDownloadState().getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_ADDED_TIME);
magnet += "&_d=" + added;
InetSocketAddress address = chat.getMyAddress();
if (address != null) {
String address_str = AddressUtils.getHostAddress(address) + ":" + address.getPort();
String arg = "&xsource=" + UrlUtils.encode(address_str);
magnet += arg;
}
magnet += "[[$dn]]";
plugin.getBeta().tagDownload(download);
download.setForceStart(true);
accepter.accept(magnet);
}
use of com.biglybt.pif.download.DownloadScrapeResult in project BiglyBT by BiglySoftware.
the class CategoryManagerImpl method generate.
@Override
public boolean generate(TrackerWebPageRequest request, TrackerWebPageResponse response) throws IOException {
URL url = request.getAbsoluteURL();
String path = url.getPath();
int pos = path.indexOf('?');
if (pos != -1) {
path = path.substring(0, pos);
}
path = path.substring(PROVIDER.length() + 1);
XMLEscapeWriter pw = new XMLEscapeWriter(new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF-8")));
pw.setEnabled(false);
if (path.length() <= 1) {
response.setContentType("text/html; charset=UTF-8");
pw.println("<HTML><HEAD><TITLE>" + Constants.APP_NAME + " Category Feeds</TITLE></HEAD><BODY>");
Map<String, String> lines = new TreeMap<>();
List<CategoryImpl> cats;
try {
categories_mon.enter();
cats = new ArrayList<>(categories.values());
} finally {
categories_mon.exit();
}
for (CategoryImpl c : cats) {
if (c.getBooleanAttribute(Category.AT_RSS_GEN)) {
String name = getDisplayName(c);
String cat_url = PROVIDER + "/" + URLEncoder.encode(c.getName(), "UTF-8");
lines.put(name, "<LI><A href=\"" + cat_url + "\">" + name + "</A></LI>");
}
}
for (String line : lines.values()) {
pw.println(line);
}
pw.println("</BODY></HTML>");
} else {
String cat_name = URLDecoder.decode(path.substring(1), "UTF-8");
CategoryImpl cat;
try {
categories_mon.enter();
cat = categories.get(cat_name);
} finally {
categories_mon.exit();
}
if (cat == null) {
response.setReplyStatus(404);
return (true);
}
List<DownloadManager> dms = cat.getDownloadManagers(CoreFactory.getSingleton().getGlobalManager().getDownloadManagers());
List<Download> downloads = new ArrayList<>(dms.size());
long dl_marker = 0;
for (DownloadManager dm : dms) {
TOTorrent torrent = dm.getTorrent();
if (torrent == null) {
continue;
}
if (!TorrentUtils.isReallyPrivate(torrent)) {
dl_marker += dm.getDownloadState().getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_ADDED_TIME);
downloads.add(PluginCoreUtils.wrap(dm));
}
}
String config_key = "cat.rss.config." + Base32.encode(cat.getName().getBytes("UTF-8"));
long old_marker = COConfigurationManager.getLongParameter(config_key + ".marker", 0);
long last_modified = COConfigurationManager.getLongParameter(config_key + ".last_mod", 0);
long now = SystemTime.getCurrentTime();
if (old_marker == dl_marker) {
if (last_modified == 0) {
last_modified = now;
}
} else {
COConfigurationManager.setParameter(config_key + ".marker", dl_marker);
last_modified = now;
}
if (last_modified == now) {
COConfigurationManager.setParameter(config_key + ".last_mod", last_modified);
}
response.setContentType("application/xml; charset=UTF-8");
pw.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
pw.println("<rss version=\"2.0\" xmlns:vuze=\"http://www.vuze.com\">");
pw.println("<channel>");
pw.println("<title>" + escape(getDisplayName(cat)) + "</title>");
Collections.sort(downloads, new Comparator<Download>() {
@Override
public int compare(Download d1, Download d2) {
long added1 = getAddedTime(d1) / 1000;
long added2 = getAddedTime(d2) / 1000;
return ((int) (added2 - added1));
}
});
pw.println("<pubDate>" + TimeFormatter.getHTTPDate(last_modified) + "</pubDate>");
for (int i = 0; i < downloads.size(); i++) {
Download download = downloads.get(i);
DownloadManager core_download = PluginCoreUtils.unwrap(download);
Torrent torrent = download.getTorrent();
byte[] hash = torrent.getHash();
String hash_str = Base32.encode(hash);
pw.println("<item>");
pw.println("<title>" + escape(download.getName()) + "</title>");
pw.println("<guid>" + hash_str + "</guid>");
String magnet_url = escape(UrlUtils.getMagnetURI(download));
pw.println("<link>" + magnet_url + "</link>");
long added = core_download.getDownloadState().getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_ADDED_TIME);
pw.println("<pubDate>" + TimeFormatter.getHTTPDate(added) + "</pubDate>");
pw.println("<vuze:size>" + torrent.getSize() + "</vuze:size>");
pw.println("<vuze:assethash>" + hash_str + "</vuze:assethash>");
pw.println("<vuze:downloadurl>" + magnet_url + "</vuze:downloadurl>");
DownloadScrapeResult scrape = download.getLastScrapeResult();
if (scrape != null && scrape.getResponseType() == DownloadScrapeResult.RT_SUCCESS) {
pw.println("<vuze:seeds>" + scrape.getSeedCount() + "</vuze:seeds>");
pw.println("<vuze:peers>" + scrape.getNonSeedCount() + "</vuze:peers>");
}
pw.println("</item>");
}
pw.println("</channel>");
pw.println("</rss>");
}
pw.flush();
return (true);
}
use of com.biglybt.pif.download.DownloadScrapeResult in project BiglyBT by BiglySoftware.
the class DefaultRankCalculator method _recalcSeedingRankSupport.
private int _recalcSeedingRankSupport(int oldSR) {
sExplainSR = "";
DownloadStats stats = dl.getStats();
int newSR = 0;
// make undownloaded sort to top so they can start first.
if (!dl.isComplete()) {
newSR = SR_COMPLETE_STARTS_AT + (10000 - dl.getPosition());
// make sure we capture FP being turned off when torrent does from
// complete to incomplete
isFirstPriority();
if (rules.bDebugLog) {
sExplainSR += " not complete. SetSR " + newSR + "\n";
}
return newSR;
}
// here we are seeding
lastModifiedShareRatio = stats.getShareRatio();
DownloadScrapeResult sr = dl.getAggregatedScrapeResult();
lastModifiedScrapeResultPeers = rules.calcPeersNoUs(dl, sr);
lastModifiedScrapeResultSeeds = rules.calcSeedsNoUs(dl, sr);
boolean bScrapeResultsOk = (lastModifiedScrapeResultPeers > 0 || lastModifiedScrapeResultSeeds > 0 || lastScrapeResultOk) && (lastModifiedScrapeResultPeers >= 0 && lastModifiedScrapeResultSeeds >= 0);
if (!isFirstPriority()) {
// Check Ignore Rules
// never apply ignore rules to First Priority Matches
// (we don't want leechers circumventing the 0.5 rule)
// 0 means unlimited
int activeMaxSR = dlSpecificMaxShareRatio;
if (activeMaxSR <= 0) {
activeMaxSR = iIgnoreShareRatio;
}
if (activeMaxSR != 0 && lastModifiedShareRatio >= activeMaxSR && (lastModifiedScrapeResultSeeds >= iIgnoreShareRatio_SeedStart || !bScrapeResultsOk) && lastModifiedShareRatio != -1) {
if (rules.bDebugLog)
sExplainSR += " shareratio met: shareRatio(" + lastModifiedShareRatio + ") >= " + activeMaxSR + "\n";
return SR_SHARERATIOMET;
} else if (rules.bDebugLog && activeMaxSR != 0 && lastModifiedShareRatio >= activeMaxSR) {
sExplainSR += " shareratio NOT met: ";
if (lastModifiedScrapeResultSeeds >= iIgnoreShareRatio_SeedStart)
sExplainSR += lastModifiedScrapeResultSeeds + " below seed threshold of " + iIgnoreShareRatio_SeedStart;
sExplainSR += "\n";
}
if (lastModifiedScrapeResultPeers == 0 && bScrapeResultsOk) {
// We have to use the normal SR_0PEERS in case it isn't FP
if (bIgnore0Peers) {
if (rules.bDebugLog)
sExplainSR += " Ignore 0 Peers criteria met\n";
return SR_0PEERS;
}
// if (bFirstPriorityIgnore0Peer) {
// if (rules.bDebugLog)
// sExplainSR += " Ignore 0 Peers criteria for FP met\n";
//
// return SR_FP0PEERS;
// }
} else if (rules.bDebugLog && lastModifiedScrapeResultPeers == 0) {
sExplainSR += " 0 Peer Ignore rule NOT applied: Scrape invalid\n";
}
// 0 means disabled
if ((iIgnoreSeedCount != 0) && (lastModifiedScrapeResultSeeds >= iIgnoreSeedCount)) {
if (rules.bDebugLog)
sExplainSR += " SeedCount Ignore rule met. numSeeds(" + lastModifiedScrapeResultSeeds + " >= iIgnoreSeedCount(" + iIgnoreSeedCount + ")\n";
return SR_NUMSEEDSMET;
}
// 0 means never stop
if (iIgnoreRatioPeers != 0 && lastModifiedScrapeResultSeeds != 0) {
float ratio = (float) lastModifiedScrapeResultPeers / lastModifiedScrapeResultSeeds;
if (ratio <= iIgnoreRatioPeers && lastModifiedScrapeResultSeeds >= iIgnoreRatioPeers_SeedStart) {
if (rules.bDebugLog)
sExplainSR += " P:S Ignore rule met. ratio(" + ratio + " <= threshold(" + iIgnoreRatioPeers_SeedStart + ")\n";
return SR_RATIOMET;
}
}
}
// Never do anything with rank type of none
if (iRankType == StartStopRulesDefaultPlugin.RANK_NONE) {
if (rules.bDebugLog)
sExplainSR += " Ranking Type set to none.. blanking seeding rank\n";
// everythink ok!
return newSR;
}
if (iRankType == StartStopRulesDefaultPlugin.RANK_TIMED) {
if (bIsFirstPriority) {
newSR += SR_TIMED_QUEUED_ENDS_AT + 1;
return newSR;
}
int state = dl.getState();
if (state == Download.ST_STOPPING || state == Download.ST_STOPPED || state == Download.ST_ERROR) {
if (rules.bDebugLog)
sExplainSR += " Download stopping, stopped or in error\n";
return SR_NOTQUEUED;
} else if (state == Download.ST_SEEDING || state == Download.ST_READY || state == Download.ST_WAITING || state == Download.ST_PREPARING) {
// force sort to top
long lMsElapsed = 0;
long lMsTimeToSeedFor = minTimeAlive;
if (state == Download.ST_SEEDING && !dl.isForceStart()) {
lMsElapsed = (SystemTime.getCurrentTime() - stats.getTimeStartedSeeding());
if (iTimed_MinSeedingTimeWithPeers > 0) {
PeerManager peerManager = dl.getPeerManager();
if (peerManager != null) {
int connectedLeechers = peerManager.getStats().getConnectedLeechers();
if (connectedLeechers > 0) {
lMsTimeToSeedFor = iTimed_MinSeedingTimeWithPeers;
}
}
}
}
if (lMsElapsed >= lMsTimeToSeedFor) {
newSR = 1;
if (oldSR > SR_TIMED_QUEUED_ENDS_AT) {
rules.requestProcessCycle(null);
if (rules.bDebugLog)
rules.log.log(dl.getTorrent(), LoggerChannel.LT_INFORMATION, "somethingChanged: TimeUp");
}
} else {
newSR = SR_TIMED_QUEUED_ENDS_AT + 1 + (int) (lMsElapsed / 1000);
if (oldSR <= SR_TIMED_QUEUED_ENDS_AT) {
rules.requestProcessCycle(null);
if (rules.bDebugLog)
rules.log.log(dl.getTorrent(), LoggerChannel.LT_INFORMATION, "somethingChanged: strange timer change");
}
}
return newSR;
} else {
// ST_QUEUED
// priority goes to ones who haven't been seeded for long
// maybe share ratio might work well too
long diff;
if (dlLastActiveTime == 0) {
diff = dl.getStats().getSecondsOnlySeeding();
if (diff > SR_TIMED_QUEUED_ENDS_AT - 100000) {
// close to overrunning.. so base off position
diff = SR_TIMED_QUEUED_ENDS_AT - 100000 + dl.getPosition();
}
newSR = SR_TIMED_QUEUED_ENDS_AT - (int) diff;
} else {
diff = ((System.currentTimeMillis() / 1000) - (dlLastActiveTime / 1000));
if (diff >= SR_TIMED_QUEUED_ENDS_AT) {
newSR = SR_TIMED_QUEUED_ENDS_AT - 1;
} else {
newSR = (int) diff;
}
}
return newSR;
}
}
// SeedCount and SPRatio require Scrape Results..
if (bScrapeResultsOk) {
if (iRankType == StartStopRulesDefaultPlugin.RANK_PEERCOUNT) {
if (lastModifiedScrapeResultPeers > lastModifiedScrapeResultSeeds * 10)
newSR = 100 * lastModifiedScrapeResultPeers * 10;
else
newSR = (int) ((long) 100 * lastModifiedScrapeResultPeers * lastModifiedScrapeResultPeers / (lastModifiedScrapeResultSeeds + 1));
} else if ((iRankType == StartStopRulesDefaultPlugin.RANK_SEEDCOUNT) && (iRankTypeSeedFallback == 0 || iRankTypeSeedFallback > lastModifiedScrapeResultSeeds)) {
if (lastModifiedScrapeResultSeeds < 10000)
newSR = 10000 - lastModifiedScrapeResultSeeds;
else
newSR = 1;
// shift over to make way for fallback
newSR *= SEEDONLY_SHIFT;
} else {
// iRankType == RANK_SPRATIO or we are falling back
if (lastModifiedScrapeResultPeers != 0) {
if (lastModifiedScrapeResultSeeds == 0) {
if (lastModifiedScrapeResultPeers >= minPeersToBoostNoSeeds)
newSR += SPRATIO_BASE_LIMIT;
} else {
// numSeeds != 0 && numPeers != 0
float x = (float) lastModifiedScrapeResultSeeds / lastModifiedScrapeResultPeers;
newSR += SPRATIO_BASE_LIMIT / ((x + 1) * (x + 1));
}
}
}
} else {
if (rules.bDebugLog)
sExplainSR += " Can't calculate SR, no scrape results\n";
}
if (staleCDOffset > 0) {
// every 10 minutes of not being active, subtract one SR
if (newSR > staleCDOffset) {
newSR -= staleCDOffset;
sExplainSR += " subtracted " + staleCDOffset + " due to non-activeness\n";
} else {
staleCDOffset = 0;
}
}
if (newSR < 0)
newSR = 1;
return newSR;
}
use of com.biglybt.pif.download.DownloadScrapeResult in project BiglyBT by BiglySoftware.
the class BuddyPlugin method getRSS.
public feedDetails getRSS(BuddyPluginBuddy buddy, String tag_or_category, String if_mod) throws BuddyPluginException {
if (!buddy.isLocalRSSTagOrCategoryAuthorised(tag_or_category)) {
throw (new BuddyPluginException("Unauthorised tag/category '" + tag_or_category + "'"));
}
buddy.localRSSTagOrCategoryRead(tag_or_category);
Download[] downloads = plugin_interface.getDownloadManager().getDownloads();
List<Download> selected_dls = new ArrayList<>();
long fingerprint = 0;
for (int i = 0; i < downloads.length; i++) {
Download download = downloads[i];
Torrent torrent = download.getTorrent();
if (torrent == null) {
continue;
}
boolean match = tag_or_category.equalsIgnoreCase("all");
if (!match) {
String dl_cat = download.getAttribute(ta_category);
match = dl_cat != null && dl_cat.equals(tag_or_category);
}
if (!match) {
try {
List<Tag> tags = TagManagerFactory.getTagManager().getTagsForTaggable(TagType.TT_DOWNLOAD_MANUAL, PluginCoreUtils.unwrap(download));
for (Tag tag : tags) {
if (tag.getTagName(true).equals(tag_or_category)) {
match = true;
break;
}
}
} catch (Throwable e) {
}
}
if (match) {
if (!TorrentUtils.isReallyPrivate(PluginCoreUtils.unwrap(torrent))) {
selected_dls.add(download);
byte[] hash = torrent.getHash();
int num = (hash[0] << 24) & 0xff000000 | (hash[1] << 16) & 0x00ff0000 | (hash[2] << 8) & 0x0000ff00 | hash[3] & 0x000000ff;
fingerprint += num;
}
}
}
PluginConfig pc = plugin_interface.getPluginconfig();
String feed_finger_key = "feed_finger.category." + tag_or_category;
String feed_date_key = "feed_date.category." + tag_or_category;
long existing_fingerprint = pc.getPluginLongParameter(feed_finger_key, 0);
long feed_date = pc.getPluginLongParameter(feed_date_key, 0);
long now = SystemTime.getCurrentTime();
if (existing_fingerprint == fingerprint) {
if (selected_dls.size() > 0) {
if (now < feed_date || now - feed_date > FEED_UPDATE_MIN_MILLIS) {
feed_date = now;
pc.setPluginParameter(feed_date_key, feed_date);
}
}
} else {
pc.setPluginParameter(feed_finger_key, fingerprint);
if (now <= feed_date) {
feed_date++;
} else {
feed_date = now;
}
pc.setPluginParameter(feed_date_key, feed_date);
}
String last_modified = TimeFormatter.getHTTPDate(feed_date);
if (if_mod != null && if_mod.equals(last_modified)) {
return (new feedDetails(new byte[0], last_modified));
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
PrintWriter pw = new PrintWriter(new OutputStreamWriter(os, "UTF-8"));
pw.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
pw.println("<rss version=\"2.0\" xmlns:vuze=\"http://www.vuze.com\">");
pw.println("<channel>");
pw.println("<title>" + escape(tag_or_category) + "</title>");
Collections.sort(selected_dls, new Comparator<Download>() {
@Override
public int compare(Download d1, Download d2) {
long added1 = getAddedTime(d1) / 1000;
long added2 = getAddedTime(d2) / 1000;
return ((int) (added2 - added1));
}
});
pw.println("<pubDate>" + last_modified + "</pubDate>");
for (int i = 0; i < selected_dls.size(); i++) {
Download download = (Download) selected_dls.get(i);
DownloadManager core_download = PluginCoreUtils.unwrap(download);
Torrent torrent = download.getTorrent();
String hash_str = Base32.encode(torrent.getHash());
pw.println("<item>");
pw.println("<title>" + escape(download.getName()) + "</title>");
pw.println("<guid>" + hash_str + "</guid>");
long added = core_download.getDownloadState().getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_ADDED_TIME);
pw.println("<pubDate>" + TimeFormatter.getHTTPDate(added) + "</pubDate>");
pw.println("<vuze:size>" + torrent.getSize() + "</vuze:size>");
pw.println("<vuze:assethash>" + hash_str + "</vuze:assethash>");
String url = "azplug:?id=azbuddy&name=Friends&arg=";
String arg = "pk=" + getPublicKey() + "&cat=" + tag_or_category + "&hash=" + Base32.encode(torrent.getHash());
url += URLEncoder.encode(arg, "UTF-8");
pw.println("<vuze:downloadurl>" + escape(url) + "</vuze:downloadurl>");
DownloadScrapeResult scrape = download.getLastScrapeResult();
if (scrape != null && scrape.getResponseType() == DownloadScrapeResult.RT_SUCCESS) {
pw.println("<vuze:seeds>" + scrape.getSeedCount() + "</vuze:seeds>");
pw.println("<vuze:peers>" + scrape.getNonSeedCount() + "</vuze:peers>");
}
pw.println("</item>");
}
pw.println("</channel>");
pw.println("</rss>");
pw.flush();
return (new feedDetails(os.toByteArray(), last_modified));
} catch (IOException e) {
throw (new BuddyPluginException("", e));
}
}
Aggregations