Search in sources :

Example 1 with DownloadException

use of com.biglybt.pif.download.DownloadException in project BiglyBT by BiglySoftware.

the class RPShortCuts method getDownloadStats.

@Override
public DownloadStats getDownloadStats(byte[] hash) throws DownloadException {
    try {
        RPDownloadStats res = (RPDownloadStats) _dispatcher.dispatch(new RPRequest(this, "getDownloadStats[byte[]]", new Object[] { hash })).getResponse();
        res._setRemote(_dispatcher);
        return (res);
    } catch (RPException e) {
        if (e.getCause() instanceof DownloadException) {
            throw ((DownloadException) e.getCause());
        }
        throw (e);
    }
}
Also used : DownloadException(com.biglybt.pif.download.DownloadException) RPDownloadStats(com.biglybt.pifimpl.remote.download.RPDownloadStats)

Example 2 with DownloadException

use of com.biglybt.pif.download.DownloadException 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 3 with DownloadException

use of com.biglybt.pif.download.DownloadException in project BiglyBT by BiglySoftware.

the class TranscodeFileImpl method getName.

@Override
public String getName() {
    TranscodeJob job = getJob();
    String text;
    if (job == null) {
        try {
            DiskManagerFileInfo sourceFile = getSourceFile();
            try {
                Download download = sourceFile.getDownload();
                if (download == null) {
                    text = sourceFile.getFile().getName();
                } else {
                    text = download.getName();
                    DiskManagerFileInfo[] fileInfo = download.getDiskManagerFileInfo();
                    if (fileInfo.length > 1) {
                        text += ": " + sourceFile.getFile(true).getName();
                    }
                }
            } catch (DownloadException e) {
                text = sourceFile.getFile().getName();
            }
        } catch (Throwable e) {
            text = "";
        }
    } else {
        text = job.getName();
    }
    return (text);
}
Also used : DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) DownloadException(com.biglybt.pif.download.DownloadException) Download(com.biglybt.pif.download.Download)

Example 4 with DownloadException

use of com.biglybt.pif.download.DownloadException in project BiglyBT by BiglySoftware.

the class TranscodeJobImpl method toMap.

protected Map<String, Object> toMap() throws IOException {
    try {
        Map<String, Object> map = new HashMap<>();
        synchronized (this) {
            MapUtils.exportInt(map, "state", state);
            MapUtils.setMapString(map, "error", error);
            MapUtils.setMapString(map, "target", target.getID());
            MapUtils.setMapString(map, "profile", profile.getUID());
            try {
                Download download = file.getDownload();
                MapUtils.setMapString(map, "dl_hash", ByteFormatter.encodeString(download.getTorrent().getHash()));
                MapUtils.exportInt(map, "file_index", file.getIndex());
            } catch (DownloadException e) {
                // external file
                MapUtils.setMapString(map, "file", file.getFile().getAbsolutePath());
            }
            MapUtils.exportInt(map, "trans_req", transcode_requirement);
            MapUtils.exportBooleanAsLong(map, "ar_enable", auto_retry_enabled);
            MapUtils.exportBooleanAsLong(map, "pdi", prefer_direct_input);
        }
        return (map);
    } catch (Throwable e) {
        throw (new IOException("Export failed: " + Debug.getNestedExceptionMessage(e)));
    }
}
Also used : HashMap(java.util.HashMap) DownloadException(com.biglybt.pif.download.DownloadException) IOException(java.io.IOException) Download(com.biglybt.pif.download.Download)

Example 5 with DownloadException

use of com.biglybt.pif.download.DownloadException in project BiglyBT by BiglySoftware.

the class PluginCoreUtils method convert.

public static Object convert(Object datasource, boolean toCore) {
    if (datasource instanceof Object[]) {
        Object[] array = (Object[]) datasource;
        Object[] newArray = new Object[array.length];
        for (int i = 0; i < array.length; i++) {
            Object o = array[i];
            newArray[i] = convert(o, toCore);
        }
        return newArray;
    }
    try {
        if (toCore) {
            if (datasource instanceof com.biglybt.core.download.DownloadManager) {
                return datasource;
            }
            if (datasource instanceof DownloadImpl) {
                return ((DownloadImpl) datasource).getDownload();
            }
            if (datasource instanceof com.biglybt.core.disk.DiskManager) {
                return datasource;
            }
            if (datasource instanceof DiskManagerImpl) {
                return ((DiskManagerImpl) datasource).getDiskmanager();
            }
            if (datasource instanceof PEPeerManager) {
                return datasource;
            }
            if (datasource instanceof PeerManagerImpl) {
                return ((PeerManagerImpl) datasource).getDelegate();
            }
            if (datasource instanceof PEPeer) {
                return datasource;
            }
            if (datasource instanceof PeerImpl) {
                return ((PeerImpl) datasource).getPEPeer();
            }
            if (datasource instanceof com.biglybt.core.disk.DiskManagerFileInfo) {
                return datasource;
            }
            if (datasource instanceof com.biglybt.pifimpl.local.disk.DiskManagerFileInfoImpl) {
                return ((com.biglybt.pifimpl.local.disk.DiskManagerFileInfoImpl) datasource).getCore();
            }
            if (datasource instanceof TRHostTorrent) {
                return datasource;
            }
            if (datasource instanceof TrackerTorrentImpl) {
                ((TrackerTorrentImpl) datasource).getHostTorrent();
            }
        } else {
            // to PI
            if (datasource instanceof com.biglybt.core.download.DownloadManager) {
                return wrap((com.biglybt.core.download.DownloadManager) datasource);
            }
            if (datasource instanceof DownloadImpl) {
                return datasource;
            }
            if (datasource instanceof com.biglybt.core.disk.DiskManager) {
                return wrap((com.biglybt.core.disk.DiskManager) datasource);
            }
            if (datasource instanceof DiskManagerImpl) {
                return datasource;
            }
            if (datasource instanceof PEPeerManager) {
                return wrap((PEPeerManager) datasource);
            }
            if (datasource instanceof PeerManagerImpl) {
                return datasource;
            }
            if (datasource instanceof PEPeer) {
                return PeerManagerImpl.getPeerForPEPeer((PEPeer) datasource);
            }
            if (datasource instanceof Peer) {
                return datasource;
            }
            if (datasource instanceof com.biglybt.core.disk.DiskManagerFileInfo) {
                DiskManagerFileInfo fileInfo = (com.biglybt.core.disk.DiskManagerFileInfo) datasource;
                if (fileInfo != null) {
                    try {
                        DownloadManager dm = fileInfo.getDownloadManager();
                        return new com.biglybt.pifimpl.local.disk.DiskManagerFileInfoImpl(dm == null ? null : DownloadManagerImpl.getDownloadStatic(dm), fileInfo);
                    } catch (DownloadException e) {
                    /* Ignore */
                    }
                }
            }
            if (datasource instanceof com.biglybt.pifimpl.local.disk.DiskManagerFileInfoImpl) {
                return datasource;
            }
            if (datasource instanceof TRHostTorrent) {
                TRHostTorrent item = (TRHostTorrent) datasource;
                return new TrackerTorrentImpl(item);
            }
            if (datasource instanceof TrackerTorrentImpl) {
                return datasource;
            }
        }
    } catch (Throwable t) {
        Debug.out(t);
    }
    return datasource;
}
Also used : PEPeer(com.biglybt.core.peer.PEPeer) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) DiskManagerImpl(com.biglybt.pifimpl.local.disk.DiskManagerImpl) PEPeer(com.biglybt.core.peer.PEPeer) Peer(com.biglybt.pif.peers.Peer) DownloadImpl(com.biglybt.pifimpl.local.download.DownloadImpl) DiskManager(com.biglybt.pif.disk.DiskManager) TRHostTorrent(com.biglybt.core.tracker.host.TRHostTorrent) TrackerTorrentImpl(com.biglybt.pifimpl.local.tracker.TrackerTorrentImpl) DownloadManager(com.biglybt.core.download.DownloadManager) DiskManagerFileInfoImpl(com.biglybt.pifimpl.local.disk.DiskManagerFileInfoImpl) PeerManagerImpl(com.biglybt.pifimpl.local.peers.PeerManagerImpl) PeerImpl(com.biglybt.pifimpl.local.peers.PeerImpl) DownloadException(com.biglybt.pif.download.DownloadException) PEPeerManager(com.biglybt.core.peer.PEPeerManager)

Aggregations

DownloadException (com.biglybt.pif.download.DownloadException)12 Download (com.biglybt.pif.download.Download)6 DownloadManager (com.biglybt.core.download.DownloadManager)5 DiskManagerFileInfo (com.biglybt.pif.disk.DiskManagerFileInfo)5 PEPeerManager (com.biglybt.core.peer.PEPeerManager)3 TOTorrent (com.biglybt.core.torrent.TOTorrent)3 Torrent (com.biglybt.pif.torrent.Torrent)3 TranscodeFile (com.biglybt.core.devices.TranscodeFile)2 TranscodeJob (com.biglybt.core.devices.TranscodeJob)2 PEPeer (com.biglybt.core.peer.PEPeer)2 PluginListener (com.biglybt.pif.PluginListener)2 UIInstance (com.biglybt.pif.ui.UIInstance)2 UIManagerListener (com.biglybt.pif.ui.UIManagerListener)2 ActivitiesEntry (com.biglybt.activities.ActivitiesEntry)1 DiskManager (com.biglybt.core.disk.DiskManager)1 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)1 DiskManagerFileInfoListener (com.biglybt.core.disk.DiskManagerFileInfoListener)1 DiskManagerPiece (com.biglybt.core.disk.DiskManagerPiece)1 GlobalManager (com.biglybt.core.global.GlobalManager)1 PiecePicker (com.biglybt.core.peermanager.piecepicker.PiecePicker)1