Search in sources :

Example 1 with SubscriptionManager

use of com.biglybt.core.subs.SubscriptionManager in project BiglyBT by BiglySoftware.

the class AZPluginConnection method connect.

@Override
public void connect() throws IOException {
    String url = getURL().toString();
    int pos = url.indexOf("?");
    if (pos == -1) {
        throw (new IOException("Malformed URL - ? missing"));
    }
    url = url.substring(pos + 1);
    String[] bits = url.split("&");
    Map args = new HashMap();
    for (int i = 0; i < bits.length; i++) {
        String bit = bits[i];
        String[] x = bit.split("=");
        if (x.length == 2) {
            String lhs = x[0];
            String rhs = UrlUtils.decode(x[1]);
            args.put(lhs.toLowerCase(), rhs);
        }
    }
    String plugin_id = (String) args.get("id");
    if (plugin_id == null) {
        throw (new IOException("Plugin id missing"));
    }
    String plugin_name = (String) args.get("name");
    String arg = (String) args.get("arg");
    if (arg == null) {
        arg = "";
    }
    String plugin_str;
    if (plugin_name == null) {
        plugin_str = "with id '" + plugin_id + "'";
    } else {
        plugin_str = "'" + plugin_name + "' (id " + plugin_id + ")";
    }
    if (plugin_id.equals("subscription")) {
        SubscriptionManager manager = SubscriptionManagerFactory.getSingleton();
        if (manager == null) {
            throw (new IOException("Subscriptions are not available"));
        }
        try {
            manager.subscribeToSubscription(arg);
            input_stream = new ByteArrayInputStream(VuzeFileHandler.getSingleton().create().exportToBytes());
        } catch (Throwable e) {
            throw (new IOException("Subscription addition failed: " + Debug.getNestedExceptionMessage(e)));
        }
    } else {
        // AZPluginConnection is called via reflection
        // Let's just assume that the Core is avail..
        PluginInterface pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByID(plugin_id);
        if (pi == null) {
            throw (new IOException("Plugin " + plugin_str + " is required - go to 'Tools->Plugins->Installation Wizard' to install."));
        }
        IPCInterface ipc = pi.getIPC();
        try {
            if (ipc.canInvoke("handleURLProtocol", new Object[] { this, arg })) {
                input_stream = (InputStream) ipc.invoke("handleURLProtocol", new Object[] { this, arg });
            } else {
                input_stream = (InputStream) ipc.invoke("handleURLProtocol", new Object[] { arg });
            }
        } catch (IPCException ipce) {
            Throwable e = ipce;
            if (e.getCause() != null) {
                e = e.getCause();
            }
            throw (new IOException("Communication error with plugin '" + plugin_str + "': " + Debug.getNestedExceptionMessage(e)));
        }
    }
}
Also used : HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) PluginInterface(com.biglybt.pif.PluginInterface) IPCException(com.biglybt.pif.ipc.IPCException) IOException(java.io.IOException) SubscriptionManager(com.biglybt.core.subs.SubscriptionManager) HashMap(java.util.HashMap) Map(java.util.Map) IPCInterface(com.biglybt.pif.ipc.IPCInterface)

Example 2 with SubscriptionManager

use of com.biglybt.core.subs.SubscriptionManager in project BiglyBT by BiglySoftware.

the class SubscriptionListWindow method startChecking.

private void startChecking() {
    action.setText(MessageText.getString("subscriptions.listwindow.subscribe"));
    action.setEnabled(false);
    try {
        SubscriptionManager subs_man = SubscriptionManagerFactory.getSingleton();
        if (useCachedSubs) {
            Subscription[] subs = subs_man.getKnownSubscriptions(torrent_hash);
            complete(torrent_hash, subs);
        } else {
            lookup = subs_man.lookupAssociations(torrent_hash, display_name, networks, this);
            lookup.setTimeout(1 * 60 * 1000);
        }
        loadingDone = false;
        AEThread2 progressMover = new AEThread2("progressMover", true) {

            @Override
            public void run() {
                final int[] waitTime = new int[1];
                waitTime[0] = 100;
                while (!loadingDone) {
                    if (display != null && !display.isDisposed()) {
                        display.asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                if (loadingProgress != null && !loadingProgress.isDisposed()) {
                                    int currentSelection = loadingProgress.getSelection() + 1;
                                    loadingProgress.setSelection(currentSelection);
                                    if (currentSelection > (loadingProgress.getMaximum()) * 80 / 100) {
                                        waitTime[0] = 300;
                                    }
                                    if (currentSelection > (loadingProgress.getMaximum()) * 90 / 100) {
                                        waitTime[0] = 1000;
                                    }
                                } else {
                                    loadingDone = true;
                                }
                            }
                        });
                    }
                    try {
                        Thread.sleep(waitTime[0]);
                    // Thread.sleep(100);
                    } catch (Exception e) {
                        loadingDone = true;
                    }
                }
            }
        };
        progressMover.start();
    } catch (Exception e) {
        failed(null, null);
    }
    animatedImage.start();
    mainLayout.topControl = loadingPanel;
}
Also used : SubscriptionManager(com.biglybt.core.subs.SubscriptionManager) Subscription(com.biglybt.core.subs.Subscription) AEThread2(com.biglybt.core.util.AEThread2) SubscriptionException(com.biglybt.core.subs.SubscriptionException)

Example 3 with SubscriptionManager

use of com.biglybt.core.subs.SubscriptionManager in project BiglyBT by BiglySoftware.

the class EngineImpl method getSubscription.

@Override
public Subscription getSubscription() {
    try {
        VuzeFile vf = exportToVuzeFile(true);
        byte[] bytes = vf.exportToBytes();
        String url_str = "vuze://?body=" + new String(bytes, Constants.BYTE_ENCODING);
        boolean is_anon = isAnonymous();
        SubscriptionManager sub_man = SubscriptionManagerFactory.getSingleton();
        Subscription subs = sub_man.createSingletonRSS(vf.getName() + ": " + getName() + " (v" + getVersion() + ")", new URL(url_str), Integer.MAX_VALUE, is_anon);
        return (subs);
    } catch (Throwable e) {
        Debug.out(e);
    }
    return (null);
}
Also used : VuzeFile(com.biglybt.core.vuzefile.VuzeFile) SubscriptionManager(com.biglybt.core.subs.SubscriptionManager) Subscription(com.biglybt.core.subs.Subscription) URL(java.net.URL)

Aggregations

SubscriptionManager (com.biglybt.core.subs.SubscriptionManager)3 Subscription (com.biglybt.core.subs.Subscription)2 SubscriptionException (com.biglybt.core.subs.SubscriptionException)1 AEThread2 (com.biglybt.core.util.AEThread2)1 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)1 PluginInterface (com.biglybt.pif.PluginInterface)1 IPCException (com.biglybt.pif.ipc.IPCException)1 IPCInterface (com.biglybt.pif.ipc.IPCInterface)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1