Search in sources :

Example 11 with DiskManagerFileInfo

use of com.biglybt.pif.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.

the class DownloadRemoveRulesPlugin method downloadAdded.

@Override
public void downloadAdded(final Download download) {
    if (!download.isPersistent()) {
        return;
    }
    if (download.getFlag(Download.FLAG_LOW_NOISE)) {
        DiskManagerFileInfo[] files = download.getDiskManagerFileInfo();
        if (files.length == 1) {
            DiskManagerFileInfo file = files[0];
            if (file.getDownloaded() == file.getLength() && !file.getFile().exists()) {
                log.log("Removing low-noise download '" + download.getName() + " as data missing");
                removeDownload(download, false);
            }
        }
    }
    DownloadTrackerListener listener = new DownloadTrackerListener() {

        @Override
        public void scrapeResult(DownloadScrapeResult response) {
            if (closing) {
                return;
            }
            handleScrape(download, response);
        }

        @Override
        public void announceResult(DownloadAnnounceResult response) {
            if (closing) {
                return;
            }
            handleAnnounce(download, response);
        }
    };
    monitored_downloads.add(download);
    dm_listener_map.put(download, listener);
    download.addTrackerListener(listener);
}
Also used : DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo)

Example 12 with DiskManagerFileInfo

use of com.biglybt.pif.disk.DiskManagerFileInfo 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 13 with DiskManagerFileInfo

use of com.biglybt.pif.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.

the class RelatedContentManager method checkAlternativePubs.

void checkAlternativePubs(DownloadInfo to_info, final byte[] map_bytes, final int f_cutoff) {
    Download dl = to_info.getRelatedToDownload();
    if (dl != null) {
        DiskManagerFileInfo[] files = dl.getDiskManagerFileInfo();
        List<Long> sizes = new ArrayList<>();
        for (DiskManagerFileInfo file : files) {
            long size = file.getLength();
            if (size >= FILE_ASSOC_MIN_SIZE) {
                sizes.add(size);
            }
        }
        final DHTPluginInterface dht_plugin = selectDHT(to_info.getNetworksInternal());
        if (dht_plugin != null && sizes.size() > 0) {
            try {
                final String to_hash = ByteFormatter.encodeString(to_info.getHash());
                final long selected_size = sizes.get(new Random().nextInt(sizes.size()));
                final byte[] key_bytes = ("az:rcm:size:assoc:" + selected_size).getBytes("UTF-8");
                int max_hits = 30;
                dht_plugin.get(key_bytes, "Content size rel test: " + to_hash.substring(0, 16), DHTPlugin.FLAG_SINGLE_VALUE, max_hits, 30 * 1000, false, false, new DHTPluginOperationListener() {

                    private boolean diversified;

                    private int hits;

                    private Set<String> entries = new HashSet<>();

                    @Override
                    public void starts(byte[] key) {
                    }

                    @Override
                    public boolean diversified() {
                        diversified = true;
                        return (false);
                    }

                    @Override
                    public void valueRead(DHTPluginContact originator, DHTPluginValue value) {
                        hits++;
                    }

                    @Override
                    public void valueWritten(DHTPluginContact target, DHTPluginValue value) {
                    }

                    @Override
                    public void complete(byte[] key, boolean timeout_occurred) {
                        boolean do_it;
                        if (diversified || hits >= f_cutoff) {
                            do_it = false;
                        } else if (hits <= f_cutoff / 2) {
                            do_it = true;
                        } else {
                            do_it = RandomUtils.nextInt(hits - (f_cutoff / 2) + 1) == 0;
                        }
                        if (do_it) {
                            try {
                                dht_plugin.put(key_bytes, "Content size rel: " + selected_size + " -> " + to_hash.substring(0, 16), map_bytes, DHTPlugin.FLAG_ANON, new DHTPluginOperationListener() {

                                    @Override
                                    public boolean diversified() {
                                        return (true);
                                    }

                                    @Override
                                    public void starts(byte[] key) {
                                    }

                                    @Override
                                    public void valueRead(DHTPluginContact originator, DHTPluginValue value) {
                                    }

                                    @Override
                                    public void valueWritten(DHTPluginContact target, DHTPluginValue value) {
                                    }

                                    @Override
                                    public void complete(byte[] key, boolean timeout_occurred) {
                                    }
                                });
                            } catch (Throwable e) {
                                Debug.printStackTrace(e);
                            }
                        }
                    }
                });
            } catch (Throwable e) {
                Debug.out(e);
            }
        }
    }
}
Also used : DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) Download(com.biglybt.pif.download.Download)

Example 14 with DiskManagerFileInfo

use of com.biglybt.pif.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.

the class DeviceUPnPImpl method setupStreamXCode.

protected boolean setupStreamXCode(TranscodeFileImpl transcode_file) {
    final TranscodeJobImpl job = transcode_file.getJob();
    if (job == null) {
        return (transcode_file.isComplete());
    }
    final String tf_key = transcode_file.getKey();
    ContentFile acf;
    synchronized (acf_map) {
        acf = acf_map.get(tf_key);
    }
    if (acf != null) {
        return (true);
    }
    IPCInterface ipc = upnpav_ipc;
    if (ipc == null) {
        return (false);
    }
    if (transcode_file.getDurationMillis() == 0) {
        return (false);
    }
    try {
        final DiskManagerFileInfo stream_file = new TranscodeJobOutputLeecher(job, transcode_file);
        acf = new ContentFile() {

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

            @Override
            public Object getProperty(String name) {
                if (name.equals(MY_ACF_KEY)) {
                    return (new Object[] { DeviceUPnPImpl.this, tf_key });
                } else if (name.equals(PT_PERCENT_DONE)) {
                    return (new Long(1000));
                } else if (name.equals(PT_ETA)) {
                    return (new Long(0));
                }
                return (null);
            }
        };
        synchronized (acf_map) {
            acf_map.put(tf_key, acf);
        }
        ipc.invoke("addContent", new Object[] { acf });
        log("Set up stream-xcode for " + transcode_file.getName());
        return (true);
    } catch (Throwable e) {
        return (false);
    }
}
Also used : DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) ContentFile(com.biglybt.core.content.ContentFile) IPCInterface(com.biglybt.pif.ipc.IPCInterface)

Example 15 with DiskManagerFileInfo

use of com.biglybt.pif.disk.DiskManagerFileInfo in project BiglyBT by BiglySoftware.

the class DeviceUPnPImpl method fileAdded.

public void fileAdded(TranscodeFile _transcode_file, boolean _new_file) {
    TranscodeFileImpl transcode_file = (TranscodeFileImpl) _transcode_file;
    IPCInterface ipc = upnpav_ipc;
    synchronized (this) {
        if (ipc == null) {
            return;
        }
        if (!transcode_file.isComplete()) {
            syncCategoriesAndTags(transcode_file, _new_file);
            return;
        }
        ContentFile acf = (ContentFile) transcode_file.getTransientProperty(UPNPAV_FILE_KEY);
        if (acf != null) {
            return;
        }
        final String tf_key = transcode_file.getKey();
        synchronized (acf_map) {
            acf = acf_map.get(tf_key);
        }
        if (acf != null) {
            return;
        }
        try {
            final DiskManagerFileInfo f = transcode_file.getTargetFile();
            acf = new ContentFile() {

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

                @Override
                public Object getProperty(String name) {
                    if (name.equals(MY_ACF_KEY)) {
                        return (new Object[] { DeviceUPnPImpl.this, tf_key });
                    } else if (name.equals(PT_CATEGORIES)) {
                        TranscodeFileImpl tf = getTranscodeFile(tf_key);
                        if (tf != null) {
                            return (tf.getCategories());
                        }
                        return (new String[0]);
                    } else if (name.equals(PT_TAGS)) {
                        TranscodeFileImpl tf = getTranscodeFile(tf_key);
                        if (tf != null) {
                            return (tf.getTags(true));
                        }
                        return (new String[0]);
                    } else if (name.equals(PT_TITLE)) {
                        TranscodeFileImpl tf = getTranscodeFile(tf_key);
                        if (tf != null) {
                            return (tf.getName());
                        }
                    } else {
                        TranscodeFileImpl tf = getTranscodeFile(tf_key);
                        if (tf != null) {
                            long res = 0;
                            if (name.equals(PT_DURATION)) {
                                res = tf.getDurationMillis();
                            } else if (name.equals(PT_VIDEO_WIDTH)) {
                                res = tf.getVideoWidth();
                            } else if (name.equals(PT_VIDEO_HEIGHT)) {
                                res = tf.getVideoHeight();
                            } else if (name.equals(PT_DATE)) {
                                res = tf.getCreationDateMillis();
                            } else if (name.equals(PT_PERCENT_DONE)) {
                                if (tf.isComplete()) {
                                    res = 1000;
                                } else {
                                    TranscodeJob job = tf.getJob();
                                    if (job == null) {
                                        res = 0;
                                    } else {
                                        res = 10 * job.getPercentComplete();
                                    }
                                }
                                return (res);
                            } else if (name.equals(PT_ETA)) {
                                if (tf.isComplete()) {
                                    res = 0;
                                } else {
                                    TranscodeJob job = tf.getJob();
                                    if (job == null) {
                                        res = Long.MAX_VALUE;
                                    } else {
                                        res = job.getETASecs();
                                    }
                                }
                                return (res);
                            }
                            if (res > 0) {
                                return (new Long(res));
                            }
                        }
                    }
                    return (null);
                }
            };
            transcode_file.setTransientProperty(UPNPAV_FILE_KEY, acf);
            synchronized (acf_map) {
                acf_map.put(tf_key, acf);
            }
            syncCategoriesAndTags(transcode_file, _new_file);
            try {
                ipc.invoke("addContent", new Object[] { acf });
            } catch (Throwable e) {
                Debug.out(e);
            }
        } catch (TranscodeException e) {
        // file deleted
        }
    }
}
Also used : DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) ContentFile(com.biglybt.core.content.ContentFile) IPCInterface(com.biglybt.pif.ipc.IPCInterface)

Aggregations

DiskManagerFileInfo (com.biglybt.pif.disk.DiskManagerFileInfo)23 Download (com.biglybt.pif.download.Download)11 DownloadException (com.biglybt.pif.download.DownloadException)5 IPCInterface (com.biglybt.pif.ipc.IPCInterface)5 Torrent (com.biglybt.pif.torrent.Torrent)3 Point (org.eclipse.swt.graphics.Point)3 ContentFile (com.biglybt.core.content.ContentFile)2 TranscodeFile (com.biglybt.core.devices.TranscodeFile)2 TranscodeJob (com.biglybt.core.devices.TranscodeJob)2 DownloadManager (com.biglybt.core.download.DownloadManager)2 TOTorrent (com.biglybt.core.torrent.TOTorrent)2 MenuItem (com.biglybt.pif.ui.menus.MenuItem)2 MenuItemFillListener (com.biglybt.pif.ui.menus.MenuItemFillListener)2 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)2 TableContextMenuItem (com.biglybt.pif.ui.tables.TableContextMenuItem)2 TableRow (com.biglybt.pif.ui.tables.TableRow)2 ISelectedContent (com.biglybt.ui.selectedcontent.ISelectedContent)2 File (java.io.File)2 URL (java.net.URL)2 ActivitiesEntry (com.biglybt.activities.ActivitiesEntry)1