Search in sources :

Example 1 with DownloadResult

use of org.nzbhydra.downloading.DownloadResult in project nzbhydra2 by theotherp.

the class TorrentFileHandler method saveOrSendTorrents.

public SaveOrSendTorrentsResponse saveOrSendTorrents(Set<Long> guids) {
    List<Long> successfulIds = new ArrayList<>();
    List<Long> failedIds = new ArrayList<>();
    for (Long guid : guids) {
        DownloadResult result;
        boolean successful = false;
        try {
            result = getTorrentByGuid(guid, FileDownloadAccessType.PROXY, SearchRequest.SearchSource.INTERNAL);
            if (!result.isSuccessful()) {
                successful = false;
                continue;
            }
            if (result.getContent() != null) {
                successful = saveToBlackHole(result);
            } else {
                successful = sendMagnet(result);
            }
        } catch (InvalidSearchResultIdException e) {
            logger.error("Unable to find result with ID {}", guid);
        }
        if (successful) {
            successfulIds.add(guid);
        } else {
            failedIds.add(guid);
        }
    }
    String message = failedIds.isEmpty() ? "All magnet URLs successfully sent" : failedIds.size() + " magnet links could not be sent";
    return new SaveOrSendTorrentsResponse(true, message, successfulIds, failedIds);
}
Also used : ArrayList(java.util.ArrayList) DownloadResult(org.nzbhydra.downloading.DownloadResult) InvalidSearchResultIdException(org.nzbhydra.downloading.InvalidSearchResultIdException)

Aggregations

ArrayList (java.util.ArrayList)1 DownloadResult (org.nzbhydra.downloading.DownloadResult)1 InvalidSearchResultIdException (org.nzbhydra.downloading.InvalidSearchResultIdException)1