Search in sources :

Example 6 with VuzeFile

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

the class VuzeURLConnection method connect.

@Override
public void connect() throws IOException {
    String str = url.toExternalForm();
    int pos = str.indexOf("=");
    str = str.substring(pos + 1);
    byte[] bytes = str.getBytes(Constants.BYTE_ENCODING);
    VuzeFile vf = VuzeFileHandler.getSingleton().loadVuzeFile(bytes);
    if (vf == null) {
        throw (new IOException("Invalid vuze file"));
    }
    input_stream = new ByteArrayInputStream(bytes);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) IOException(java.io.IOException)

Example 7 with VuzeFile

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

the class CustomizationManagerImpl method exportCustomization.

protected void exportCustomization(CustomizationImpl cust, File to_file) throws CustomizationException {
    if (to_file.isDirectory()) {
        to_file = new File(to_file, VuzeFileHandler.getVuzeFileName(cust.getName() + "_" + cust.getVersion()));
    }
    if (!VuzeFileHandler.isAcceptedVuzeFileName(to_file.getName())) {
        to_file = new File(to_file.getParentFile(), VuzeFileHandler.getVuzeFileName(to_file.getName()));
    }
    try {
        Map contents = new HashMap();
        byte[] data = FileUtil.readFileAsByteArray(cust.getContents());
        contents.put("name", cust.getName());
        contents.put("version", cust.getVersion());
        contents.put("data", data);
        VuzeFile vf = VuzeFileHandler.getSingleton().create();
        vf.addComponent(VuzeFileComponent.COMP_TYPE_CUSTOMIZATION, contents);
        vf.write(to_file);
    } catch (Throwable e) {
        throw (new CustomizationException("Failed to export customization", e));
    }
}
Also used : CustomizationException(com.biglybt.core.custom.CustomizationException) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File) VuzeFile(com.biglybt.core.vuzefile.VuzeFile)

Example 8 with VuzeFile

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

the class EngineImpl method exportToVuzeFile.

@Override
public void exportToVuzeFile(File target) throws IOException {
    VuzeFile vf = VuzeFileHandler.getSingleton().create();
    vf.addComponent(VuzeFileComponent.COMP_TYPE_METASEARCH_TEMPLATE, exportToBencodedMap());
    vf.write(target);
}
Also used : VuzeFile(com.biglybt.core.vuzefile.VuzeFile)

Example 9 with VuzeFile

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

the class MetaSearchImpl method updateEngine.

protected boolean updateEngine(EngineImpl engine) {
    String update_url = engine.getUpdateURL();
    int pos = update_url.indexOf('?');
    if (pos == -1) {
        update_url += "?";
    } else {
        update_url += "&";
    }
    update_url += "az_template_uid=" + engine.getUID() + "&az_template_version=" + engine.getVersion() + "&az_version=" + Constants.AZUREUS_VERSION + "&az_locale=" + MessageText.getCurrentLocale().toString() + "&az_rand=" + RandomUtils.nextAbsoluteLong();
    log("Engine " + engine.getName() + ": auto-update check via " + update_url);
    try {
        ResourceDownloaderFactory rdf = StaticUtilities.getResourceDownloaderFactory();
        ResourceDownloader url_rd = rdf.create(new URL(update_url));
        ResourceDownloader rd = rdf.getMetaRefreshDownloader(url_rd);
        InputStream is = rd.download();
        try {
            Map<String, Object> map = BDecoder.decode(new BufferedInputStream(is));
            log("    update check reply: " + map);
            // reply is either "response" meaning "no update" and giving possibly changed update secs
            // or Vuze file with updated template
            Map<String, Object> response = (Map<String, Object>) map.get("response");
            if (response != null) {
                Long update_secs = (Long) response.get("update_url_check_secs");
                if (update_secs == null) {
                    engine.setLocalUpdateCheckSecs(0);
                } else {
                    int check_secs = update_secs.intValue();
                    if (check_secs < MIN_UPDATE_CHECK_SECS) {
                        log("    update check secs for to small, min is " + MIN_UPDATE_CHECK_SECS);
                        check_secs = MIN_UPDATE_CHECK_SECS;
                    }
                    engine.setLocalUpdateCheckSecs(check_secs);
                }
                return (true);
            } else {
                VuzeFile vf = VuzeFileHandler.getSingleton().loadVuzeFile(map);
                if (vf == null) {
                    log("    failed to decode vuze file");
                    return (false);
                }
                Engine[] updated_engines = manager.loadFromVuzeFile(vf);
                if (updated_engines.length > 0) {
                    String existing_uid = engine.getUID();
                    boolean found = false;
                    String engine_str = "";
                    for (int i = 0; i < updated_engines.length; i++) {
                        Engine updated_engine = updated_engines[i];
                        engine_str += (i == 0 ? "" : ",") + updated_engine.getName() + ": uid=" + updated_engine.getUID() + ",version=" + updated_engine.getVersion();
                        if (updated_engine.getUID().equals(existing_uid)) {
                            found = true;
                        }
                    }
                    if (!found) {
                        log("    existing engine not found in updated set, deleting");
                        engine.delete();
                    }
                    log("    update complete: new engines=" + engine_str);
                } else {
                    log("    no engines found in vuze file");
                }
                return (true);
            }
        } finally {
            is.close();
        }
    } catch (Throwable e) {
        log("    update check failed", e);
        return (false);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) URL(java.net.URL) BufferedInputStream(java.io.BufferedInputStream) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) ResourceDownloaderFactory(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderFactory) PluginEngine(com.biglybt.core.metasearch.impl.plugin.PluginEngine) RSSEngine(com.biglybt.core.metasearch.impl.web.rss.RSSEngine) WebEngine(com.biglybt.core.metasearch.impl.web.WebEngine)

Example 10 with VuzeFile

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

the class MetaSearchManagerImpl method main.

public static void main(String[] args) {
    try {
        VuzeFile vf = VuzeFileHandler.getSingleton().create();
        Map contents = new HashMap();
        contents.put("type", new Long(1));
        contents.put("term", "donkey");
        vf.addComponent(VuzeFileComponent.COMP_TYPE_METASEARCH_OPERATION, contents);
        vf.write(new File("C:\\temp\\search.vuze"));
    } catch (Throwable e) {
        e.printStackTrace();
    }
}
Also used : VuzeFile(com.biglybt.core.vuzefile.VuzeFile) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) File(java.io.File)

Aggregations

VuzeFile (com.biglybt.core.vuzefile.VuzeFile)36 File (java.io.File)12 VuzeFileHandler (com.biglybt.core.vuzefile.VuzeFileHandler)10 VuzeFileComponent (com.biglybt.core.vuzefile.VuzeFileComponent)9 URL (java.net.URL)9 RSSEngine (com.biglybt.core.metasearch.impl.web.rss.RSSEngine)5 TOTorrent (com.biglybt.core.torrent.TOTorrent)5 IOException (java.io.IOException)5 PluginEngine (com.biglybt.core.metasearch.impl.plugin.PluginEngine)4 WebEngine (com.biglybt.core.metasearch.impl.web.WebEngine)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Map (java.util.Map)4 Subscription (com.biglybt.core.subs.Subscription)3 VuzeFileProcessor (com.biglybt.core.vuzefile.VuzeFileProcessor)3 UIManager (com.biglybt.pif.ui.UIManager)3 Engine (com.biglybt.core.metasearch.Engine)2 SubscriptionException (com.biglybt.core.subs.SubscriptionException)2 ResourceDownloader (com.biglybt.pif.utils.resourcedownloader.ResourceDownloader)2 ResourceDownloaderFactory (com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderFactory)2 InputStream (java.io.InputStream)2