Search in sources :

Example 1 with DiskManagerFileInfo

use of com.biglybt.pif.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.

the class DeviceManagerImpl method getStreamURL.

protected URL getStreamURL(TranscodeFileImpl file, String host) {
    IPCInterface ipc = upnp_manager.getUPnPAVIPC();
    if (ipc != null) {
        try {
            DiskManagerFileInfo f = file.getTargetFile();
            String str = (String) ipc.invoke("getContentURL", new Object[] { f });
            if (str != null && str.length() > 0) {
                if (host != null) {
                    str = str.replace("127.0.0.1", host);
                }
                return (new URL(str));
            }
        } catch (Throwable e) {
        }
    }
    return (null);
}
Also used : DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) IPCInterface(com.biglybt.pif.ipc.IPCInterface) URL(java.net.URL)

Example 2 with DiskManagerFileInfo

use of com.biglybt.pif.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.

the class DeviceManagerImpl method getMimeType.

protected String getMimeType(TranscodeFileImpl file) {
    if (getMimeType_fails > 5) {
        return (null);
    }
    IPCInterface ipc = upnp_manager.getUPnPAVIPC();
    if (ipc != null) {
        try {
            DiskManagerFileInfo f = file.getTargetFile();
            String[] strs = (String[]) ipc.invoke("getMimeTypes", new Object[] { f });
            if (strs != null && strs.length > 0) {
                return (strs[0]);
            }
        } catch (Throwable e) {
            getMimeType_fails++;
            e.printStackTrace();
        }
    }
    return (null);
}
Also used : DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) IPCInterface(com.biglybt.pif.ipc.IPCInterface)

Example 3 with DiskManagerFileInfo

use of com.biglybt.pif.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.

the class DataSourceUtils method getTorrent.

public static TOTorrent getTorrent(Object ds) {
    if (ds instanceof TOTorrent) {
        return (TOTorrent) ds;
    }
    if (ds instanceof DownloadManager) {
        TOTorrent torrent = ((DownloadManager) ds).getTorrent();
        if (torrent != null) {
            return torrent;
        }
    }
    if (ds instanceof ActivitiesEntry) {
        TOTorrent torrent = ((ActivitiesEntry) ds).getTorrent();
        if (torrent == null) {
            // getDM will check hash as well
            DownloadManager dm = getDM(ds);
            if (dm != null) {
                torrent = dm.getTorrent();
            }
        }
        return torrent;
    }
    if (ds instanceof TranscodeFile) {
        TranscodeFile tf = (TranscodeFile) ds;
        try {
            DiskManagerFileInfo file = tf.getSourceFile();
            if (file != null) {
                Download download = file.getDownload();
                if (download != null) {
                    Torrent torrent = download.getTorrent();
                    if (torrent != null) {
                        return PluginCoreUtils.unwrap(torrent);
                    }
                }
            }
        } catch (Throwable e) {
        }
    }
    if (ds instanceof TranscodeJob) {
        TranscodeJob tj = (TranscodeJob) ds;
        try {
            DiskManagerFileInfo file = tj.getFile();
            if (file != null) {
                Download download = tj.getFile().getDownload();
                if (download != null) {
                    Torrent torrent = download.getTorrent();
                    if (torrent != null) {
                        return PluginCoreUtils.unwrap(torrent);
                    }
                }
            }
        } catch (DownloadException e) {
        }
    }
    if (ds instanceof ISelectedContent) {
        return ((ISelectedContent) ds).getTorrent();
    }
    if (ds instanceof String) {
        String hash = (String) ds;
        try {
            GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
            DownloadManager dm = gm.getDownloadManager(new HashWrapper(Base32.decode(hash)));
            if (dm != null) {
                return dm.getTorrent();
            }
        } catch (Exception e) {
        // ignore
        }
    }
    DownloadManager dm = getDM(ds);
    if (dm != null) {
        return dm.getTorrent();
    }
    return null;
}
Also used : TOTorrent(com.biglybt.core.torrent.TOTorrent) Torrent(com.biglybt.pif.torrent.Torrent) DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) ISelectedContent(com.biglybt.ui.selectedcontent.ISelectedContent) DownloadManager(com.biglybt.core.download.DownloadManager) DownloadException(com.biglybt.pif.download.DownloadException) TranscodeJob(com.biglybt.core.devices.TranscodeJob) ActivitiesEntry(com.biglybt.activities.ActivitiesEntry) GlobalManager(com.biglybt.core.global.GlobalManager) HashWrapper(com.biglybt.core.util.HashWrapper) TOTorrent(com.biglybt.core.torrent.TOTorrent) DownloadException(com.biglybt.pif.download.DownloadException) TranscodeFile(com.biglybt.core.devices.TranscodeFile) Download(com.biglybt.pif.download.Download)

Example 4 with DiskManagerFileInfo

use of com.biglybt.pif.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.

the class BuddyPluginViewBetaChat method handleDrop.

private void handleDrop(Object payload, DropAccepter accepter) {
    if (payload instanceof String[]) {
        String[] files = (String[]) payload;
        if (files.length == 0) {
            Debug.out("Nothing to drop");
        } else {
            int hits = 0;
            for (String file : files) {
                File f = new File(file);
                if (f.exists()) {
                    dropFile(f, accepter);
                    hits++;
                }
            }
            if (hits == 0) {
                Debug.out("Nothing files found to drop");
            }
        }
    } else if (payload instanceof String) {
        String stuff = (String) payload;
        if (stuff.startsWith("DownloadManager\n") || stuff.startsWith("DiskManagerFileInfo\n")) {
            String[] bits = Constants.PAT_SPLIT_SLASH_N.split(stuff);
            for (int i = 1; i < bits.length; i++) {
                String hash_str = bits[i];
                int pos = hash_str.indexOf(';');
                try {
                    if (pos == -1) {
                        byte[] hash = Base32.decode(bits[i]);
                        Download download = CoreFactory.getSingleton().getPluginManager().getDefaultPluginInterface().getShortCuts().getDownload(hash);
                        dropDownload(download, accepter);
                    } else {
                        String[] files = hash_str.split(";");
                        byte[] hash = Base32.decode(files[0].trim());
                        DiskManagerFileInfo[] dm_files = CoreFactory.getSingleton().getPluginManager().getDefaultPluginInterface().getShortCuts().getDownload(hash).getDiskManagerFileInfo();
                        for (int j = 1; j < files.length; j++) {
                            DiskManagerFileInfo dm_file = dm_files[Integer.parseInt(files[j].trim())];
                            dropDownloadFile(dm_file, accepter);
                        }
                    }
                } catch (Throwable e) {
                    Debug.out("Failed to get download for hash " + bits[1]);
                }
            }
        } else if (stuff.startsWith("TranscodeFile\n")) {
            String[] bits = Constants.PAT_SPLIT_SLASH_N.split(stuff);
            for (int i = 1; i < bits.length; i++) {
                File f = new File(bits[i]);
                if (f.isFile()) {
                    dropFile(f, accepter);
                }
            }
        } else {
            File f = new File(stuff);
            if (f.exists()) {
                dropFile(f, accepter);
            } else {
                String lc_stuff = stuff.toLowerCase(Locale.US);
                if (lc_stuff.startsWith("http:") || lc_stuff.startsWith("https:") || lc_stuff.startsWith("magnet: ")) {
                    dropURL(stuff, accepter);
                } else {
                    Debug.out("Failed to handle drop for '" + stuff + "'");
                }
            }
        }
    } else if (payload instanceof FixedURLTransfer.URLType) {
        String url = ((FixedURLTransfer.URLType) payload).linkURL;
        if (url != null) {
            dropURL(url, accepter);
        } else {
            Debug.out("Failed to handle drop for '" + payload + "'");
        }
    }
}
Also used : DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) File(java.io.File) ShareResourceFile(com.biglybt.pif.sharing.ShareResourceFile) Download(com.biglybt.pif.download.Download) Point(org.eclipse.swt.graphics.Point)

Example 5 with DiskManagerFileInfo

use of com.biglybt.pif.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.

the class DeviceManagerUI method setupTranscodeMenus.

private void setupTranscodeMenus() {
    if (DISABLED_TRANSCODING) {
        return;
    }
    // top level menus
    final String[] tables = { TableManager.TABLE_MYTORRENTS_INCOMPLETE, TableManager.TABLE_MYTORRENTS_INCOMPLETE_BIG, TableManager.TABLE_MYTORRENTS_COMPLETE, TableManager.TABLE_MYTORRENTS_COMPLETE_BIG, TableManager.TABLE_TORRENT_FILES, TableManager.TABLE_MYTORRENTS_UNOPENED, TableManager.TABLE_MYTORRENTS_UNOPENED_BIG, TableManager.TABLE_MYTORRENTS_ALL_BIG };
    TableManager table_manager = plugin_interface.getUIManager().getTableManager();
    MenuItemFillListener menu_fill_listener = new MenuItemFillListener() {

        @Override
        public void menuWillBeShown(MenuItem menu, Object _target) {
            final TableRow[] target;
            if (_target instanceof TableRow) {
                target = new TableRow[] { (TableRow) _target };
            } else {
                target = (TableRow[]) _target;
            }
            boolean enabled = target.length > 0;
            for (TableRow row : target) {
                Object obj = row.getDataSource();
                if (obj instanceof Download) {
                    Download download = (Download) obj;
                    if (download.getState() == Download.ST_ERROR) {
                        enabled = false;
                    }
                } else {
                    DiskManagerFileInfo file = (DiskManagerFileInfo) obj;
                    try {
                        if (file.getIndex() < 0 || file.getDownload().getState() == Download.ST_ERROR) {
                            enabled = false;
                        }
                    } catch (Throwable e) {
                        enabled = false;
                    }
                }
            }
            menu.setEnabled(enabled);
            menu.removeAllChildItems();
            if (enabled) {
                Device[] devices = device_manager.getDevices();
                int devices_added = 0;
                for (Device device : devices) {
                    if (device.isHidden()) {
                        continue;
                    }
                    if (device instanceof TranscodeTarget) {
                        devices_added++;
                        final TranscodeTarget renderer = (TranscodeTarget) device;
                        TranscodeProfile[] profiles = renderer.getTranscodeProfiles();
                        TableContextMenuItem device_item = plugin_interface.getUIManager().getTableManager().addContextMenuItem((TableContextMenuItem) menu, "!" + device.getName() + (profiles.length == 0 ? " (No Profiles)" : "") + "!");
                        device_item.setStyle(MenuItem.STYLE_MENU);
                        if (profiles.length == 0) {
                            device_item.setEnabled(false);
                        } else {
                            Arrays.sort(profiles, new Comparator<TranscodeProfile>() {

                                @Override
                                public int compare(TranscodeProfile o1, TranscodeProfile o2) {
                                    int i1 = o1.getIconIndex();
                                    int i2 = o2.getIconIndex();
                                    if (i1 == i2) {
                                        return o1.getName().compareToIgnoreCase(o2.getName());
                                    } else {
                                        return (i1 - i2);
                                    }
                                }
                            });
                            for (final TranscodeProfile profile : profiles) {
                                TableContextMenuItem profile_item = plugin_interface.getUIManager().getTableManager().addContextMenuItem(device_item, "!" + profile.getName() + "!");
                                profile_item.addMultiListener(new MenuItemListener() {

                                    @Override
                                    public void selected(MenuItem menu, Object x) {
                                        for (TableRow row : target) {
                                            Object obj = row.getDataSource();
                                            try {
                                                if (obj instanceof Download) {
                                                    Download download = (Download) obj;
                                                    addDownload(renderer, profile, -1, download);
                                                } else {
                                                    DiskManagerFileInfo file = (DiskManagerFileInfo) obj;
                                                    addFile(renderer, profile, -1, file);
                                                }
                                            } catch (Throwable e) {
                                                Debug.out(e);
                                            }
                                        }
                                    }
                                });
                            }
                        }
                    }
                }
                if (devices_added == 0) {
                    TableContextMenuItem device_item = plugin_interface.getUIManager().getTableManager().addContextMenuItem((TableContextMenuItem) menu, "!(No Devices)!");
                    device_item.setEnabled(false);
                }
            }
        }
    };
    // instead of forcing a loop like this
    for (String table : tables) {
        TableContextMenuItem menu = table_manager.addContextMenuItem(table, "devices.contextmenu.xcode");
        menu.setStyle(TableContextMenuItem.STYLE_MENU);
        menu.setHeaderCategory(MenuItem.HEADER_CONTENT);
        menu.addFillListener(menu_fill_listener);
        menu.setDisposeWithUIDetach(UIInstance.UIT_SWT);
    }
}
Also used : DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) UPnPDevice(com.biglybt.net.upnp.UPnPDevice) UnassociatedDevice(com.biglybt.core.devices.DeviceManager.UnassociatedDevice) UPnPRootDevice(com.biglybt.net.upnp.UPnPRootDevice) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) MenuItem(com.biglybt.pif.ui.menus.MenuItem) Point(org.eclipse.swt.graphics.Point) TableContextMenuItem(com.biglybt.pif.ui.tables.TableContextMenuItem) MenuItemFillListener(com.biglybt.pif.ui.menus.MenuItemFillListener) TableRow(com.biglybt.pif.ui.tables.TableRow) TableManager(com.biglybt.pif.ui.tables.TableManager) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) Download(com.biglybt.pif.download.Download)

Aggregations

DiskManagerFileInfo (com.biglybt.pif.disk.DiskManagerFileInfo)23 Download (com.biglybt.pif.download.Download)11 DownloadException (com.biglybt.pif.download.DownloadException)5 IPCInterface (com.biglybt.pif.ipc.IPCInterface)5 Torrent (com.biglybt.pif.torrent.Torrent)3 Point (org.eclipse.swt.graphics.Point)3 ContentFile (com.biglybt.core.content.ContentFile)2 TranscodeFile (com.biglybt.core.devices.TranscodeFile)2 TranscodeJob (com.biglybt.core.devices.TranscodeJob)2 DownloadManager (com.biglybt.core.download.DownloadManager)2 TOTorrent (com.biglybt.core.torrent.TOTorrent)2 MenuItem (com.biglybt.pif.ui.menus.MenuItem)2 MenuItemFillListener (com.biglybt.pif.ui.menus.MenuItemFillListener)2 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)2 TableContextMenuItem (com.biglybt.pif.ui.tables.TableContextMenuItem)2 TableRow (com.biglybt.pif.ui.tables.TableRow)2 ISelectedContent (com.biglybt.ui.selectedcontent.ISelectedContent)2 File (java.io.File)2 URL (java.net.URL)2 ActivitiesEntry (com.biglybt.activities.ActivitiesEntry)1