Search in sources :

Example 6 with TorrentAttribute

use of com.biglybt.pif.torrent.TorrentAttribute in project BiglyBT by BiglySoftware.

the class ExternalSeedPlugin method addSeed.

public List<ExternalSeedPeer> addSeed(Download download, Map config) {
    Torrent torrent = download.getTorrent();
    List<ExternalSeedPeer> peers = new ArrayList<>();
    if (torrent != null) {
        for (int i = 0; i < factories.length; i++) {
            String attributeID = "no-ext-seeds-" + factories[i].getClass().getSimpleName();
            TorrentAttribute attribute = plugin_interface.getTorrentManager().getPluginAttribute(attributeID);
            ExternalSeedReader[] x = factories[i].getSeedReaders(this, download, config);
            download.setBooleanAttribute(attribute, x.length == 0);
            for (int j = 0; j < x.length; j++) {
                ExternalSeedReader reader = x[j];
                ExternalSeedPeer peer = new ExternalSeedPeer(this, download, reader);
                peers.add(peer);
            }
        }
        addPeers(download, peers);
    }
    return (peers);
}
Also used : Torrent(com.biglybt.pif.torrent.Torrent) TorrentAttribute(com.biglybt.pif.torrent.TorrentAttribute)

Example 7 with TorrentAttribute

use of com.biglybt.pif.torrent.TorrentAttribute in project BiglyBT by BiglySoftware.

the class PlatformContentDirectory method lookupContentFile.

@Override
public ContentFile lookupContentFile(Map attributes) {
    byte[] hash = (byte[]) attributes.get(AT_BTIH);
    int index = ((Integer) attributes.get(AT_FILE_INDEX)).intValue();
    try {
        Download download = PluginInitializer.getDefaultInterface().getDownloadManager().getDownload(hash);
        if (download == null) {
            return (null);
        }
        Torrent t_torrent = download.getTorrent();
        if (t_torrent == null) {
            return (null);
        }
        String ud_key = "PlatformContentDirectory" + ":" + index;
        ContentFile acf = (ContentFile) download.getUserData(ud_key);
        if (acf != null) {
            return (acf);
        }
        final DiskManagerFileInfo file = download.getDiskManagerFileInfo(index);
        acf = new ContentFile() {

            @Override
            public DiskManagerFileInfo getFile() {
                return (file);
            }

            @Override
            public Object getProperty(String name) {
                try {
                    if (name.equals(PT_DATE)) {
                        return (new Long(file.getDownload().getCreationTime()));
                    } else if (name.equals(PT_CATEGORIES)) {
                        try {
                            String cat = file.getDownload().getCategoryName();
                            if (cat != null && cat.length() > 0) {
                                if (!cat.equalsIgnoreCase("Categories.uncategorized")) {
                                    return (new String[] { cat });
                                }
                            }
                        } catch (Throwable e) {
                        }
                        return (new String[0]);
                    } else if (name.equals(PT_TAGS)) {
                        List<Tag> tags = TagManagerFactory.getTagManager().getTagsForTaggable(PluginCoreUtils.unwrap(file.getDownload()));
                        List<String> tag_names = new ArrayList<>();
                        for (Tag tag : tags) {
                            if (tag.getTagType().getTagType() == TagType.TT_DOWNLOAD_MANUAL) {
                                tag_names.add(tag.getTagName(true));
                            }
                        }
                        return (tag_names.toArray(new String[tag_names.size()]));
                    } else if (name.equals(PT_PERCENT_DONE)) {
                        long size = file.getLength();
                        return (new Long(size == 0 ? 100 : (1000 * file.getDownloaded() / size)));
                    } else if (name.equals(PT_ETA)) {
                        return (getETA(file));
                    }
                } catch (Throwable e) {
                }
                return (null);
            }
        };
        download.setUserData(ud_key, acf);
        final ContentFile f_acf = acf;
        download.addAttributeListener(new DownloadAttributeListener() {

            @Override
            public void attributeEventOccurred(Download download, TorrentAttribute attribute, int eventType) {
                fireCatsChanged(f_acf);
            }
        }, ta_category, DownloadAttributeListener.WRITTEN);
        TagManagerFactory.getTagManager().getTagType(TagType.TT_DOWNLOAD_MANUAL).addTagListener(PluginCoreUtils.unwrap(download), new TagListener() {

            @Override
            public void taggableSync(Tag tag) {
            }

            @Override
            public void taggableRemoved(Tag tag, Taggable tagged) {
                update(tagged);
            }

            @Override
            public void taggableAdded(Tag tag, Taggable tagged) {
                update(tagged);
            }

            private void update(Taggable tagged) {
                fireTagsChanged(f_acf);
            }
        });
        return (acf);
    } catch (Throwable e) {
        return (null);
    }
}
Also used : Torrent(com.biglybt.pif.torrent.Torrent) DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) TorrentAttribute(com.biglybt.pif.torrent.TorrentAttribute) DownloadAttributeListener(com.biglybt.pif.download.DownloadAttributeListener) List(java.util.List) ArrayList(java.util.ArrayList) CopyOnWriteList(com.biglybt.core.util.CopyOnWriteList) Download(com.biglybt.pif.download.Download)

Example 8 with TorrentAttribute

use of com.biglybt.pif.torrent.TorrentAttribute in project BiglyBT by BiglySoftware.

the class DeviceUPnPImpl method syncCategoriesAndTags.

protected void syncCategoriesAndTags(TranscodeFileImpl tf, boolean inherit_from_download) {
    try {
        final Download dl = tf.getSourceFile().getDownload();
        if (dl != null) {
            if (inherit_from_download) {
                setCategories(tf, dl);
                setTags(tf, dl);
            }
            final String tf_key = tf.getKey();
            dl.addAttributeListener(new DownloadAttributeListener() {

                @Override
                public void attributeEventOccurred(Download download, TorrentAttribute attribute, int eventType) {
                    TranscodeFileImpl tf = getTranscodeFile(tf_key);
                    if (tf != null) {
                        setCategories(tf, download);
                    } else {
                        dl.removeAttributeListener(this, upnp_manager.getCategoryAttibute(), DownloadAttributeListener.WRITTEN);
                    }
                }
            }, upnp_manager.getCategoryAttibute(), DownloadAttributeListener.WRITTEN);
            TagManagerFactory.getTagManager().getTagType(TagType.TT_DOWNLOAD_MANUAL).addTagListener(PluginCoreUtils.unwrap(dl), new TagListener() {

                @Override
                public void taggableSync(Tag tag) {
                }

                @Override
                public void taggableRemoved(Tag tag, Taggable tagged) {
                    update(tagged);
                }

                @Override
                public void taggableAdded(Tag tag, Taggable tagged) {
                    update(tagged);
                }

                private void update(Taggable tagged) {
                    TranscodeFileImpl tf = getTranscodeFile(tf_key);
                    if (tf != null) {
                        setTags(tf, dl);
                    } else {
                        TagManagerFactory.getTagManager().getTagType(TagType.TT_DOWNLOAD_MANUAL).removeTagListener(tagged, this);
                    }
                }
            });
        }
    } catch (Throwable e) {
    }
}
Also used : TorrentAttribute(com.biglybt.pif.torrent.TorrentAttribute) DownloadAttributeListener(com.biglybt.pif.download.DownloadAttributeListener) Download(com.biglybt.pif.download.Download) ContentDownload(com.biglybt.core.content.ContentDownload)

Example 9 with TorrentAttribute

use of com.biglybt.pif.torrent.TorrentAttribute in project BiglyBT by BiglySoftware.

the class ShareManagerImpl method generate.

@Override
public void generate(IndentWriter writer) {
    writer.println("Shares");
    try {
        writer.indent();
        ShareResource[] shares = getShares();
        HashSet share_map = new HashSet();
        for (int i = 0; i < shares.length; i++) {
            ShareResource share = shares[i];
            if (share instanceof ShareResourceDirContents) {
                share_map.add(share);
            } else if (share.getParent() != null) {
            } else {
                writer.println(getDebugName(share));
            }
        }
        Iterator it = share_map.iterator();
        // Hopefully all the things we need are avail on core create
        if (!CoreFactory.isCoreAvailable()) {
            // could probably log some stuff below, but for now
            // be safe and lazy and just exit
            writer.println("No Core");
            return;
        }
        TorrentManager tm = PluginInitializer.getDefaultInterface().getTorrentManager();
        TorrentAttribute category_attribute = tm.getAttribute(TorrentAttribute.TA_CATEGORY);
        TorrentAttribute props_attribute = tm.getAttribute(TorrentAttribute.TA_SHARE_PROPERTIES);
        while (it.hasNext()) {
            ShareResourceDirContents root = (ShareResourceDirContents) it.next();
            String cat = root.getAttribute(category_attribute);
            String props = root.getAttribute(props_attribute);
            String extra = cat == null ? "" : (",cat=" + cat);
            extra += props == null ? "" : (",props=" + props);
            extra += ",rec=" + root.isRecursive();
            writer.println(root.getName() + extra);
            generate(writer, root);
        }
    } finally {
        writer.exdent();
    }
}
Also used : TorrentAttribute(com.biglybt.pif.torrent.TorrentAttribute) TorrentManager(com.biglybt.pif.torrent.TorrentManager)

Example 10 with TorrentAttribute

use of com.biglybt.pif.torrent.TorrentAttribute in project BiglyBT by BiglySoftware.

the class ShareResourceFileOrDirImpl method createTorrent.

protected void createTorrent() throws ShareException {
    try {
        manager.reportCurrentTask((item == null ? "Creating" : "Re-creating").concat(" torrent for '").concat(file.toString()).concat("'"));
        URL[] urls = manager.getAnnounceURLs();
        TOTorrentCreator creator = TOTorrentFactory.createFromFileOrDirWithComputedPieceLength(file, urls[0], manager.getAddHashes());
        creator.addListener(manager);
        TOTorrent to_torrent;
        try {
            manager.setTorrentCreator(creator);
            to_torrent = creator.create();
        } finally {
            manager.setTorrentCreator(null);
        }
        if (personal_key != null) {
            Map map = to_torrent.serialiseToMap();
            Map info = (Map) map.get("info");
            info.put("az_salt", personal_key);
            to_torrent = TOTorrentFactory.deserialiseFromMap(map);
        }
        LocaleTorrentUtil.setDefaultTorrentEncoding(to_torrent);
        for (int i = 1; i < urls.length; i++) {
            TorrentUtils.announceGroupsInsertLast(to_torrent, new URL[] { urls[i] });
        }
        String comment = COConfigurationManager.getStringParameter("Sharing Torrent Comment").trim();
        boolean private_torrent = COConfigurationManager.getBooleanParameter("Sharing Torrent Private");
        boolean dht_backup_enabled = COConfigurationManager.getBooleanParameter("Sharing Permit DHT");
        TorrentAttribute ta_props = TorrentManagerImpl.getSingleton().getAttribute(TorrentAttribute.TA_SHARE_PROPERTIES);
        String props = getAttribute(ta_props);
        if (props != null) {
            StringTokenizer tok = new StringTokenizer(props, ";");
            while (tok.hasMoreTokens()) {
                String token = tok.nextToken();
                int pos = token.indexOf('=');
                if (pos == -1) {
                    Debug.out("ShareProperty invalid: " + props);
                } else {
                    String lhs = token.substring(0, pos).trim().toLowerCase();
                    String rhs = token.substring(pos + 1).trim().toLowerCase();
                    boolean set = rhs.equals("true");
                    if (lhs.equals("private")) {
                        private_torrent = set;
                    } else if (lhs.equals("dht_backup")) {
                        dht_backup_enabled = set;
                    } else if (lhs.equals("comment")) {
                        comment = rhs;
                    } else {
                        Debug.out("ShareProperty invalid: " + props);
                        break;
                    }
                }
            }
        }
        if (comment.length() > 0) {
            to_torrent.setComment(comment);
        }
        TorrentUtils.setDHTBackupEnabled(to_torrent, dht_backup_enabled);
        TorrentUtils.setPrivate(to_torrent, private_torrent);
        if (TorrentUtils.isDecentralised(to_torrent)) {
            TorrentUtils.setDecentralised(to_torrent);
        }
        if (COConfigurationManager.getBooleanParameter("Sharing Disable RCM")) {
            TorrentUtils.setFlag(to_torrent, TorrentUtils.TORRENT_FLAG_DISABLE_RCM, true);
        }
        DownloadManagerState download_manager_state = DownloadManagerStateFactory.getDownloadState(to_torrent);
        TorrentUtils.setResumeDataCompletelyValid(download_manager_state);
        download_manager_state.save();
        if (item == null) {
            byte[] fingerprint = getFingerPrint();
            item = new ShareItemImpl(this, fingerprint, new TorrentImpl(to_torrent));
        } else {
            item.setTorrent(new TorrentImpl(to_torrent));
            item.writeTorrent();
        }
    } catch (TOTorrentException e) {
        if (e.getReason() == TOTorrentException.RT_CANCELLED) {
            throw (new ShareException("ShareResource: Operation cancelled", e));
        } else {
            throw (new ShareException("ShareResource: Torrent create failed", e));
        }
    } catch (Throwable e) {
        throw (new ShareException("ShareResource: Torrent create failed", e));
    }
}
Also used : TorrentImpl(com.biglybt.pifimpl.local.torrent.TorrentImpl) DownloadManagerState(com.biglybt.core.download.DownloadManagerState) URL(java.net.URL) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) StringTokenizer(java.util.StringTokenizer) TorrentAttribute(com.biglybt.pif.torrent.TorrentAttribute) ShareException(com.biglybt.pif.sharing.ShareException) TOTorrent(com.biglybt.core.torrent.TOTorrent) TOTorrentCreator(com.biglybt.core.torrent.TOTorrentCreator) Map(java.util.Map)

Aggregations

TorrentAttribute (com.biglybt.pif.torrent.TorrentAttribute)11 Torrent (com.biglybt.pif.torrent.Torrent)5 Download (com.biglybt.pif.download.Download)3 TOTorrent (com.biglybt.core.torrent.TOTorrent)2 DownloadAttributeListener (com.biglybt.pif.download.DownloadAttributeListener)2 ShareException (com.biglybt.pif.sharing.ShareException)2 TorrentManager (com.biglybt.pif.torrent.TorrentManager)2 ContentDownload (com.biglybt.core.content.ContentDownload)1 DownloadManager (com.biglybt.core.download.DownloadManager)1 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)1 PEPeer (com.biglybt.core.peer.PEPeer)1 PEPeerManager (com.biglybt.core.peer.PEPeerManager)1 Tag (com.biglybt.core.tag.Tag)1 TOTorrentCreator (com.biglybt.core.torrent.TOTorrentCreator)1 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)1 TRTrackerAnnouncerResponsePeer (com.biglybt.core.tracker.client.TRTrackerAnnouncerResponsePeer)1 AEThread (com.biglybt.core.util.AEThread)1 CopyOnWriteList (com.biglybt.core.util.CopyOnWriteList)1 MagnetURIHandler (com.biglybt.net.magneturi.MagnetURIHandler)1 MagnetURIHandlerException (com.biglybt.net.magneturi.MagnetURIHandlerException)1