Search in sources :

Example 1 with VuzeFileComponent

use of com.biglybt.core.vuzefile.VuzeFileComponent in project BiglyBT by BiglySoftware.

the class SubscriptionManagerImpl method subscribeToSubscription.

@Override
public Subscription subscribeToSubscription(String uri) throws Exception {
    SubscriptionManager manager = SubscriptionManagerFactory.getSingleton();
    Subscription subs = manager.createFromURI(uri);
    if (!subs.isSubscribed()) {
        subs.setSubscribed(true);
    }
    if (subs.isSearchTemplate()) {
        try {
            VuzeFile vf = subs.getSearchTemplateVuzeFile();
            if (vf != null) {
                VuzeFileHandler.getSingleton().handleFiles(new VuzeFile[] { vf }, VuzeFileComponent.COMP_TYPE_NONE);
                for (VuzeFileComponent comp : vf.getComponents()) {
                    Engine engine = (Engine) comp.getData(Engine.VUZE_FILE_COMPONENT_ENGINE_KEY);
                    if (engine != null && (engine.getSelectionState() == Engine.SEL_STATE_DESELECTED || engine.getSelectionState() == Engine.SEL_STATE_FORCE_DESELECTED)) {
                        engine.setSelectionState(Engine.SEL_STATE_MANUAL_SELECTED);
                    }
                }
            }
        } catch (Throwable e) {
            Debug.out(e);
        }
    } else {
        subs.requestAttention();
    }
    return (subs);
}
Also used : VuzeFileComponent(com.biglybt.core.vuzefile.VuzeFileComponent) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine) Engine(com.biglybt.core.metasearch.Engine) RSSEngine(com.biglybt.core.metasearch.impl.web.rss.RSSEngine)

Example 2 with VuzeFileComponent

use of com.biglybt.core.vuzefile.VuzeFileComponent in project BiglyBT by BiglySoftware.

the class SubscriptionManagerImpl method getSubscriptionFromVuzeFile.

protected SubscriptionImpl getSubscriptionFromVuzeFile(byte[] sid, int add_type, VuzeFile vf) throws SubscriptionException {
    VuzeFileComponent[] comps = vf.getComponents();
    for (int j = 0; j < comps.length; j++) {
        VuzeFileComponent comp = comps[j];
        if (comp.getType() == VuzeFileComponent.COMP_TYPE_SUBSCRIPTION) {
            Map map = comp.getContent();
            try {
                SubscriptionBodyImpl body = new SubscriptionBodyImpl(SubscriptionManagerImpl.this, map);
                SubscriptionImpl new_subs = new SubscriptionImpl(SubscriptionManagerImpl.this, body, add_type, false);
                if (Arrays.equals(new_subs.getShortID(), sid)) {
                    return (new_subs);
                }
            } catch (Throwable e) {
                log("Subscription decode failed", e);
            }
        }
    }
    throw (new SubscriptionException("Subscription not found"));
}
Also used : VuzeFileComponent(com.biglybt.core.vuzefile.VuzeFileComponent)

Example 3 with VuzeFileComponent

use of com.biglybt.core.vuzefile.VuzeFileComponent in project BiglyBT by BiglySoftware.

the class MetaSearchManagerImpl method syncRefresh.

protected void syncRefresh() throws MetaSearchException {
    boolean refresh_completed = false;
    boolean first_run = false;
    try {
        refresh_sem.reserve();
        first_run = COConfigurationManager.getBooleanParameter("metasearch.refresh.first_run", true);
        if (!checked_customization) {
            checked_customization = true;
            CustomizationManager cust_man = CustomizationManagerFactory.getSingleton();
            Customization cust = cust_man.getActiveCustomization();
            if (cust != null) {
                String cust_name = COConfigurationManager.getStringParameter("metasearch.custom.name", "");
                String cust_version = COConfigurationManager.getStringParameter("metasearch.custom.version", "0");
                boolean new_name = !cust_name.equals(cust.getName());
                boolean new_version = com.biglybt.core.util.Constants.compareVersions(cust_version, cust.getVersion()) < 0;
                if (new_name || new_version) {
                    log("Customization: checking templates for " + cust.getName() + "/" + cust.getVersion());
                    try {
                        InputStream[] streams = cust.getResources(Customization.RT_META_SEARCH_TEMPLATES);
                        if (streams.length > 0 && new_name) {
                            // reset engines
                            log("    setting auto-mode to false");
                            setAutoMode(false);
                        /*
								Engine[]	engines = meta_search.getEngines( false, false );

								for (int i=0;i<engines.length;i++){

									Engine engine = engines[i];

									if ( engine.getSelectionState()) == Engine.SEL_STATE_MANUAL_SELECTED ){

									}
								}
								*/
                        }
                        for (int i = 0; i < streams.length; i++) {
                            InputStream is = streams[i];
                            try {
                                VuzeFile vf = VuzeFileHandler.getSingleton().loadVuzeFile(is);
                                if (vf != null) {
                                    VuzeFileComponent[] comps = vf.getComponents();
                                    for (int j = 0; j < comps.length; j++) {
                                        VuzeFileComponent comp = comps[j];
                                        if (comp.getType() == VuzeFileComponent.COMP_TYPE_METASEARCH_TEMPLATE) {
                                            try {
                                                Engine e = getSingleton().importEngine(comp.getContent(), false);
                                                log("    updated " + e.getName());
                                                e.setSelectionState(Engine.SEL_STATE_MANUAL_SELECTED);
                                            } catch (Throwable e) {
                                                Debug.printStackTrace(e);
                                            }
                                        }
                                    }
                                }
                            } finally {
                                try {
                                    is.close();
                                } catch (Throwable e) {
                                }
                            }
                        }
                    } finally {
                        COConfigurationManager.setParameter("metasearch.custom.name", cust.getName());
                        COConfigurationManager.setParameter("metasearch.custom.version", cust.getVersion());
                    }
                }
            }
        }
        log("Refreshing engines");
        // featured templates are always shown - can't be deselected
        // popular ones are selected if in 'auto' mode
        // manually selected ones are, well, manually selected
        Map<Long, PlatformMetaSearchMessenger.templateInfo> vuze_selected_ids = new HashMap<>();
        Map<Long, PlatformMetaSearchMessenger.templateInfo> vuze_preload_ids = new HashMap<>();
        Set<Long> featured_ids = new HashSet<>();
        Set<Long> popular_ids = new HashSet<>();
        Set<Long> manual_vuze_ids = new HashSet<>();
        boolean auto_mode = isAutoMode();
        Engine[] engines = meta_search.getEngines(false, false);
        String fud = meta_search.getFUD();
        try {
            PlatformMetaSearchMessenger.templateInfo[] featured = PlatformMetaSearchMessenger.listFeaturedTemplates(extension_key, fud);
            String featured_str = "";
            for (int i = 0; i < featured.length; i++) {
                PlatformMetaSearchMessenger.templateInfo template = featured[i];
                if (!template.isVisible()) {
                    continue;
                }
                Long key = new Long(template.getId());
                vuze_selected_ids.put(key, template);
                featured_ids.add(key);
                featured_str += (featured_str.length() == 0 ? "" : ",") + key;
            }
            log("Featured templates: " + featured_str);
            if (auto_mode || first_run) {
                PlatformMetaSearchMessenger.templateInfo[] popular = PlatformMetaSearchMessenger.listTopPopularTemplates(extension_key, fud);
                String popular_str = "";
                String preload_str = "";
                for (int i = 0; i < popular.length; i++) {
                    PlatformMetaSearchMessenger.templateInfo template = popular[i];
                    if (!template.isVisible()) {
                        continue;
                    }
                    Long key = new Long(template.getId());
                    if (auto_mode) {
                        if (!vuze_selected_ids.containsKey(key)) {
                            vuze_selected_ids.put(key, template);
                            popular_ids.add(key);
                            popular_str += (popular_str.length() == 0 ? "" : ",") + key;
                        }
                    } else {
                        if (!vuze_preload_ids.containsKey(key)) {
                            vuze_preload_ids.put(key, template);
                            preload_str += (preload_str.length() == 0 ? "" : ",") + key;
                        }
                    }
                }
                log("Popular templates: " + popular_str);
                if (preload_str.length() > 0) {
                    log("Pre-load templates: " + popular_str);
                }
            }
            // pick up explicitly selected vuze ones
            String manual_str = "";
            for (int i = 0; i < engines.length; i++) {
                Engine engine = engines[i];
                Long key = new Long(engine.getId());
                if (engine.getSource() == Engine.ENGINE_SOURCE_VUZE && engine.getSelectionState() == Engine.SEL_STATE_MANUAL_SELECTED && !vuze_selected_ids.containsKey(key)) {
                    manual_vuze_ids.add(key);
                }
            }
            if (manual_vuze_ids.size() > 0) {
                long[] manual_ids = new long[manual_vuze_ids.size()];
                Iterator<Long> it = manual_vuze_ids.iterator();
                int pos = 0;
                while (it.hasNext()) {
                    manual_ids[pos++] = it.next().longValue();
                }
                PlatformMetaSearchMessenger.templateInfo[] manual = PlatformMetaSearchMessenger.getTemplateDetails(extension_key, manual_ids);
                for (int i = 0; i < manual.length; i++) {
                    PlatformMetaSearchMessenger.templateInfo template = manual[i];
                    if (!template.isVisible()) {
                        continue;
                    }
                    Long key = new Long(template.getId());
                    vuze_selected_ids.put(key, template);
                    manual_str += (manual_str.length() == 0 ? "" : ",") + key;
                }
            }
            log("Manual templates: " + manual_str);
            Map<Long, Engine> existing_engine_map = new HashMap<>();
            String existing_str = "";
            for (int i = 0; i < engines.length; i++) {
                Engine engine = engines[i];
                Long key = new Long(engine.getId());
                existing_engine_map.put(key, engine);
                existing_str += (existing_str.length() == 0 ? "" : ",") + key + "[source=" + Engine.ENGINE_SOURCE_STRS[engine.getSource()] + ",type=" + engine.getType() + ",selected=" + Engine.SEL_STATE_STRINGS[engine.getSelectionState()] + "]";
            }
            log("Existing templates: " + existing_str);
            // we've compiled a list of the engines we should have and their latest dates
            // update any that are out of date
            Iterator<Map.Entry<Long, PlatformMetaSearchMessenger.templateInfo>> it = vuze_selected_ids.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<Long, PlatformMetaSearchMessenger.templateInfo> entry = it.next();
                vuze_preload_ids.remove(entry.getKey());
                long id = entry.getKey().longValue();
                PlatformMetaSearchMessenger.templateInfo template = entry.getValue();
                long modified = template.getModifiedDate();
                Engine this_engine = (Engine) existing_engine_map.get(new Long(id));
                boolean update = this_engine == null || this_engine.getLastUpdated() < modified;
                if (update) {
                    PlatformMetaSearchMessenger.templateDetails details = PlatformMetaSearchMessenger.getTemplate(extension_key, id);
                    log("Downloading definition of template " + id);
                    log(details.getValue());
                    if (details.isVisible()) {
                        try {
                            this_engine = meta_search.importFromJSONString(details.getType() == PlatformMetaSearchMessenger.templateDetails.ENGINE_TYPE_JSON ? Engine.ENGINE_TYPE_JSON : Engine.ENGINE_TYPE_REGEX, details.getId(), details.getModifiedDate(), details.getRankBias(), details.getName(), details.getValue());
                            this_engine.setSource(Engine.ENGINE_SOURCE_VUZE);
                            meta_search.addEngine(this_engine);
                        } catch (Throwable e) {
                            log("Failed to import engine '" + details.getValue() + "'", e);
                        }
                    }
                } else if (this_engine.getRankBias() != template.getRankBias()) {
                    this_engine.setRankBias(template.getRankBias());
                    log("Updating rank bias for " + this_engine.getString() + " to " + template.getRankBias());
                } else {
                    log("Not updating " + this_engine.getString() + " as unchanged");
                }
                if (this_engine != null) {
                    int sel_state = this_engine.getSelectionState();
                    if (sel_state == Engine.SEL_STATE_DESELECTED) {
                        log("Auto-selecting " + this_engine.getString());
                        this_engine.setSelectionState(Engine.SEL_STATE_AUTO_SELECTED);
                    } else if (auto_mode && sel_state == Engine.SEL_STATE_MANUAL_SELECTED) {
                        log("Switching Manual to Auto select for " + this_engine.getString());
                        this_engine.setSelectionState(Engine.SEL_STATE_AUTO_SELECTED);
                    }
                }
            }
            // do any pre-loads
            it = vuze_preload_ids.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<Long, PlatformMetaSearchMessenger.templateInfo> entry = it.next();
                long id = ((Long) entry.getKey()).longValue();
                Engine this_engine = (Engine) existing_engine_map.get(new Long(id));
                if (this_engine == null) {
                    PlatformMetaSearchMessenger.templateDetails details = PlatformMetaSearchMessenger.getTemplate(extension_key, id);
                    log("Downloading pre-load definition of template " + id);
                    log(details.getValue());
                    if (details.isVisible()) {
                        try {
                            this_engine = meta_search.importFromJSONString(details.getType() == PlatformMetaSearchMessenger.templateDetails.ENGINE_TYPE_JSON ? Engine.ENGINE_TYPE_JSON : Engine.ENGINE_TYPE_REGEX, details.getId(), details.getModifiedDate(), details.getRankBias(), details.getName(), details.getValue());
                            this_engine.setSource(Engine.ENGINE_SOURCE_VUZE);
                            this_engine.setSelectionState(Engine.SEL_STATE_DESELECTED);
                            meta_search.addEngine(this_engine);
                        } catch (Throwable e) {
                            log("Failed to import engine '" + details.getValue() + "'", e);
                        }
                    }
                }
            }
            for (int i = 0; i < engines.length; i++) {
                Engine engine = engines[i];
                if (engine.getSource() == Engine.ENGINE_SOURCE_VUZE && engine.getSelectionState() == Engine.SEL_STATE_AUTO_SELECTED && !vuze_selected_ids.containsKey(new Long(engine.getId()))) {
                    log("Deselecting " + engine.getString() + " as no longer visible on Vuze");
                    engine.setSelectionState(Engine.SEL_STATE_DESELECTED);
                }
            }
            for (int i = 0; i < engines.length; i++) {
                Engine engine = engines[i];
                if (engine.getSource() == Engine.ENGINE_SOURCE_VUZE && engine.getSelectionState() == Engine.SEL_STATE_MANUAL_SELECTED) {
                    engine.recordSelectionState();
                } else {
                    engine.checkSelectionStateRecorded();
                }
            }
            refresh_completed = true;
        } catch (Throwable e) {
            log("Refresh failed", e);
            throw (new MetaSearchException("Refresh failed", e));
        }
    } finally {
        if (first_run && refresh_completed) {
            COConfigurationManager.setParameter("metasearch.refresh.first_run", false);
        }
        refresh_sem.release();
        initial_refresh_sem.releaseForever();
    }
}
Also used : VuzeFileComponent(com.biglybt.core.vuzefile.VuzeFileComponent) Customization(com.biglybt.core.custom.Customization) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) PluginEngine(com.biglybt.core.metasearch.impl.plugin.PluginEngine) InputStream(java.io.InputStream) PlatformMetaSearchMessenger(com.biglybt.core.messenger.config.PlatformMetaSearchMessenger) CustomizationManager(com.biglybt.core.custom.CustomizationManager)

Example 4 with VuzeFileComponent

use of com.biglybt.core.vuzefile.VuzeFileComponent in project BiglyBT by BiglySoftware.

the class MetaSearchManagerImpl method preInitialise.

public static void preInitialise() {
    VuzeFileHandler.getSingleton().addProcessor(new VuzeFileProcessor() {

        @Override
        public void process(VuzeFile[] files, int expected_types) {
            for (int i = 0; i < files.length; i++) {
                VuzeFile vf = files[i];
                VuzeFileComponent[] comps = vf.getComponents();
                for (int j = 0; j < comps.length; j++) {
                    VuzeFileComponent comp = comps[j];
                    int comp_type = comp.getType();
                    if (comp_type == VuzeFileComponent.COMP_TYPE_METASEARCH_TEMPLATE) {
                        try {
                            Engine e = getSingleton().importEngine(comp.getContent(), (expected_types & VuzeFileComponent.COMP_TYPE_METASEARCH_TEMPLATE) == 0);
                            comp.setProcessed();
                            if (e != null) {
                                comp.setData(Engine.VUZE_FILE_COMPONENT_ENGINE_KEY, e);
                            }
                        } catch (Throwable e) {
                            Debug.printStackTrace(e);
                        }
                    } else if (comp_type == VuzeFileComponent.COMP_TYPE_METASEARCH_OPERATION) {
                        getSingleton().addOperation(comp.getContent());
                        comp.setProcessed();
                    }
                }
            }
        }
    });
    TorrentUtils.addTorrentAttributeListener(new TorrentUtils.torrentAttributeListener() {

        @Override
        public void attributeSet(TOTorrent torrent, String attribute, Object value) {
            if (attribute == TorrentUtils.TORRENT_AZ_PROP_OBTAINED_FROM && !TorrentUtils.isReallyPrivate(torrent)) {
                try {
                    getSingleton().checkPotentialAssociations(torrent.getHash(), (String) value);
                } catch (Throwable e) {
                    Debug.printStackTrace(e);
                }
            }
        }
    });
}
Also used : VuzeFileComponent(com.biglybt.core.vuzefile.VuzeFileComponent) VuzeFileProcessor(com.biglybt.core.vuzefile.VuzeFileProcessor) TOTorrent(com.biglybt.core.torrent.TOTorrent) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) PluginEngine(com.biglybt.core.metasearch.impl.plugin.PluginEngine)

Example 5 with VuzeFileComponent

use of com.biglybt.core.vuzefile.VuzeFileComponent in project BiglyBT by BiglySoftware.

the class MetaSearchManagerImpl method isImportable.

@Override
public boolean isImportable(VuzeFile vf) {
    VuzeFileComponent[] comps = vf.getComponents();
    for (int j = 0; j < comps.length; j++) {
        VuzeFileComponent comp = comps[j];
        int comp_type = comp.getType();
        if (comp_type == VuzeFileComponent.COMP_TYPE_METASEARCH_TEMPLATE) {
            try {
                EngineImpl engine = (EngineImpl) meta_search.importFromBEncodedMap(comp.getContent());
                long id = engine.getId();
                Engine existing = meta_search.getEngine(id);
                if (existing != null) {
                    int state = existing.getSelectionState();
                    if (state == Engine.SEL_STATE_DESELECTED || state == Engine.SEL_STATE_FORCE_DESELECTED || !existing.sameLogicAs(engine)) {
                        return (true);
                    }
                } else {
                    try {
                        Engine[] engines = meta_search.getEngines(false, false);
                        boolean is_new = true;
                        for (Engine e : engines) {
                            int state = e.getSelectionState();
                            if (state != Engine.SEL_STATE_DESELECTED && state != Engine.SEL_STATE_FORCE_DESELECTED && e.sameLogicAs(engine)) {
                                is_new = false;
                                break;
                            }
                        }
                        if (is_new) {
                            return (true);
                        }
                    } catch (Throwable e) {
                    }
                }
            } catch (Throwable e) {
            }
        }
    }
    return (false);
}
Also used : VuzeFileComponent(com.biglybt.core.vuzefile.VuzeFileComponent) PluginEngine(com.biglybt.core.metasearch.impl.plugin.PluginEngine)

Aggregations

VuzeFileComponent (com.biglybt.core.vuzefile.VuzeFileComponent)12 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)9 PluginEngine (com.biglybt.core.metasearch.impl.plugin.PluginEngine)4 File (java.io.File)4 VuzeFileProcessor (com.biglybt.core.vuzefile.VuzeFileProcessor)3 URL (java.net.URL)3 Engine (com.biglybt.core.metasearch.Engine)2 WebEngine (com.biglybt.core.metasearch.impl.web.WebEngine)2 Subscription (com.biglybt.core.subs.Subscription)2 TOTorrent (com.biglybt.core.torrent.TOTorrent)2 UIManager (com.biglybt.pif.ui.UIManager)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ParameterListener (com.biglybt.core.config.ParameterListener)1 Customization (com.biglybt.core.custom.Customization)1 CustomizationManager (com.biglybt.core.custom.CustomizationManager)1 DHT (com.biglybt.core.dht.DHT)1 DHTListener (com.biglybt.core.dht.DHTListener)1 DHTSpeedTester (com.biglybt.core.dht.speed.DHTSpeedTester)1 GlobalManagerAdapter (com.biglybt.core.global.GlobalManagerAdapter)1 LogAlert (com.biglybt.core.logging.LogAlert)1