Search in sources :

Example 1 with TorrentCrawlableSearchResult

use of com.frostwire.search.torrent.TorrentCrawlableSearchResult 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;
    }
}
Also used : TorrentCrawledSearchResult(com.frostwire.search.torrent.TorrentCrawledSearchResult) FileStorage(com.frostwire.jlibtorrent.FileStorage) TorrentCrawlableSearchResult(com.frostwire.search.torrent.TorrentCrawlableSearchResult) TorrentCrawledSearchResult(com.frostwire.search.torrent.TorrentCrawledSearchResult) TorrentInfo(com.frostwire.jlibtorrent.TorrentInfo) LinkedList(java.util.LinkedList)

Aggregations

FileStorage (com.frostwire.jlibtorrent.FileStorage)1 TorrentInfo (com.frostwire.jlibtorrent.TorrentInfo)1 TorrentCrawlableSearchResult (com.frostwire.search.torrent.TorrentCrawlableSearchResult)1 TorrentCrawledSearchResult (com.frostwire.search.torrent.TorrentCrawledSearchResult)1 LinkedList (java.util.LinkedList)1