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);
}
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);
}
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;
}
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 + "'");
}
}
}
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);
}
}
Aggregations