use of com.frostwire.jlibtorrent.FileStorage 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.FileStorage 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;
}
}
use of com.frostwire.jlibtorrent.FileStorage in project frostwire by frostwire.
the class TorrentFetcherDownload method calculateSelection.
private boolean[] calculateSelection(TorrentInfo ti, String path) {
boolean[] selection = new boolean[ti.numFiles()];
FileStorage fs = ti.files();
for (int i = 0; i < selection.length; i++) {
String filePath = fs.filePath(i);
if (path.endsWith(filePath) || filePath.endsWith(path)) {
selection[i] = true;
}
}
return selection;
}
use of com.frostwire.jlibtorrent.FileStorage in project frostwire by frostwire.
the class BTDownload method getItems.
@Override
public List<TransferItem> getItems() {
ArrayList<TransferItem> items = new ArrayList<>();
if (th.isValid()) {
TorrentInfo ti = th.torrentFile();
if (ti != null && ti.isValid()) {
FileStorage fs = ti.files();
int numFiles = ti.numFiles();
for (int i = 0; i < numFiles; i++) {
BTDownloadItem item = new BTDownloadItem(th, i, fs.filePath(i), fs.fileSize(i), piecesTracker);
items.add(item);
}
if (piecesTracker != null) {
int numPieces = ti.numPieces();
// perform piece complete check
for (int i = 0; i < numPieces; i++) {
if (th.havePiece(i)) {
piecesTracker.setComplete(i, true);
}
}
}
}
}
return items;
}
use of com.frostwire.jlibtorrent.FileStorage in project frostwire by frostwire.
the class BTDownload method getPredominantFileExtension.
@Override
public String getPredominantFileExtension() {
if (predominantFileExtension == null && th != null) {
TorrentInfo torrentInfo = th.torrentFile();
if (torrentInfo != null) {
FileStorage files = torrentInfo.files();
Map<String, Long> extensionByteSums = new HashMap<>();
int numFiles = files.numFiles();
if (files.paths() != null) {
for (int i = 0; i < numFiles; i++) {
String path = files.filePath(i);
String extension = FilenameUtils.getExtension(path);
if ("".equals(extension)) {
// skip folders
continue;
}
if (extensionByteSums.containsKey(extension)) {
Long bytes = extensionByteSums.get(extension);
extensionByteSums.put(extension, bytes + files.fileSize(i));
} else {
extensionByteSums.put(extension, files.fileSize(i));
}
}
String extensionCandidate = null;
Set<String> exts = extensionByteSums.keySet();
for (String ext : exts) {
if (extensionCandidate == null) {
extensionCandidate = ext;
} else {
if (extensionByteSums.get(ext) > extensionByteSums.get(extensionCandidate)) {
extensionCandidate = ext;
}
}
}
predominantFileExtension = extensionCandidate;
}
}
}
return predominantFileExtension;
}
Aggregations