use of com.frostwire.jlibtorrent.TorrentInfo in project frostwire by frostwire.
the class SeedAction method buildTorrentAndSeedIt.
private void buildTorrentAndSeedIt(final FileDescriptor fd) {
try {
// TODO: Do this so it works with SD Card support / New BS File storage api from Android.
File file = new File(fd.filePath);
File saveDir = file.getParentFile();
file_storage fs = new file_storage();
fs.add_file(file.getName(), file.length());
fs.set_name(file.getName());
// , 0, -1, create_torrent.flags_t.merkle.swigValue());
create_torrent ct = new create_torrent(fs);
// commented out the merkle flag above because torrent doesn't appear as "Seeding", piece count doesn't work
// as the algorithm in BTDownload.getProgress() doesn't make sense at the moment for merkle torrents.
ct.set_creator("FrostWire " + Constants.FROSTWIRE_VERSION_STRING + " build " + Constants.FROSTWIRE_BUILD);
ct.set_priv(false);
final error_code ec = new error_code();
libtorrent.set_piece_hashes_ex(ct, saveDir.getAbsolutePath(), new set_piece_hashes_listener(), ec);
final byte[] torrent_bytes = new Entry(ct.generate()).bencode();
final TorrentInfo tinfo = TorrentInfo.bdecode(torrent_bytes);
// so the TorrentHandle object is created and added to the libtorrent session.
BTEngine.getInstance().download(tinfo, saveDir, new boolean[] { true }, null, TransferManager.instance().isDeleteStartedTorrentEnabled());
} catch (Throwable e) {
// TODO: better handling of this error
LOG.error("Error creating torrent for seed", e);
}
}
use of com.frostwire.jlibtorrent.TorrentInfo in project frostwire by frostwire.
the class BTEngine method download.
public void download(TorrentCrawledSearchResult sr, File saveDir, boolean dontSaveTorrentFile) {
if (swig() == null) {
return;
}
saveDir = setupSaveDir(saveDir);
if (saveDir == null) {
return;
}
TorrentInfo ti = sr.getTorrentInfo();
int fileIndex = sr.getFileIndex();
TorrentHandle th = find(ti.infoHash());
boolean exists = th != null;
if (th != null) {
Priority[] priorities = th.filePriorities();
if (priorities[fileIndex] == Priority.IGNORE) {
priorities[fileIndex] = Priority.NORMAL;
download(ti, saveDir, priorities, null, null);
}
} else {
Priority[] priorities = Priority.array(Priority.IGNORE, ti.numFiles());
priorities[fileIndex] = Priority.NORMAL;
download(ti, saveDir, priorities, null, null);
}
if (!exists) {
saveResumeTorrent(ti);
if (!dontSaveTorrentFile) {
saveTorrent(ti);
}
}
}
use of com.frostwire.jlibtorrent.TorrentInfo in project frostwire by frostwire.
the class BTEngine method download.
public void download(File torrent, File saveDir, boolean[] selection) {
if (swig() == null) {
return;
}
saveDir = setupSaveDir(saveDir);
if (saveDir == null) {
return;
}
TorrentInfo ti = new TorrentInfo(torrent);
if (selection == null) {
selection = new boolean[ti.numFiles()];
Arrays.fill(selection, true);
}
Priority[] priorities = null;
TorrentHandle th = find(ti.infoHash());
boolean exists = th != null;
if (selection != null) {
if (th != null) {
priorities = th.filePriorities();
} else {
priorities = Priority.array(Priority.IGNORE, ti.numFiles());
}
boolean changed = false;
for (int i = 0; i < selection.length; i++) {
if (selection[i]) {
if (priorities[i] == Priority.IGNORE) {
priorities[i] = Priority.NORMAL;
changed = true;
}
}
}
if (!changed) {
// nothing to do
return;
}
}
download(ti, saveDir, priorities, null, null);
if (!exists) {
saveResumeTorrent(ti);
}
}
use of com.frostwire.jlibtorrent.TorrentInfo in project frostwire by frostwire.
the class BTDownload method getIncompleteFiles.
public Set<File> getIncompleteFiles() {
Set<File> s = new HashSet<>();
try {
if (!th.isValid()) {
return s;
}
long[] progress = th.fileProgress(TorrentHandle.FileProgressFlags.PIECE_GRANULARITY);
TorrentInfo ti = th.torrentFile();
if (ti == null) {
// still downloading the info (from magnet)
return s;
}
FileStorage fs = ti.files();
String prefix = savePath.getAbsolutePath();
long createdTime = created.getTime();
for (int i = 0; i < progress.length; i++) {
String fePath = fs.filePath(i);
long feSize = fs.fileSize(i);
if (progress[i] < feSize) {
// lets see if indeed the file is incomplete
File f = new File(prefix, fePath);
if (!f.exists()) {
// nothing to do here
continue;
}
if (f.lastModified() >= createdTime) {
// we have a file modified (supposedly) by this transfer
s.add(f);
}
}
}
} catch (Throwable e) {
LOG.error("Error calculating the incomplete files set", e);
}
return s;
}
use of com.frostwire.jlibtorrent.TorrentInfo in project frostwire by frostwire.
the class PerformersHelper method crawlTorrent.
/**
* This method is only public allow reuse inside the package search, consider it a private API
*/
public static List<? extends SearchResult> crawlTorrent(SearchPerformer performer, TorrentCrawlableSearchResult sr, byte[] data, boolean detectAlbums) {
List<TorrentCrawledSearchResult> list = new LinkedList<>();
if (data == null) {
return list;
}
TorrentInfo ti;
try {
ti = TorrentInfo.bdecode(data);
} catch (Throwable t) {
// LOG.error("Can't bdecode:\n" + new String(data) + "\n\n");
throw t;
}
int numFiles = ti.numFiles();
FileStorage fs = ti.files();
for (int i = 0; !performer.isStopped() && i < numFiles; i++) {
// TODO: Check for the hidden attribute
if (fs.padFileAt(i)) {
continue;
}
list.add(new TorrentCrawledSearchResult(sr, ti, i, fs.filePath(i), fs.fileSize(i)));
}
if (detectAlbums) {
List<SearchResult> temp = new LinkedList<>();
temp.addAll(list);
temp.addAll(new AlbumCluster().detect(sr, list));
return temp;
} else {
return list;
}
}
Aggregations