Search in sources :

Example 6 with Engine

use of com.biglybt.core.metasearch.Engine in project BiglyBT by BiglySoftware.

the class SubscriptionManagerImpl method requestSubscription.

@Override
public void requestSubscription(SearchProvider sp, Map<String, Object> search_parameters) throws com.biglybt.pif.utils.subscriptions.SubscriptionException {
    try {
        Engine engine = MetaSearchManagerFactory.getSingleton().getEngine(sp);
        if (engine == null) {
            throw (new SubscriptionException("Engine not found "));
        }
        Boolean anonymous = (Boolean) search_parameters.get("_anonymous_");
        String term = (String) search_parameters.get(SearchProvider.SP_SEARCH_TERM);
        String[] networks = (String[]) search_parameters.get(SearchProvider.SP_NETWORKS);
        String networks_str = null;
        if (networks != null && networks.length > 0) {
            networks_str = "";
            for (String network : networks) {
                networks_str += (networks_str.length() == 0 ? "" : ",") + network;
            }
        }
        String json = SubscriptionImpl.getSkeletonJSON(engine, term, networks_str, 60);
        String name = (String) search_parameters.get(SearchProvider.SP_SEARCH_NAME);
        if (name == null || name.length() == 0) {
            name = engine.getName() + ": " + search_parameters.get(SearchProvider.SP_SEARCH_TERM);
        }
        boolean anon = anonymous != null && anonymous;
        SubscriptionImpl subs = new SubscriptionImpl(this, name, engine.isPublic(), anon, null, json, SubscriptionImpl.ADD_TYPE_CREATE);
        if (anon) {
            subs.getHistory().setDownloadNetworks(new String[] { AENetworkClassifier.AT_I2P });
        }
        log("Created new subscription: " + subs.getString());
        subs = addSubscription(subs);
        Number freq = (Number) search_parameters.get("_frequency_");
        if (freq != null) {
            subs.getHistory().setCheckFrequencyMins(freq.intValue());
        }
        if (subs.isPublic()) {
            updatePublicSubscription(subs);
        }
        Boolean silent = (Boolean) search_parameters.get("_silent_");
        if (silent == null || !silent) {
            subs.requestAttention();
        }
    } catch (Throwable e) {
        throw (new com.biglybt.pif.utils.subscriptions.SubscriptionException("Failed to create subscription", e));
    }
}
Also used : WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine) Engine(com.biglybt.core.metasearch.Engine) RSSEngine(com.biglybt.core.metasearch.impl.web.rss.RSSEngine)

Example 7 with Engine

use of com.biglybt.core.metasearch.Engine in project BiglyBT by BiglySoftware.

the class SubscriptionManagerImpl method getEngine.

protected Engine getEngine(SubscriptionImpl subs, Map json_map, boolean local_only) throws SubscriptionException {
    long id = ((Long) json_map.get("engine_id")).longValue();
    Engine engine = MetaSearchManagerFactory.getSingleton().getMetaSearch().getEngine(id);
    if (engine != null) {
        return (engine);
    }
    if (!local_only) {
        try {
            if (id >= 0 && id < Integer.MAX_VALUE) {
                log("Engine " + id + " not present, loading");
                try {
                    engine = MetaSearchManagerFactory.getSingleton().getMetaSearch().addEngine(id);
                    return (engine);
                } catch (Throwable e) {
                    throw (new SubscriptionException("Failed to load engine '" + id + "'", e));
                }
            }
        } catch (Throwable e) {
            log("Failed to load search template", e);
        }
    }
    engine = subs.extractEngine(json_map, id);
    if (engine != null) {
        return (engine);
    }
    throw (new SubscriptionException("Failed to extract engine id " + id));
}
Also used : WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine) Engine(com.biglybt.core.metasearch.Engine) RSSEngine(com.biglybt.core.metasearch.impl.web.rss.RSSEngine)

Example 8 with Engine

use of com.biglybt.core.metasearch.Engine in project BiglyBT by BiglySoftware.

the class BuddyPluginViewBetaChat method checkSubscriptions.

private void checkSubscriptions(boolean ftux_change) {
    Subscription[] subs = SubscriptionManagerFactory.getSingleton().getSubscriptions();
    for (Subscription sub : subs) {
        try {
            Engine e = sub.getEngine();
            if (e instanceof WebEngine) {
                String url = ((WebEngine) e).getSearchUrl();
                if (isRSSURL(url, chat)) {
                    if (ftux_change) {
                        SubscriptionResult[] results = sub.getResults(false);
                        for (SubscriptionResult r : results) {
                            Map<Integer, Object> properties = r.toPropertyMap();
                            String name = (String) properties.get(SearchResult.PR_NAME);
                            if (name.equals(BuddyPluginBeta.RSS_ITEMS_UNAVAILABLE)) {
                                r.delete();
                            }
                        }
                    } else {
                        sub.getManager().getScheduler().downloadAsync(sub, true);
                    }
                }
            }
        } catch (Throwable e) {
        }
    }
}
Also used : SubscriptionResult(com.biglybt.core.subs.SubscriptionResult) Subscription(com.biglybt.core.subs.Subscription) WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine) Engine(com.biglybt.core.metasearch.Engine) WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine)

Example 9 with Engine

use of com.biglybt.core.metasearch.Engine in project BiglyBT by BiglySoftware.

the class SBC_SearchResultsView method downloadAction.

public static void downloadAction(final SearchSubsResultBase entry) {
    String link = entry.getTorrentLink();
    if (link.startsWith("chat:")) {
        Utils.launch(link);
        return;
    }
    showDownloadFTUX(entry, new UserPrompterResultListener() {

        @Override
        public void prompterClosed(int result) {
            if (result == 0) {
                String referer_str = null;
                String torrentUrl = entry.getTorrentLink();
                try {
                    Map headers = UrlUtils.getBrowserHeaders(referer_str);
                    if (entry instanceof SBC_SubscriptionResult) {
                        SBC_SubscriptionResult sub_entry = (SBC_SubscriptionResult) entry;
                        Subscription subs = sub_entry.getSubscription();
                        try {
                            Engine engine = subs.getEngine();
                            if (engine != null && engine instanceof WebEngine) {
                                WebEngine webEngine = (WebEngine) engine;
                                if (webEngine.isNeedsAuth()) {
                                    headers.put("Cookie", webEngine.getCookies());
                                }
                            }
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                        subs.addPotentialAssociation(sub_entry.getID(), torrentUrl);
                    } else {
                        SBC_SearchResult search_entry = (SBC_SearchResult) entry;
                        Engine engine = search_entry.getEngine();
                        if (engine != null) {
                            engine.addPotentialAssociation(torrentUrl);
                            if (engine instanceof WebEngine) {
                                WebEngine webEngine = (WebEngine) engine;
                                if (webEngine.isNeedsAuth()) {
                                    headers.put("Cookie", webEngine.getCookies());
                                }
                            }
                        }
                    }
                    byte[] torrent_hash = entry.getHash();
                    if (torrent_hash != null) {
                        if (torrent_hash != null && !torrentUrl.toLowerCase().startsWith("magnet")) {
                            String title = entry.getName();
                            String magnet = UrlUtils.getMagnetURI(torrent_hash, title, null);
                            headers.put("X-Alternative-URI-1", magnet);
                        }
                    }
                    PluginInitializer.getDefaultInterface().getDownloadManager().addDownload(new URL(torrentUrl), headers);
                } catch (Throwable e) {
                    Debug.out(e);
                }
            }
        }
    });
}
Also used : UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) Subscription(com.biglybt.core.subs.Subscription) WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine) Engine(com.biglybt.core.metasearch.Engine) WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine) URL(java.net.URL) SBC_SubscriptionResult(com.biglybt.ui.swt.subscriptions.SBC_SubscriptionResult)

Example 10 with Engine

use of com.biglybt.core.metasearch.Engine in project BiglyBT by BiglySoftware.

the class SBC_SearchResultsView method buildEngineArea.

private void buildEngineArea(final SearchInstance search) {
    if (engine_area.isDisposed()) {
        return;
    }
    final Engine[] engines = search == null ? new Engine[0] : search.getEngines();
    Utils.disposeComposite(engine_area, false);
    Arrays.sort(engines, new Comparator<Engine>() {

        @Override
        public int compare(Engine o1, Engine o2) {
            return (o1.getName().compareTo(o2.getName()));
        }
    });
    RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
    rowLayout.spacing = 3;
    rowLayout.marginBottom = rowLayout.marginTop = rowLayout.marginLeft = rowLayout.marginRight = 0;
    rowLayout.pack = false;
    engine_area.setLayout(rowLayout);
    final Composite label_comp = new Composite(engine_area, SWT.NULL);
    GridLayout layout = new GridLayout();
    layout.marginBottom = layout.marginTop = layout.marginLeft = layout.marginRight = 1;
    label_comp.setLayout(layout);
    Label label = new Label(label_comp, SWT.NULL);
    Messages.setLanguageText(label, "label.show.results.from");
    GridData grid_data = new GridData(SWT.LEFT, SWT.CENTER, true, true);
    label.setLayoutData(grid_data);
    final List<Button> buttons = new ArrayList<>();
    final List<Label> result_counts = new ArrayList<>();
    final List<ImageLabel> indicators = new ArrayList<>();
    label.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            deselected_engines.clear();
            for (Button b : buttons) {
                b.setSelection(true);
            }
            refilter();
        }
    });
    for (final Engine engine : engines) {
        final Composite engine_comp = new Composite(engine_area, SWT.NULL);
        layout = new GridLayout(3, false);
        layout.marginBottom = layout.marginTop = layout.marginLeft = layout.marginRight = 1;
        engine_comp.setLayout(layout);
        engine_comp.addPaintListener(new PaintListener() {

            @Override
            public void paintControl(PaintEvent e) {
                GC gc = e.gc;
                gc.setForeground(Colors.grey);
                Point size = engine_comp.getSize();
                gc.drawRectangle(new Rectangle(0, 0, size.x - 1, size.y - 1));
            }
        });
        final Button button = new Button(engine_comp, SWT.CHECK);
        button.setData(engine);
        buttons.add(button);
        button.setText(engine.getName());
        button.setSelection(!deselected_engines.contains(engine.getUID()));
        Image image = getIcon(engine, new ImageLoadListener() {

            @Override
            public void imageLoaded(Image image) {
                button.setImage(image);
            }
        });
        if (image != null) {
            try {
                button.setImage(image);
            } catch (Throwable e) {
            }
        }
        button.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                String id = engine.getUID();
                if (button.getSelection()) {
                    deselected_engines.remove(id);
                } else {
                    deselected_engines.add(id);
                }
                refilter();
            }
        });
        Menu menu = new Menu(button);
        button.setMenu(menu);
        MenuItem mi = new MenuItem(menu, SWT.PUSH);
        mi.setText(MessageText.getString("label.this.site.only"));
        mi.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                deselected_engines.clear();
                button.setSelection(true);
                for (Button b : buttons) {
                    if (b != button) {
                        b.setSelection(false);
                        deselected_engines.add(((Engine) b.getData()).getUID());
                    }
                }
                refilter();
            }
        });
        MenuItem miCreateSubscription = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(miCreateSubscription, "menu.search.create.subscription");
        miCreateSubscription.addSelectionListener(new SelectionListener() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                Map filterMap = buildFilterMap();
                SearchUtils.showCreateSubscriptionDialog(engine.getId(), current_search.sq.term, filterMap);
            }

            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
            }
        });
        SearchUtils.addMenus(menu, engine, true);
        Label results = new Label(engine_comp, SWT.NULL);
        GC temp = new GC(results);
        Point size = temp.textExtent("(888)");
        temp.dispose();
        GridData gd = new GridData();
        gd.widthHint = Utils.adjustPXForDPI(size.x);
        results.setLayoutData(gd);
        result_counts.add(results);
        ImageLabel indicator = new ImageLabel(engine_comp, vitality_images[0]);
        indicators.add(indicator);
        indicator.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseDown(MouseEvent e) {
                deselected_engines.clear();
                boolean only_me_selected = button.getSelection();
                if (only_me_selected) {
                    for (Button b : buttons) {
                        if (b != button) {
                            if (b.getSelection()) {
                                only_me_selected = false;
                            }
                        }
                    }
                }
                if (only_me_selected) {
                    button.setSelection(false);
                    deselected_engines.add(engine.getUID());
                    for (Button b : buttons) {
                        if (b != button) {
                            b.setSelection(true);
                        }
                    }
                } else {
                    button.setSelection(true);
                    for (Button b : buttons) {
                        if (b != button) {
                            b.setSelection(false);
                            deselected_engines.add(((Engine) b.getData()).getUID());
                        }
                    }
                }
                refilter();
            }
        });
    }
    Composite cAddEdit = new Composite(engine_area, SWT.NONE);
    cAddEdit.setLayout(new GridLayout());
    Button btnAddEdit = new Button(cAddEdit, SWT.PUSH);
    btnAddEdit.setLayoutData(new GridData(SWT.CENTER, 0, true, true));
    Messages.setLanguageText(btnAddEdit, "button.add.edit.search.templates");
    btnAddEdit.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            UIFunctions functions = UIFunctionsManager.getUIFunctions();
            if (functions != null) {
                functions.viewURL(Constants.URL_SEARCH_ADDEDIT, null, "");
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    Composite cCreateTemplate = new Composite(engine_area, SWT.NONE);
    cCreateTemplate.setLayout(new GridLayout());
    Button btnCreateTemplate = new Button(cCreateTemplate, SWT.PUSH);
    btnCreateTemplate.setLayoutData(new GridData(SWT.CENTER, 0, true, true));
    Messages.setLanguageText(btnCreateTemplate, "menu.search.create.subscription");
    btnCreateTemplate.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Map filterMap = buildFilterMap();
            SearchUtils.showCreateSubscriptionDialog(-1, current_search.sq.term, buildFilterMap());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    if (engines.length > 0) {
        new AEThread2("updater") {

            int ticks;

            int image_index = 0;

            volatile boolean running = true;

            @Override
            public void run() {
                while (running) {
                    if (label_comp.isDisposed()) {
                        return;
                    }
                    try {
                        Thread.sleep(100);
                    } catch (Throwable e) {
                    }
                    Utils.execSWTThread(new Runnable() {

                        @Override
                        public void run() {
                            if (label_comp.isDisposed()) {
                                return;
                            }
                            ticks++;
                            image_index++;
                            if (image_index == vitality_images.length) {
                                image_index = 0;
                            }
                            boolean do_results = ticks % 5 == 0;
                            boolean all_done = do_results;
                            for (int i = 0; i < engines.length; i++) {
                                Object[] status = search.getEngineStatus(engines[i]);
                                int state = (Integer) status[0];
                                ImageLabel indicator = indicators.get(i);
                                if (state == 0) {
                                    indicator.setImage(vitality_images[image_index]);
                                } else if (state == 1) {
                                    indicator.setImage(ok_image);
                                } else if (state == 2) {
                                    indicator.setImage(fail_image);
                                    String msg = (String) status[2];
                                    if (msg != null) {
                                        indicator.setToolTipText(msg);
                                    }
                                } else {
                                    indicator.setImage(auth_image);
                                }
                                if (do_results) {
                                    if (state == 0) {
                                        all_done = false;
                                    }
                                    String str = "(" + status[1] + ")";
                                    Label rc = result_counts.get(i);
                                    if (!str.equals(rc.getText())) {
                                        rc.setText(str);
                                    }
                                }
                            }
                            if (all_done) {
                                running = false;
                            }
                        }
                    });
                }
            }
        }.start();
    }
    engine_area.layout(true);
}
Also used : Label(org.eclipse.swt.widgets.Label) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) UIFunctions(com.biglybt.ui.UIFunctions) RowLayout(org.eclipse.swt.layout.RowLayout) Menu(org.eclipse.swt.widgets.Menu) WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine) Engine(com.biglybt.core.metasearch.Engine) Composite(org.eclipse.swt.widgets.Composite) MenuItem(org.eclipse.swt.widgets.MenuItem) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridData(org.eclipse.swt.layout.GridData) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject)

Aggregations

Engine (com.biglybt.core.metasearch.Engine)24 WebEngine (com.biglybt.core.metasearch.impl.web.WebEngine)18 RSSEngine (com.biglybt.core.metasearch.impl.web.rss.RSSEngine)9 Subscription (com.biglybt.core.subs.Subscription)5 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)4 URL (java.net.URL)4 PluginEngine (com.biglybt.core.metasearch.impl.plugin.PluginEngine)3 SubscriptionException (com.biglybt.core.subs.SubscriptionException)2 VuzeFileComponent (com.biglybt.core.vuzefile.VuzeFileComponent)2 MenuItemFillListener (com.biglybt.pif.ui.menus.MenuItemFillListener)2 UserPrompterResultListener (com.biglybt.ui.UserPrompterResultListener)2 ArrayList (java.util.ArrayList)2 Menu (org.eclipse.swt.widgets.Menu)2 MenuItem (org.eclipse.swt.widgets.MenuItem)2 Result (com.biglybt.core.metasearch.Result)1 SearchLoginException (com.biglybt.core.metasearch.SearchLoginException)1 SearchParameter (com.biglybt.core.metasearch.SearchParameter)1 PluginProxy (com.biglybt.core.proxy.AEProxyFactory.PluginProxy)1 SubscriptionManagerListener (com.biglybt.core.subs.SubscriptionManagerListener)1 SubscriptionResult (com.biglybt.core.subs.SubscriptionResult)1