Search in sources :

Example 1 with InvalidSearchResultIdException

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

the class TorrentFileHandler method getTorrentByGuid.

public DownloadResult getTorrentByGuid(long guid, FileDownloadAccessType accessType, SearchRequest.SearchSource accessSource) throws InvalidSearchResultIdException {
    // Get result. if link contains magnet: return redirect to magnet URI. otherwise return file
    SearchResultEntity result = searchResultRepository.findOne(guid);
    if (result == null) {
        logger.error("Download request with invalid/outdated GUID {}", guid);
        throw new InvalidSearchResultIdException(guid, accessSource == SearchRequest.SearchSource.INTERNAL);
    }
    logger.info("Download request for \"{}\" from indexer {}", result.getTitle(), result.getIndexer().getName());
    if (result.getLink().contains("magnet:") || accessType == FileDownloadAccessType.REDIRECT) {
        return fileHandler.handleRedirect(accessSource, result);
    } else {
        return fileHandler.handleContentDownload(accessSource, result, "torrent");
    }
}
Also used : InvalidSearchResultIdException(org.nzbhydra.downloading.InvalidSearchResultIdException) SearchResultEntity(org.nzbhydra.searching.SearchResultEntity)

Example 2 with InvalidSearchResultIdException

use of org.nzbhydra.downloading.InvalidSearchResultIdException 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

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