Search in sources :

Example 11 with PluginConfig

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

Example 12 with PluginConfig

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));
    }
}
Also used : Torrent(com.biglybt.pif.torrent.Torrent) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) DownloadManager(com.biglybt.core.download.DownloadManager) PluginConfig(com.biglybt.pif.PluginConfig) OutputStreamWriter(java.io.OutputStreamWriter) Tag(com.biglybt.core.tag.Tag) Download(com.biglybt.pif.download.Download) DownloadScrapeResult(com.biglybt.pif.download.DownloadScrapeResult) PrintWriter(java.io.PrintWriter)

Aggregations

PluginConfig (com.biglybt.pif.PluginConfig)12 DownloadManager (com.biglybt.core.download.DownloadManager)1 MessageText (com.biglybt.core.internat.MessageText)1 CryptoHandler (com.biglybt.core.security.CryptoHandler)1 CryptoManager (com.biglybt.core.security.CryptoManager)1 CryptoManagerKeyListener (com.biglybt.core.security.CryptoManagerKeyListener)1 Tag (com.biglybt.core.tag.Tag)1 UPnPWANConnectionPortMapping (com.biglybt.net.upnp.services.UPnPWANConnectionPortMapping)1 PluginListener (com.biglybt.pif.PluginListener)1 Download (com.biglybt.pif.download.Download)1 DownloadScrapeResult (com.biglybt.pif.download.DownloadScrapeResult)1 LoggerChannel (com.biglybt.pif.logging.LoggerChannel)1 LoggerChannelListener (com.biglybt.pif.logging.LoggerChannelListener)1 Torrent (com.biglybt.pif.torrent.Torrent)1 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)1 UIManager (com.biglybt.pif.ui.UIManager)1 UIManagerEvent (com.biglybt.pif.ui.UIManagerEvent)1 BasicPluginConfigModel (com.biglybt.pif.ui.model.BasicPluginConfigModel)1 BasicPluginViewModel (com.biglybt.pif.ui.model.BasicPluginViewModel)1 DelayedTask (com.biglybt.pif.utils.DelayedTask)1