use of com.biglybt.pif.PluginConfig in project BiglyBT by BiglySoftware.
the class BuddyPlugin method setClassicEnabled.
public boolean setClassicEnabled(boolean enabled, boolean auto) {
if (classic_enabled_param == null) {
return (false);
}
if (enabled && auto && !classic_enabled_param.getValue()) {
PluginConfig config = plugin_interface.getPluginconfig();
if (config.getPluginBooleanParameter("classic.auto.enable.done", false)) {
return (false);
}
config.setPluginParameter("classic.auto.enable.done", true);
}
classic_enabled_param.setValue(enabled);
return (enabled);
}
use of com.biglybt.pif.PluginConfig 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=" + buddy.getPluginNetwork().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