Search in sources :

Example 1 with TranscodeJob

use of com.biglybt.core.devices.TranscodeJob 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 2 with TranscodeJob

use of com.biglybt.core.devices.TranscodeJob in project BiglyBT by BiglySoftware.

the class ColumnTJ_Status method refresh.

// @see com.biglybt.pif.ui.tables.TableCellRefreshListener#refresh(com.biglybt.pif.ui.tables.TableCell)
@Override
public void refresh(TableCell cell) {
    TranscodeFile tf = (TranscodeFile) cell.getDataSource();
    if (tf == null || tf.isDeleted()) {
        return;
    }
    TranscodeJob job = tf.getJob();
    String tooltip = null;
    String text = null;
    boolean error = false;
    if (job == null) {
        try {
            if (tf.isComplete() && !tf.getTargetFile().getFile(true).exists()) {
                tooltip = "File '" + tf.getTargetFile().getFile().getAbsolutePath() + "' not found";
                text = js_resources[5] + ": File not found";
                error = true;
            }
        } catch (Throwable e) {
        }
        if (text == null) {
            if (tf.isCopyingToDevice()) {
                text = js_resources[11];
            } else if (tf.getCopyToDeviceFails() > 0) {
                text = js_resources[7];
                error = true;
            } else if (tf.isTemplate() && !tf.isComplete()) {
                text = js_resources[8];
            } else {
                text = js_resources[9];
            }
        }
    } else {
        int state = job.getState();
        text = js_resources[state];
        if (state == TranscodeJob.ST_QUEUED) {
            long eta = job.getDownloadETA();
            if (eta > 0) {
                text = js_resources[10] + ": " + eta_text + " " + (eta == Long.MAX_VALUE ? Constants.INFINITY_STRING : TimeFormatter.format(eta));
            }
        } else {
            text = js_resources[state];
            if (state == TranscodeJob.ST_FAILED) {
                String error_msg = job.getError();
                if (error_msg != null) {
                    try {
                        int pos = error_msg.indexOf('\n');
                        if (pos >= 0) {
                            error_msg = error_msg.substring(0, pos);
                        }
                        pos = error_msg.indexOf(',');
                        if (pos >= 0) {
                            pos = error_msg.indexOf(',', pos + 1);
                            if (pos >= 0) {
                                error_msg = error_msg.substring(0, pos);
                            }
                        }
                        text += ": " + error_msg.trim();
                    } catch (Throwable e) {
                    }
                }
                tooltip = "See transcode log for more details";
                error = true;
            }
        }
    }
    cell.setText(text);
    cell.setToolTip(tooltip);
    if (error) {
        cell.setForegroundToErrorColor();
    } else {
        cell.setForeground(Utils.colorToIntArray(null));
    }
}
Also used : TranscodeFile(com.biglybt.core.devices.TranscodeFile) TranscodeJob(com.biglybt.core.devices.TranscodeJob)

Example 3 with TranscodeJob

use of com.biglybt.core.devices.TranscodeJob in project BiglyBT by BiglySoftware.

the class DataSourceUtils method getFileInfo.

public static com.biglybt.core.disk.DiskManagerFileInfo getFileInfo(Object ds) {
    try {
        if (ds instanceof DiskManagerFileInfo) {
            return PluginCoreUtils.unwrap((DiskManagerFileInfo) ds);
        } else if (ds instanceof com.biglybt.core.disk.DiskManagerFileInfo) {
            return (com.biglybt.core.disk.DiskManagerFileInfo) ds;
        } else if ((ds instanceof ISelectedContent) && ((ISelectedContent) ds).getFileIndex() >= 0) {
            ISelectedContent sc = (ISelectedContent) ds;
            int idx = sc.getFileIndex();
            DownloadManager dm = sc.getDownloadManager();
            return dm.getDiskManagerFileInfoSet().getFiles()[idx];
        } else if (ds instanceof TranscodeJob) {
            TranscodeJob tj = (TranscodeJob) ds;
            try {
                return PluginCoreUtils.unwrap(tj.getFile());
            } catch (DownloadException e) {
            }
        } else if (ds instanceof TranscodeFile) {
            TranscodeFile tf = (TranscodeFile) ds;
            try {
                DiskManagerFileInfo file = tf.getSourceFile();
                return PluginCoreUtils.unwrap(file);
            } catch (DownloadException e) {
            }
        }
    } catch (Exception e) {
        Debug.printStackTrace(e);
    }
    return null;
}
Also used : DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) ISelectedContent(com.biglybt.ui.selectedcontent.ISelectedContent) DownloadException(com.biglybt.pif.download.DownloadException) TranscodeFile(com.biglybt.core.devices.TranscodeFile) DownloadManager(com.biglybt.core.download.DownloadManager) DownloadException(com.biglybt.pif.download.DownloadException) TranscodeJob(com.biglybt.core.devices.TranscodeJob)

Example 4 with TranscodeJob

use of com.biglybt.core.devices.TranscodeJob in project BiglyBT by BiglySoftware.

the class ColumnTJ_Rank method refresh.

// @see com.biglybt.pif.ui.tables.TableCellRefreshListener#refresh(com.biglybt.pif.ui.tables.TableCell)
@Override
public void refresh(TableCell cell) {
    TranscodeFile tf = (TranscodeFile) cell.getDataSource();
    if (tf == null) {
        return;
    }
    TranscodeJob job = tf.getJob();
    long value;
    if (job == null) {
        try {
            value = Integer.MAX_VALUE + tf.getCreationDateMillis() + 1;
        } catch (Throwable t) {
            value = Integer.MAX_VALUE + 1L;
        }
    } else {
        value = job.getIndex();
    }
    if (cell.setSortValue(value) || !cell.isValid()) {
        if (value > Integer.MAX_VALUE) {
            cell.setText("");
        } else {
            cell.setText("" + value);
        }
    }
}
Also used : TranscodeFile(com.biglybt.core.devices.TranscodeFile) TranscodeJob(com.biglybt.core.devices.TranscodeJob)

Aggregations

TranscodeFile (com.biglybt.core.devices.TranscodeFile)4 TranscodeJob (com.biglybt.core.devices.TranscodeJob)4 DownloadManager (com.biglybt.core.download.DownloadManager)2 DiskManagerFileInfo (com.biglybt.pif.disk.DiskManagerFileInfo)2 DownloadException (com.biglybt.pif.download.DownloadException)2 ISelectedContent (com.biglybt.ui.selectedcontent.ISelectedContent)2 ActivitiesEntry (com.biglybt.activities.ActivitiesEntry)1 GlobalManager (com.biglybt.core.global.GlobalManager)1 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 HashWrapper (com.biglybt.core.util.HashWrapper)1 Download (com.biglybt.pif.download.Download)1 Torrent (com.biglybt.pif.torrent.Torrent)1