Search in sources :

Example 1 with TOTorrent

use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.

the class SBC_TagDiscovery method startScan.

private void startScan() {
    try {
        mon_scansRemaining.enter();
        if (scansRemaining > 0) {
            return;
        }
    } finally {
        mon_scansRemaining.exit();
    }
    CoreFactory.addCoreRunningListener(new CoreRunningListener() {

        @Override
        public void coreRunning(Core core) {
            GlobalManager gm = core.getGlobalManager();
            try {
                try {
                    mon_scansRemaining.enter();
                    scansRemaining = 0;
                } finally {
                    mon_scansRemaining.exit();
                }
                RelatedContentManager rcm = RelatedContentManager.getSingleton();
                List<DownloadManager> dms = gm.getDownloadManagers();
                for (final DownloadManager dm : dms) {
                    if (tv == null) {
                        return;
                    }
                    TOTorrent torrent = dm.getTorrent();
                    if (torrent == null) {
                        continue;
                    }
                    try {
                        final byte[] hash = torrent.getHash();
                        try {
                            mon_scansRemaining.enter();
                            scansRemaining++;
                            if (vitalityImage != null && scansRemaining == 1) {
                                vitalityImage.setVisible(true);
                            }
                            if (soTitle != null) {
                                soTitle.setText(MessageText.getString("tag.discovery.view.heading") + " : Scanning " + scansRemaining);
                            }
                        } finally {
                            mon_scansRemaining.exit();
                        }
                        try {
                            rcm.lookupAttributes(hash, dm.getDownloadState().getNetworks(), new RelatedAttributeLookupListener() {

                                @Override
                                public void tagFound(String tag, String network) {
                                    if (DEBUG) {
                                        System.out.println("Tag Search: Found Tag " + tag + " for " + dm.getDisplayName());
                                    }
                                    if (tv == null) {
                                        return;
                                    }
                                    String key = Base32.encode(hash) + tag;
                                    TagManager tm = TagManagerFactory.getTagManager();
                                    TagType tt_manual = tm.getTagType(TagType.TT_DOWNLOAD_MANUAL);
                                    List<Tag> existingDMTags = tt_manual.getTagsForTaggable(dm);
                                    for (Tag existingTag : existingDMTags) {
                                        if (existingTag.getTagName(true).equalsIgnoreCase(tag)) {
                                            return;
                                        }
                                    }
                                    synchronized (mapTagDiscoveries) {
                                        if (!mapTagDiscoveries.containsKey(key)) {
                                            TagDiscovery tagDiscovery = new TagDiscovery(tag, network, dm.getDisplayName(), hash);
                                            mapTagDiscoveries.put(key, tagDiscovery);
                                            ViewTitleInfoManager.refreshTitleInfo(SBC_TagDiscovery.this);
                                            tv.addDataSource(tagDiscovery);
                                        }
                                    }
                                }

                                @Override
                                public void lookupStart() {
                                    if (DEBUG) {
                                        System.out.println("Tag Search: Start" + " for " + dm.getDisplayName());
                                    }
                                }

                                @Override
                                public void lookupFailed(ContentException error) {
                                    if (DEBUG) {
                                        System.out.println("Tag Search: Failed " + error.getMessage() + " for " + dm.getDisplayName());
                                    }
                                }

                                @Override
                                public void lookupComplete() {
                                    decreaseScansRemaining();
                                    if (DEBUG) {
                                        System.out.println("Tag Search: Complete" + " for " + dm.getDisplayName());
                                    }
                                }
                            });
                        } catch (Throwable e) {
                            // can get here if the scan never gets kicked off (dht unavailable for network etc)
                            decreaseScansRemaining();
                        }
                    } catch (TOTorrentException e) {
                        e.printStackTrace();
                    }
                }
            } catch (ContentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });
}
Also used : RelatedContentManager(com.biglybt.core.content.RelatedContentManager) ContentException(com.biglybt.core.content.ContentException) RelatedAttributeLookupListener(com.biglybt.core.content.RelatedAttributeLookupListener) DownloadManager(com.biglybt.core.download.DownloadManager) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) GlobalManager(com.biglybt.core.global.GlobalManager) TOTorrent(com.biglybt.core.torrent.TOTorrent) CoreRunningListener(com.biglybt.core.CoreRunningListener) List(java.util.List) Core(com.biglybt.core.Core)

Example 2 with TOTorrent

use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.

the class TorrentListViewsUtils method downloadDataSource.

public static void downloadDataSource(Object ds, boolean playNow, String referal) {
    TOTorrent torrent = DataSourceUtils.getTorrent(ds);
    if (torrent != null) {
        // handle encapsulated vuze file
        try {
            Map torrent_map = torrent.serialiseToMap();
            torrent_map.remove("info");
            VuzeFile vf = VuzeFileHandler.getSingleton().loadVuzeFile(torrent_map);
            if (vf != null) {
                VuzeFileHandler.getSingleton().handleFiles(new VuzeFile[] { vf }, VuzeFileComponent.COMP_TYPE_NONE);
                return;
            }
        } catch (Throwable e) {
        }
    }
    // one is likely stale
    if (torrent != null) {
        TorrentUIUtilsV3.addTorrentToGM(torrent);
    } else {
        DownloadUrlInfo dlInfo = DataSourceUtils.getDownloadInfo(ds);
        if (dlInfo != null) {
            TorrentUIUtilsV3.loadTorrent(dlInfo, playNow, false, true);
            return;
        }
        String hash = DataSourceUtils.getHash(ds);
        if (hash != null) {
            dlInfo = new DownloadUrlInfo(UrlUtils.parseTextForMagnets(hash));
            dlInfo.setReferer(referal);
            TorrentUIUtilsV3.loadTorrent(dlInfo, playNow, false, true);
            return;
        }
    }
}
Also used : DownloadUrlInfo(com.biglybt.ui.selectedcontent.DownloadUrlInfo) TOTorrent(com.biglybt.core.torrent.TOTorrent) VuzeFile(com.biglybt.core.vuzefile.VuzeFile) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with TOTorrent

use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.

the class SBC_LibraryTableView method doDefaultClick.

public static void doDefaultClick(final TableRowCore[] rows, final int stateMask, final boolean neverPlay, int origin) {
    if (rows == null || rows.length != 1) {
        return;
    }
    final Object ds = rows[0].getDataSource(true);
    boolean webInBrowser = COConfigurationManager.getBooleanParameter("Library.LaunchWebsiteInBrowser");
    if (webInBrowser) {
        DiskManagerFileInfo fileInfo = DataSourceUtils.getFileInfo(ds);
        if (fileInfo != null) {
            if (ManagerUtils.browseWebsite(fileInfo)) {
                return;
            }
        } else {
            DownloadManager dm = DataSourceUtils.getDM(ds);
            if (dm != null) {
                if (ManagerUtils.browseWebsite(dm)) {
                    return;
                }
            }
        }
    }
    String mode = COConfigurationManager.getStringParameter("list.dm.dblclick");
    if (origin == 1) {
        String enter_mode = COConfigurationManager.getStringParameter("list.dm.enteraction");
        if (!enter_mode.equals("-1")) {
            mode = enter_mode;
        }
    }
    if (mode.equals("1")) {
        if (UIFunctionsManager.getUIFunctions().getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, ds)) {
            return;
        }
    } else if (mode.equals("2")) {
        // Show in explorer
        boolean openMode = COConfigurationManager.getBooleanParameter("MyTorrentsView.menu.show_parent_folder_enabled");
        DiskManagerFileInfo file = DataSourceUtils.getFileInfo(ds);
        if (file != null) {
            ManagerUtils.open(file, openMode);
            return;
        }
        DownloadManager dm = DataSourceUtils.getDM(ds);
        if (dm != null) {
            ManagerUtils.open(dm, openMode);
            return;
        }
    } else if (mode.equals("3") || mode.equals("4")) {
        // Launch
        DiskManagerFileInfo file = DataSourceUtils.getFileInfo(ds);
        if (file != null) {
            if (mode.equals("4") && file.getDownloaded() == file.getLength() && Utils.isQuickViewSupported(file)) {
                Utils.setQuickViewActive(file, true);
            } else {
                TorrentUtil.runDataSources(new Object[] { file });
            }
            return;
        }
        DownloadManager dm = DataSourceUtils.getDM(ds);
        if (dm != null) {
            TorrentUtil.runDataSources(new Object[] { dm });
            return;
        }
    } else if (mode.equals("5")) {
        DiskManagerFileInfo fileInfo = DataSourceUtils.getFileInfo(ds);
        if (fileInfo != null) {
            ManagerUtils.browse(fileInfo);
            return;
        }
        DownloadManager dm = DataSourceUtils.getDM(ds);
        if (dm != null) {
            ManagerUtils.browse(dm);
            return;
        }
    }
    if (neverPlay) {
        return;
    }
    if (PlayUtils.canPlayDS(ds, -1, true) || (stateMask & SWT.CONTROL) != 0) {
        TorrentListViewsUtils.playOrStreamDataSource(ds, DLReferals.DL_REFERAL_DBLCLICK, false, true);
        return;
    }
    if (PlayUtils.canStreamDS(ds, -1, true)) {
        TorrentListViewsUtils.playOrStreamDataSource(ds, DLReferals.DL_REFERAL_DBLCLICK, true, false);
        return;
    }
    DownloadManager dm = DataSourceUtils.getDM(ds);
    DiskManagerFileInfo file = DataSourceUtils.getFileInfo(ds);
    TOTorrent torrent = DataSourceUtils.getTorrent(ds);
    if (torrent == null && file != null) {
        DownloadManager dmFile = file.getDownloadManager();
        if (dmFile != null) {
            torrent = dmFile.getTorrent();
        }
    }
    if (file != null && file.getDownloaded() == file.getLength()) {
        TorrentUtil.runDataSources(new Object[] { file });
    } else if (dm != null) {
        TorrentUtil.runDataSources(new Object[] { dm });
    }
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) TOTorrent(com.biglybt.core.torrent.TOTorrent) SWTSkinObject(com.biglybt.ui.swt.skin.SWTSkinObject) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 4 with TOTorrent

use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.

the class TrackerNameItem method refresh.

@Override
public void refresh(TableCell cell) {
    DownloadManager dm = (DownloadManager) cell.getDataSource();
    String name = "";
    if (dm != null && dm.getTorrent() != null) {
        TOTorrent torrent = dm.getTorrent();
        name = getTrackerName(torrent);
    }
    if (cell.setText(name) || !cell.isValid()) {
        TrackerCellUtils.updateColor(cell, dm, false);
    }
}
Also used : TOTorrent(com.biglybt.core.torrent.TOTorrent) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 5 with TOTorrent

use of com.biglybt.core.torrent.TOTorrent in project BiglyBT by BiglySoftware.

the class NameItem method refresh.

@Override
public void refresh(TableCell cell, boolean sortOnlyRefresh) {
    String name = null;
    DownloadManager dm = (DownloadManager) cell.getDataSource();
    if (dm != null)
        name = dm.getDisplayName();
    if (name == null)
        name = "";
    // setText returns true only if the text is updated
    if ((cell.setText(name) || !cell.isValid())) {
        if (dm != null && isShowIcon() && !sortOnlyRefresh && (cell instanceof TableCellSWT)) {
            DiskManagerFileInfo fileInfo = dm.getDownloadState().getPrimaryFile();
            if (fileInfo != null) {
                // Don't ever dispose of PathIcon, it's cached and may be used elsewhere
                TOTorrent torrent = dm.getTorrent();
                Image icon = ImageRepository.getPathIcon(fileInfo.getFile(false).getName(), false, torrent != null && !torrent.isSimpleTorrent());
                ((TableCellSWT) cell).setIcon(icon);
            }
        }
    }
}
Also used : DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) TableCellSWT(com.biglybt.ui.swt.views.table.TableCellSWT) TOTorrent(com.biglybt.core.torrent.TOTorrent) Image(org.eclipse.swt.graphics.Image) DownloadManager(com.biglybt.core.download.DownloadManager)

Aggregations

TOTorrent (com.biglybt.core.torrent.TOTorrent)123 DownloadManager (com.biglybt.core.download.DownloadManager)34 File (java.io.File)32 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)29 URL (java.net.URL)25 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)15 TOTorrentFile (com.biglybt.core.torrent.TOTorrentFile)13 IOException (java.io.IOException)13 GlobalManager (com.biglybt.core.global.GlobalManager)10 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)10 Torrent (com.biglybt.pif.torrent.Torrent)9 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)8 TOTorrentAnnounceURLSet (com.biglybt.core.torrent.TOTorrentAnnounceURLSet)8 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)8 List (java.util.List)8 Map (java.util.Map)7 Core (com.biglybt.core.Core)6 DiskManagerFileInfoSet (com.biglybt.core.disk.DiskManagerFileInfoSet)6 Download (com.biglybt.pif.download.Download)6 TorrentImpl (com.biglybt.pifimpl.local.torrent.TorrentImpl)6