Search in sources :

Example 21 with ResourceDownloader

use of com.biglybt.pif.utils.resourcedownloader.ResourceDownloader in project BiglyBT by BiglySoftware.

the class UtilitiesImpl method getRSSFeed.

@Override
public RSSFeed getRSSFeed(URL feed_location) throws ResourceDownloaderException, SimpleXMLParserDocumentException {
    String feed_str = feed_location.toExternalForm();
    String lc_feed_str = feed_str.toLowerCase(Locale.US);
    ResourceDownloader rd;
    PluginProxy plugin_proxy = null;
    try {
        if (lc_feed_str.startsWith("tor:")) {
            String target_resource = feed_str.substring(4);
            try {
                feed_location = new URL(target_resource);
            } catch (MalformedURLException e) {
                throw (new ResourceDownloaderException(e));
            }
            Map<String, Object> options = new HashMap<>();
            options.put(AEProxyFactory.PO_PEER_NETWORKS, new String[] { AENetworkClassifier.AT_TOR });
            plugin_proxy = AEProxyFactory.getPluginProxy("RSS Feed download of '" + target_resource + "'", feed_location, options, true);
            if (plugin_proxy == null) {
                throw (new ResourceDownloaderException("No Tor plugin proxy available for '" + feed_str + "'"));
            }
            rd = getResourceDownloaderFactory().create(plugin_proxy.getURL(), plugin_proxy.getProxy());
            rd.setProperty("URL_HOST", plugin_proxy.getURLHostRewrite() + (feed_location.getPort() == -1 ? "" : (":" + feed_location.getPort())));
        } else {
            if (AENetworkClassifier.categoriseAddress(feed_location.getHost()) != AENetworkClassifier.AT_PUBLIC) {
                plugin_proxy = AEProxyFactory.getPluginProxy("RSS Feed download of '" + feed_location + "'", feed_location, true);
                if (plugin_proxy == null) {
                    throw (new ResourceDownloaderException("No Plugin proxy available for '" + feed_str + "'"));
                }
                rd = getResourceDownloaderFactory().create(plugin_proxy.getURL(), plugin_proxy.getProxy());
                rd.setProperty("URL_HOST", plugin_proxy.getURLHostRewrite() + (feed_location.getPort() == -1 ? "" : (":" + feed_location.getPort())));
            } else {
                rd = getResourceDownloaderFactory().create(feed_location);
            }
        }
        return (getRSSFeed(feed_location, rd));
    } finally {
        if (plugin_proxy != null) {
            plugin_proxy.setOK(true);
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException) PluginProxy(com.biglybt.core.proxy.AEProxyFactory.PluginProxy) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) URL(java.net.URL)

Example 22 with ResourceDownloader

use of com.biglybt.pif.utils.resourcedownloader.ResourceDownloader in project BiglyBT by BiglySoftware.

the class ImageBytesDownloader method loadImage.

public static void loadImage(final String url, final ImageDownloaderListener l) {
    // System.out.println("download " + url);
    mon_map.enter();
    try {
        List<ImageDownloaderListener> list = map.get(url);
        if (list != null) {
            list.add(l);
            return;
        }
        list = new ArrayList<>(1);
        list.add(l);
        map.put(url, list);
    } finally {
        mon_map.exit();
    }
    try {
        URL u = new URL(url);
        ResourceDownloader rd;
        if (AENetworkClassifier.categoriseAddress(u.getHost()) == AENetworkClassifier.AT_PUBLIC) {
            rd = ResourceDownloaderFactoryImpl.getSingleton().create(u);
        } else {
            rd = ResourceDownloaderFactoryImpl.getSingleton().createWithAutoPluginProxy(u);
        }
        rd.addListener(new ResourceDownloaderAdapter() {

            @Override
            public boolean completed(ResourceDownloader downloader, InputStream is) {
                mon_map.enter();
                try {
                    List<ImageDownloaderListener> list = map.get(url);
                    if (list != null) {
                        try {
                            if (is != null && is.available() > 0) {
                                byte[] newImageBytes = new byte[is.available()];
                                is.read(newImageBytes);
                                for (ImageDownloaderListener l : list) {
                                    try {
                                        l.imageDownloaded(newImageBytes);
                                    } catch (Exception e) {
                                        Debug.out(e);
                                    }
                                }
                            }
                        } catch (Exception e) {
                            Debug.out(e);
                        }
                    }
                    map.remove(url);
                } finally {
                    mon_map.exit();
                }
                return false;
            }
        });
        rd.asyncDownload();
    } catch (Exception e) {
        Debug.out(url, e);
    }
}
Also used : ResourceDownloaderAdapter(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter) InputStream(java.io.InputStream) List(java.util.List) ArrayList(java.util.ArrayList) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) URL(java.net.URL)

Example 23 with ResourceDownloader

use of com.biglybt.pif.utils.resourcedownloader.ResourceDownloader in project BiglyBT by BiglySoftware.

the class UPNPMSBrowserImpl method getXML.

private SimpleXMLParserDocument getXML(URL url, String soap_action, String post_data) throws UPnPMSException {
    ResourceDownloader rd = new ResourceDownloaderFactoryImpl().create(url, post_data);
    try {
        rd.setProperty("URL_Connection", "Keep-Alive");
        rd.setProperty("URL_Read_Timeout", 10 * 60 * 1000);
        rd.setProperty("URL_Connect_Timeout", 5 * 60 * 1000);
        rd.setProperty("URL_SOAPAction", "\"" + soap_action + "\"");
        rd.setProperty("URL_X-AV-Client-Info", "av=1.0; cn=\"" + Constants.AZUREUS_NAME + "\"; mn=\"" + client_name + "\"; mv=\"" + Constants.AZUREUS_VERSION + "\"");
        rd.setProperty("URL_Content-Type", "text/xml; charset=\"utf-8\"");
        SimpleXMLParserDocument doc = SimpleXMLParserDocumentFactory.create(url, rd.download());
        return (doc);
    } catch (Throwable e) {
        throw (new UPnPMSException("XML RPC failed", e));
    }
}
Also used : SimpleXMLParserDocument(com.biglybt.pif.utils.xml.simpleparser.SimpleXMLParserDocument) UPnPMSException(com.biglybt.net.upnpms.UPnPMSException) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) ResourceDownloaderFactoryImpl(com.biglybt.pifimpl.local.utils.resourcedownloader.ResourceDownloaderFactoryImpl)

Example 24 with ResourceDownloader

use of com.biglybt.pif.utils.resourcedownloader.ResourceDownloader in project BiglyBT by BiglySoftware.

the class MagnetPlugin method doSecondaryLookup.

protected void doSecondaryLookup(final MagnetPluginProgressListener listener, final Object[] result, byte[] hash, Set<String> networks_enabled, String args) {
    if (listener != null) {
        listener.reportActivity(getMessageText("report.secondarylookup", null));
    }
    PluginProxy plugin_proxy = null;
    try {
        URL original_sl_url = new URL(SECONDARY_LOOKUP + "magnetLookup?hash=" + Base32.encode(hash) + (args.length() == 0 ? "" : ("&args=" + UrlUtils.encode(args))));
        URL sl_url = original_sl_url;
        Proxy proxy = null;
        if (!networks_enabled.contains(AENetworkClassifier.AT_PUBLIC)) {
            plugin_proxy = AEProxyFactory.getPluginProxy("secondary magnet lookup", sl_url);
            if (plugin_proxy == null) {
                throw (new NoRouteToHostException("plugin proxy unavailable"));
            } else {
                proxy = plugin_proxy.getProxy();
                sl_url = plugin_proxy.getURL();
            }
        }
        ResourceDownloaderFactory rdf = plugin_interface.getUtilities().getResourceDownloaderFactory();
        ResourceDownloader rd;
        if (proxy == null) {
            rd = rdf.create(sl_url);
        } else {
            rd = rdf.create(sl_url, proxy);
            rd.setProperty("URL_HOST", original_sl_url.getHost());
        }
        final PluginProxy f_pp = plugin_proxy;
        rd.addListener(new ResourceDownloaderAdapter() {

            @Override
            public boolean completed(ResourceDownloader downloader, InputStream data) {
                try {
                    if (listener != null) {
                        listener.reportActivity(getMessageText("report.secondarylookup.ok", null));
                    }
                    synchronized (result) {
                        result[0] = data;
                    }
                    return (true);
                } finally {
                    complete();
                }
            }

            @Override
            public void failed(ResourceDownloader downloader, ResourceDownloaderException e) {
                try {
                    synchronized (result) {
                        result[0] = e;
                    }
                    if (listener != null) {
                        listener.reportActivity(getMessageText("report.secondarylookup.fail"));
                    }
                } finally {
                    complete();
                }
            }

            private void complete() {
                if (f_pp != null) {
                    // outcome doesn't really indicate whether the result was wholesome
                    f_pp.setOK(true);
                }
            }
        });
        rd.asyncDownload();
    } catch (Throwable e) {
        if (plugin_proxy != null) {
            // tidy up, no indication of proxy badness here so say its ok
            plugin_proxy.setOK(true);
        }
        if (listener != null) {
            listener.reportActivity(getMessageText("report.secondarylookup.fail", Debug.getNestedExceptionMessage(e)));
        }
    }
}
Also used : Proxy(java.net.Proxy) PluginProxy(com.biglybt.core.proxy.AEProxyFactory.PluginProxy) ResourceDownloaderAdapter(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter) InputStream(java.io.InputStream) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException) PluginProxy(com.biglybt.core.proxy.AEProxyFactory.PluginProxy) ResourceDownloaderFactory(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderFactory) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) NoRouteToHostException(java.net.NoRouteToHostException) URL(java.net.URL)

Example 25 with ResourceDownloader

use of com.biglybt.pif.utils.resourcedownloader.ResourceDownloader in project BiglyBT by BiglySoftware.

the class PlatformManagerUpdateChecker method checkForUpdate.

@Override
public void checkForUpdate(final UpdateChecker checker) {
    try {
        SFPluginDetails sf_details = SFPluginDetailsLoaderFactory.getSingleton().getPluginDetails(plugin_interface.getPluginID());
        String current_version = plugin_interface.getPluginVersion();
        if (Logger.isEnabled())
            Logger.log(new LogEvent(LOGID, "PlatformManager:Win32 update check starts: current = " + current_version));
        boolean current_az_is_cvs = Constants.isCVSVersion();
        String sf_plugin_version = sf_details.getVersion();
        String sf_comp_version = sf_plugin_version;
        if (current_az_is_cvs) {
            String sf_cvs_version = sf_details.getCVSVersion();
            if (sf_cvs_version.length() > 0) {
                // sf cvs version ALWAYS entry in _CVS
                sf_plugin_version = sf_cvs_version;
                sf_comp_version = sf_plugin_version.substring(0, sf_plugin_version.length() - 4);
            }
        }
        String target_version = null;
        if (sf_comp_version.length() == 0 || !Character.isDigit(sf_comp_version.charAt(0))) {
            if (Logger.isEnabled())
                Logger.log(new LogEvent(LOGID, LogEvent.LT_WARNING, "PlatformManager:Win32 no valid version to check against (" + sf_comp_version + ")"));
        } else if (Constants.compareVersions(current_version, sf_comp_version) < 0) {
            target_version = sf_comp_version;
        }
        checker.reportProgress("Win32: current = " + current_version + ", latest = " + sf_comp_version);
        if (Logger.isEnabled())
            Logger.log(new LogEvent(LOGID, "PlatformManager:Win32 update required = " + (target_version != null)));
        if (target_version != null) {
            String target_download = sf_details.getDownloadURL();
            if (current_az_is_cvs) {
                String sf_cvs_version = sf_details.getCVSVersion();
                if (sf_cvs_version.length() > 0) {
                    target_download = sf_details.getCVSDownloadURL();
                }
            }
            ResourceDownloaderFactory rdf = ResourceDownloaderFactoryImpl.getSingleton();
            ResourceDownloader direct_rdl = rdf.create(new URL(target_download));
            String torrent_download = Constants.URL_PLUGINS_TORRENT_BASE;
            int slash_pos = target_download.lastIndexOf("/");
            if (slash_pos == -1) {
                torrent_download += target_download;
            } else {
                torrent_download += target_download.substring(slash_pos + 1);
            }
            torrent_download += ".torrent";
            if (I2PHelpers.isI2PInstalled()) {
                torrent_download += "?i2p=1";
            }
            ResourceDownloader torrent_rdl = rdf.create(new URL(torrent_download));
            torrent_rdl = rdf.getSuffixBasedDownloader(torrent_rdl);
            // create an alternate downloader with torrent attempt first
            ResourceDownloader alternate_rdl = rdf.getAlternateDownloader(new ResourceDownloader[] { torrent_rdl, direct_rdl });
            // get size here so it is cached
            rdf.getTimeoutDownloader(rdf.getRetryDownloader(alternate_rdl, RD_SIZE_RETRIES), RD_SIZE_TIMEOUT).getSize();
            List update_desc = new ArrayList();
            List desc_lines = HTMLUtils.convertHTMLToText("", sf_details.getDescription());
            update_desc.addAll(desc_lines);
            List comment_lines = HTMLUtils.convertHTMLToText("    ", sf_details.getComment());
            update_desc.addAll(comment_lines);
            String[] update_d = new String[update_desc.size()];
            update_desc.toArray(update_d);
            final Update update = checker.addUpdate(UPDATE_NAME, update_d, current_version, target_version, alternate_rdl, Update.RESTART_REQUIRED_YES);
            update.setDescriptionURL(sf_details.getInfoURL());
            alternate_rdl.addListener(new ResourceDownloaderAdapter() {

                @Override
                public boolean completed(final ResourceDownloader downloader, InputStream data) {
                    installUpdate(checker, update, downloader, data);
                    return (true);
                }

                @Override
                public void failed(ResourceDownloader downloader, ResourceDownloaderException e) {
                    // Debug.out( downloader.getName() + " failed", e );
                    update.complete(false);
                }
            });
        }
    } catch (Throwable e) {
        Debug.printStackTrace(e);
        checker.reportProgress("Failed to load plugin details for the platform manager: " + Debug.getNestedExceptionMessage(e));
        checker.failed();
    } finally {
        checker.completed();
    }
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException) ArrayList(java.util.ArrayList) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) Update(com.biglybt.pif.update.Update) URL(java.net.URL) ResourceDownloaderAdapter(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter) ResourceDownloaderFactory(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderFactory) ArrayList(java.util.ArrayList) List(java.util.List) SFPluginDetails(com.biglybt.pifimpl.update.sf.SFPluginDetails)

Aggregations

ResourceDownloader (com.biglybt.pif.utils.resourcedownloader.ResourceDownloader)37 URL (java.net.URL)18 ResourceDownloaderException (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException)16 InputStream (java.io.InputStream)14 ResourceDownloaderAdapter (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter)12 ResourceDownloaderFactory (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderFactory)11 Update (com.biglybt.pif.update.Update)9 LogEvent (com.biglybt.core.logging.LogEvent)7 PluginProxy (com.biglybt.core.proxy.AEProxyFactory.PluginProxy)6 ZipInputStream (java.util.zip.ZipInputStream)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)4 SFPluginDetails (com.biglybt.pifimpl.update.sf.SFPluginDetails)4 LogAlert (com.biglybt.core.logging.LogAlert)3 AESemaphore (com.biglybt.core.util.AESemaphore)3 PluginException (com.biglybt.pif.PluginException)3 InstallablePlugin (com.biglybt.pif.installer.InstallablePlugin)3 PluginInstallationListener (com.biglybt.pif.installer.PluginInstallationListener)3 StandardPlugin (com.biglybt.pif.installer.StandardPlugin)3