private object Grab(int id) { var pendingRelease = _pendingReleaseService.FindPendingQueueItem(id); if (pendingRelease == null) { throw new NotFoundException(); } _downloadService.DownloadReport(pendingRelease.RemoteAlbum); return(new object()); }
public object Grab(int id) { var pendingRelease = _pendingReleaseService.FindPendingQueueItem(id); if (pendingRelease == null) { throw new NotFoundException(); } _downloadService.DownloadReport(pendingRelease.RemoteBook); return(new { }); }
public List <DownloadDecision> DownloadApproved(List <DownloadDecision> decisions) { var qualifiedReports = GetQualifiedReports(decisions); var downloadedReports = new List <DownloadDecision>(); foreach (var report in qualifiedReports) { var remoteEpisode = report.RemoteEpisode; try { if (downloadedReports.SelectMany(r => r.RemoteEpisode.Episodes) .Select(e => e.Id) .ToList() .Intersect(remoteEpisode.Episodes.Select(e => e.Id)) .Any()) { continue; } _downloadService.DownloadReport(remoteEpisode); downloadedReports.Add(report); } catch (Exception e) { _logger.WarnException("Couldn't add report to download queue. " + remoteEpisode, e); } } return(downloadedReports); }
private Response DownloadRelease(ReleaseResource release) { var remoteEpisode = _parsingService.Map(release.InjectTo <ParsedEpisodeInfo>(), 0); remoteEpisode.Release = release.InjectTo <ReleaseInfo>(); _downloadService.DownloadReport(remoteEpisode); return(release.AsResponse()); }
public ProcessedDecisions ProcessDecisions(List <DownloadDecision> decisions) { var qualifiedReports = GetQualifiedReports(decisions); var prioritizedDecisions = _prioritizeDownloadDecision.PrioritizeDecisions(qualifiedReports); var grabbed = new List <DownloadDecision>(); var pending = new List <DownloadDecision>(); foreach (var report in prioritizedDecisions) { var remoteEpisode = report.RemoteEpisode; var episodeIds = remoteEpisode.Episodes.Select(e => e.Id).ToList(); //Skip if already grabbed if (grabbed.SelectMany(r => r.RemoteEpisode.Episodes) .Select(e => e.Id) .ToList() .Intersect(episodeIds) .Any()) { continue; } if (report.TemporarilyRejected) { _pendingReleaseService.Add(report); pending.Add(report); continue; } if (pending.SelectMany(r => r.RemoteEpisode.Episodes) .Select(e => e.Id) .ToList() .Intersect(episodeIds) .Any()) { continue; } try { _downloadService.DownloadReport(remoteEpisode); grabbed.Add(report); } catch (Exception e) { //TODO: support for store & forward //We'll need to differentiate between a download client error and an indexer error _logger.Warn(e, "Couldn't add report to download queue. " + remoteEpisode); } } return(new ProcessedDecisions(grabbed, pending, decisions.Where(d => d.Rejected).ToList())); }
private Response DownloadRelease(ReleaseResource release) { var remoteEpisode = _remoteEpisodeCache.Find(release.Guid); if (remoteEpisode == null) { _logger.Debug("Couldn't find requested release in cache, cache timeout probably expired."); var remoteMovie = _remoteMovieCache.Find(release.Guid); if (remoteMovie == null) { return(new NotFoundResponse()); } try { _downloadService.DownloadReport(remoteMovie, false); } catch (ReleaseDownloadException ex) { _logger.Error(ex, ex.Message); throw new NzbDroneClientException(HttpStatusCode.Conflict, "Getting release from indexer failed"); } return(release.AsResponse()); } try { _downloadService.DownloadReport(remoteEpisode); } catch (ReleaseDownloadException ex) { _logger.Error(ex, ex.Message); throw new NzbDroneClientException(HttpStatusCode.Conflict, "Getting release from indexer failed"); } return(release.AsResponse()); }
private object Grab() { var resource = Request.Body.FromJson <QueueResource>(); var pendingRelease = _pendingReleaseService.FindPendingQueueItem(resource.Id); if (pendingRelease == null) { throw new NotFoundException(); } _downloadService.DownloadReport(pendingRelease.RemoteMovie); return(resource); }
private object DownloadRelease(ReleaseResource release) { var remoteBook = _remoteBookCache.Find(GetCacheKey(release)); if (remoteBook == null) { _logger.Debug("Couldn't find requested release in cache, cache timeout probably expired."); throw new NzbDroneClientException(HttpStatusCode.NotFound, "Couldn't find requested release in cache, try searching again"); } try { _downloadService.DownloadReport(remoteBook); } catch (ReleaseDownloadException ex) { _logger.Error(ex, "Getting release from indexer failed"); throw new NzbDroneClientException(HttpStatusCode.Conflict, "Getting release from indexer failed"); } return(release); }
public object DownloadRelease(ReleaseResource release) { var remoteMovie = _remoteMovieCache.Find(GetCacheKey(release)); if (remoteMovie == null) { _logger.Debug("Couldn't find requested release in cache, cache timeout probably expired."); throw new NzbDroneClientException(HttpStatusCode.NotFound, "Couldn't find requested release in cache, try searching again"); } try { if (remoteMovie.Movie == null) { if (release.MovieId.HasValue) { var movie = _movieService.GetMovie(release.MovieId.Value); remoteMovie.Movie = movie; } else { throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to find matching movie"); } } _downloadService.DownloadReport(remoteMovie); } catch (ReleaseDownloadException ex) { _logger.Error(ex, ex.Message); throw new NzbDroneClientException(HttpStatusCode.Conflict, "Getting release from indexer failed"); } return(release); }
private object DownloadRelease(ReleaseResource release) { var remoteEpisode = _remoteEpisodeCache.Find(GetCacheKey(release)); if (remoteEpisode == null) { _logger.Debug("Couldn't find requested release in cache, cache timeout probably expired."); throw new NzbDroneClientException(HttpStatusCode.NotFound, "Couldn't find requested release in cache, try searching again"); } try { if (remoteEpisode.Series == null) { if (release.EpisodeId.HasValue) { var episode = _episodeService.GetEpisode(release.EpisodeId.Value); remoteEpisode.Series = _seriesService.GetSeries(episode.SeriesId); remoteEpisode.Episodes = new List <Episode> { episode }; } else if (release.SeriesId.HasValue) { var series = _seriesService.GetSeries(release.SeriesId.Value); var episodes = _parsingService.GetEpisodes(remoteEpisode.ParsedEpisodeInfo, series, true); if (episodes.Empty()) { throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to parse episodes in the release"); } remoteEpisode.Series = series; remoteEpisode.Episodes = episodes; } else { throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to find matching series and episodes"); } } else if (remoteEpisode.Episodes.Empty()) { var episodes = _parsingService.GetEpisodes(remoteEpisode.ParsedEpisodeInfo, remoteEpisode.Series, true); if (episodes.Empty() && release.EpisodeId.HasValue) { var episode = _episodeService.GetEpisode(release.EpisodeId.Value); episodes = new List <Episode> { episode }; } remoteEpisode.Episodes = episodes; } if (remoteEpisode.Episodes.Empty()) { throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to parse episodes in the release"); } _downloadService.DownloadReport(remoteEpisode); } catch (ReleaseDownloadException ex) { _logger.Error(ex, ex.Message); throw new NzbDroneClientException(HttpStatusCode.Conflict, "Getting release from indexer failed"); } return(release); }
public ProcessedDecisions ProcessDecisions(List <DownloadDecision> decisions) { var qualifiedReports = GetQualifiedReports(decisions); var prioritizedDecisions = _prioritizeDownloadDecision.PrioritizeDecisions(qualifiedReports); var grabbed = new List <DownloadDecision>(); var pending = new List <DownloadDecision>(); var failed = new List <DownloadDecision>(); var rejected = decisions.Where(d => d.Rejected).ToList(); var usenetFailed = false; var torrentFailed = false; foreach (var report in prioritizedDecisions) { var remoteEpisode = report.RemoteEpisode; var downloadProtocol = report.RemoteEpisode.Release.DownloadProtocol; // Skip if already grabbed if (IsEpisodeProcessed(grabbed, report)) { continue; } if (report.TemporarilyRejected) { _pendingReleaseService.Add(report, PendingReleaseReason.Delay); pending.Add(report); continue; } if (downloadProtocol == DownloadProtocol.Usenet && usenetFailed || downloadProtocol == DownloadProtocol.Torrent && torrentFailed) { failed.Add(report); continue; } try { _downloadService.DownloadReport(remoteEpisode); grabbed.Add(report); } catch (ReleaseUnavailableException) { _logger.Warn("Failed to download release from indexer, no longer available. " + remoteEpisode); rejected.Add(report); } catch (Exception ex) { if (ex is DownloadClientUnavailableException || ex is DownloadClientAuthenticationException) { _logger.Debug(ex, "Failed to send release to download client, storing until later. " + remoteEpisode); failed.Add(report); if (downloadProtocol == DownloadProtocol.Usenet) { usenetFailed = true; } else if (downloadProtocol == DownloadProtocol.Torrent) { torrentFailed = true; } } else { _logger.Warn(ex, "Couldn't add report to download queue. " + remoteEpisode); } } } pending.AddRange(ProcessFailedGrabs(grabbed, failed)); return(new ProcessedDecisions(grabbed, pending, rejected)); }
public ProcessedDecisions ProcessDecisions(List <DownloadDecision> decisions) { var qualifiedReports = GetQualifiedReports(decisions); var prioritizedDecisions = _prioritizeDownloadDecision.PrioritizeDecisionsForMovies(qualifiedReports); var grabbed = new List <DownloadDecision>(); var pending = new List <DownloadDecision>(); foreach (var report in prioritizedDecisions) { var remoteMovie = report.RemoteMovie; if (remoteMovie == null || remoteMovie.Movie == null) { continue; } List <int> movieIds = new List <int> { remoteMovie.Movie.Id }; //Skip if already grabbed if (grabbed.Select(r => r.RemoteMovie.Movie) .Select(e => e.Id) .ToList() .Intersect(movieIds) .Any()) { continue; } if (report.TemporarilyRejected) { _pendingReleaseService.Add(report); pending.Add(report); continue; } if (report.Rejections.Any()) { _logger.Debug("Rejecting release {0} because {1}", report.ToString(), report.Rejections.First().Reason); continue; } if (pending.Select(r => r.RemoteMovie.Movie) .Select(e => e.Id) .ToList() .Intersect(movieIds) .Any()) { continue; } try { _downloadService.DownloadReport(remoteMovie, false); grabbed.Add(report); } catch (Exception e) { //TODO: support for store & forward //We'll need to differentiate between a download client error and an indexer error _logger.Warn(e, "Couldn't add report to download queue. " + remoteMovie); } } return(new ProcessedDecisions(grabbed, pending, decisions.Where(d => d.Rejected).ToList())); }
public ProcessedDecisions ProcessDecisions(List <DownloadDecision> decisions) { var qualifiedReports = GetQualifiedReports(decisions); var prioritizedDecisions = _prioritizeDownloadDecision.PrioritizeDecisions(qualifiedReports); var grabbed = new List <DownloadDecision>(); var pending = new List <DownloadDecision>(); //var failed = new List<DownloadDecision>(); var rejected = decisions.Where(d => d.Rejected).ToList(); var pendingAddQueue = new List <Tuple <DownloadDecision, PendingReleaseReason> >(); var usenetFailed = false; var torrentFailed = false; foreach (var report in prioritizedDecisions) { var remoteBook = report.RemoteBook; var downloadProtocol = report.RemoteBook.Release.DownloadProtocol; //Skip if already grabbed if (IsAlbumProcessed(grabbed, report)) { continue; } if (report.TemporarilyRejected) { PreparePending(pendingAddQueue, grabbed, pending, report, PendingReleaseReason.Delay); continue; } if ((downloadProtocol == DownloadProtocol.Usenet && usenetFailed) || (downloadProtocol == DownloadProtocol.Torrent && torrentFailed)) { PreparePending(pendingAddQueue, grabbed, pending, report, PendingReleaseReason.DownloadClientUnavailable); continue; } try { _logger.Trace("Grabbing from Indexer {0} at priority {1}.", remoteBook.Release.Indexer, remoteBook.Release.IndexerPriority); _downloadService.DownloadReport(remoteBook); grabbed.Add(report); } catch (ReleaseUnavailableException) { _logger.Warn("Failed to download release from indexer, no longer available. " + remoteBook); rejected.Add(report); } catch (Exception ex) { if (ex is DownloadClientUnavailableException || ex is DownloadClientAuthenticationException) { _logger.Debug(ex, "Failed to send release to download client, storing until later. " + remoteBook); PreparePending(pendingAddQueue, grabbed, pending, report, PendingReleaseReason.DownloadClientUnavailable); if (downloadProtocol == DownloadProtocol.Usenet) { usenetFailed = true; } else if (downloadProtocol == DownloadProtocol.Torrent) { torrentFailed = true; } } else { _logger.Warn(ex, "Couldn't add report to download queue. " + remoteBook); } } } if (pendingAddQueue.Any()) { _pendingReleaseService.AddMany(pendingAddQueue); } return(new ProcessedDecisions(grabbed, pending, rejected)); }
private object DownloadRelease(ReleaseResource release) { var remoteBook = _remoteBookCache.Find(GetCacheKey(release)); if (remoteBook == null) { _logger.Debug("Couldn't find requested release in cache, cache timeout probably expired."); throw new NzbDroneClientException(HttpStatusCode.NotFound, "Couldn't find requested release in cache, try searching again"); } try { if (remoteBook.Author == null) { if (release.BookId.HasValue) { var book = _bookService.GetBook(release.BookId.Value); remoteBook.Author = _authorService.GetAuthor(book.AuthorId); remoteBook.Books = new List <Book> { book }; } else if (release.AuthorId.HasValue) { var author = _authorService.GetAuthor(release.AuthorId.Value); var books = _parsingService.GetBooks(remoteBook.ParsedBookInfo, author); if (books.Empty()) { throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to parse books in the release"); } remoteBook.Author = author; remoteBook.Books = books; } else { throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to find matching author and books"); } } else if (remoteBook.Books.Empty()) { var books = _parsingService.GetBooks(remoteBook.ParsedBookInfo, remoteBook.Author); if (books.Empty() && release.BookId.HasValue) { var book = _bookService.GetBook(release.BookId.Value); books = new List <Book> { book }; } remoteBook.Books = books; } if (remoteBook.Books.Empty()) { throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to parse books in the release"); } _downloadService.DownloadReport(remoteBook); } catch (ReleaseDownloadException ex) { _logger.Error(ex, "Getting release from indexer failed"); throw new NzbDroneClientException(HttpStatusCode.Conflict, "Getting release from indexer failed"); } return(release); }
private object DownloadRelease(ReleaseResource release) { var remoteAlbum = _remoteAlbumCache.Find(GetCacheKey(release)); if (remoteAlbum == null) { _logger.Debug("Couldn't find requested release in cache, cache timeout probably expired."); throw new NzbDroneClientException(HttpStatusCode.NotFound, "Couldn't find requested release in cache, try searching again"); } try { if (remoteAlbum.Artist == null) { if (release.AlbumId.HasValue) { var album = _albumService.GetAlbum(release.AlbumId.Value); remoteAlbum.Artist = _artistService.GetArtist(album.ArtistId); remoteAlbum.Albums = new List <Album> { album }; } else if (release.ArtistId.HasValue) { var artist = _artistService.GetArtist(release.ArtistId.Value); var albums = _parsingService.GetAlbums(remoteAlbum.ParsedAlbumInfo, artist); if (albums.Empty()) { throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to parse albums in the release"); } remoteAlbum.Artist = artist; remoteAlbum.Albums = albums; } else { throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to find matching artist and albums"); } } else if (remoteAlbum.Albums.Empty()) { var albums = _parsingService.GetAlbums(remoteAlbum.ParsedAlbumInfo, remoteAlbum.Artist); if (albums.Empty() && release.AlbumId.HasValue) { var album = _albumService.GetAlbum(release.AlbumId.Value); albums = new List <Album> { album }; } remoteAlbum.Albums = albums; } if (remoteAlbum.Albums.Empty()) { throw new NzbDroneClientException(HttpStatusCode.NotFound, "Unable to parse albums in the release"); } _downloadService.DownloadReport(remoteAlbum); } catch (ReleaseDownloadException ex) { _logger.Error(ex, ex.Message); throw new NzbDroneClientException(HttpStatusCode.Conflict, "Getting release from indexer failed"); } return(release); }