public void DownloadReport(RemoteEpisode remoteEpisode) { //Ensure.That(remoteEpisode.Series, () => remoteEpisode.Series).IsNotNull(); //Ensure.That(remoteEpisode.Episodes, () => remoteEpisode.Episodes).HasItems(); TODO update this shit var downloadTitle = remoteEpisode.Release.Title; var downloadClient = _downloadClientProvider.GetDownloadClient(remoteEpisode.Release.DownloadProtocol); if (downloadClient == null) { _logger.Warn("{0} Download client isn't configured yet.", remoteEpisode.Release.DownloadProtocol); return; } // Limit grabs to 2 per second. if (remoteEpisode.Release.DownloadUrl.IsNotNullOrWhiteSpace() && !remoteEpisode.Release.DownloadUrl.StartsWith("magnet:")) { var url = new HttpUri(remoteEpisode.Release.DownloadUrl); _rateLimitService.WaitAndPulse(url.Host, TimeSpan.FromSeconds(2)); } string downloadClientId; try { downloadClientId = downloadClient.Download(remoteEpisode); _indexerStatusService.RecordSuccess(remoteEpisode.Release.IndexerId); } catch (ReleaseDownloadException ex) { var http429 = ex.InnerException as TooManyRequestsException; if (http429 != null) { _indexerStatusService.RecordFailure(remoteEpisode.Release.IndexerId, http429.RetryAfter); } else { _indexerStatusService.RecordFailure(remoteEpisode.Release.IndexerId); } throw; } var episodeGrabbedEvent = new EpisodeGrabbedEvent(remoteEpisode); episodeGrabbedEvent.DownloadClient = downloadClient.GetType().Name; if (!string.IsNullOrWhiteSpace(downloadClientId)) { episodeGrabbedEvent.DownloadId = downloadClientId; } _logger.ProgressInfo("Report sent to {0}. {1}", downloadClient.Definition.Name, downloadTitle); _eventAggregator.PublishEvent(episodeGrabbedEvent); }
public void DownloadReport(RemoteEpisode remoteEpisode) { Ensure.That(remoteEpisode.Series, () => remoteEpisode.Series).IsNotNull(); Ensure.That(remoteEpisode.Episodes, () => remoteEpisode.Episodes).HasItems(); var downloadTitle = remoteEpisode.Release.Title; var downloadClient = _downloadClientProvider.GetDownloadClient(remoteEpisode.Release.DownloadProtocol); if (downloadClient == null) { _logger.Warn("{0} Download client isn't configured yet.", remoteEpisode.Release.DownloadProtocol); return; } // Limit grabs to 2 per second. if (remoteEpisode.Release.DownloadUrl.IsNotNullOrWhiteSpace() && !remoteEpisode.Release.DownloadUrl.StartsWith("magnet:")) { var uri = new Uri(remoteEpisode.Release.DownloadUrl); _rateLimitService.WaitAndPulse(uri.Host, TimeSpan.FromSeconds(2)); } var downloadClientId = downloadClient.Download(remoteEpisode); var episodeGrabbedEvent = new EpisodeGrabbedEvent(remoteEpisode); episodeGrabbedEvent.DownloadClient = downloadClient.GetType().Name; if (!String.IsNullOrWhiteSpace(downloadClientId)) { episodeGrabbedEvent.DownloadId = downloadClientId; } _logger.ProgressInfo("Report sent to {0}. {1}", downloadClient.Definition.Name, downloadTitle); _eventAggregator.PublishEvent(episodeGrabbedEvent); }
public void DownloadReport(RemoteEpisode remoteEpisode) { Ensure.That(remoteEpisode.Series, () => remoteEpisode.Series).IsNotNull(); Ensure.That(remoteEpisode.Episodes, () => remoteEpisode.Episodes).HasItems(); var downloadTitle = remoteEpisode.Release.Title; var downloadClient = _downloadClientProvider.GetDownloadClient(remoteEpisode.Release.DownloadProtocol); if (downloadClient == null) { _logger.Warn("{0} Download client isn't configured yet.", remoteEpisode.Release.DownloadProtocol); return; } var downloadClientId = downloadClient.Download(remoteEpisode); var episodeGrabbedEvent = new EpisodeGrabbedEvent(remoteEpisode); episodeGrabbedEvent.DownloadClient = downloadClient.GetType().Name; if (!String.IsNullOrWhiteSpace(downloadClientId)) { episodeGrabbedEvent.DownloadId = downloadClientId; } _logger.ProgressInfo("Report sent to download client. {0}", downloadTitle); _eventAggregator.PublishEvent(episodeGrabbedEvent); }
public List <Queue> GetQueue() { var downloadClient = _downloadClientProvider.GetDownloadClient(); var queueItems = downloadClient.GetQueue(); return(MapQueue(queueItems)); }
private IDownloadClient GetDownloadClient() { var downloadClient = _downloadClientProvider.GetDownloadClient(); if (downloadClient == null) { _logger.Debug("No download client is configured"); } return(downloadClient); }
public bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria) { var downloadClient = _downloadClientProvider.GetDownloadClient(); if (!downloadClient.IsConfigured) { _logger.Warn("Download client {0} isn't configured yet.", downloadClient.GetType().Name); return(true); } var queue = downloadClient.GetQueue().Select(q => q.RemoteEpisode); return(!IsInQueue(subject, queue)); }
public bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria) { var downloadClient = _downloadClientProvider.GetDownloadClient(); if (!downloadClient.IsConfigured) { _logger.Warn("Download client {0} isn't configured yet.", downloadClient.GetType().Name); return(true); } var queue = downloadClient.GetQueue().Select(queueItem => Parser.Parser.ParseTitle(queueItem.Title)).Where(episodeInfo => episodeInfo != null); return(!IsInQueue(subject, queue)); }
public void DownloadReport(RemoteEpisode remoteEpisode) { Ensure.That(() => remoteEpisode.Series).IsNotNull(); Ensure.That(() => remoteEpisode.Episodes).HasItems(); var downloadTitle = remoteEpisode.Release.Title; var downloadClient = _downloadClientProvider.GetDownloadClient(); if (!downloadClient.IsConfigured) { _logger.Warn("Download client {0} isn't configured yet.", downloadClient.GetType().Name); return; } downloadClient.DownloadNzb(remoteEpisode); _logger.ProgressInfo("Report sent to download client. {0}", downloadTitle); _eventAggregator.PublishEvent(new EpisodeGrabbedEvent(remoteEpisode)); }
public virtual bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria) { if (searchCriteria != null) { _logger.Debug("Skipping history check during search"); return(true); } var downloadClient = _downloadClientProvider.GetDownloadClient(); if (downloadClient != null && downloadClient.GetType() == typeof(Sabnzbd)) { _logger.Debug("Performing history status check on report"); foreach (var episode in subject.Episodes) { _logger.Debug("Checking current status of episode [{0}] in history", episode.Id); var mostRecent = _historyService.MostRecentForEpisode(episode.Id); if (mostRecent != null && mostRecent.EventType == HistoryEventType.Grabbed) { _logger.Debug("Latest history item is downloading, rejecting."); return(false); } } return(true); } foreach (var episode in subject.Episodes) { var bestQualityInHistory = _historyService.GetBestQualityInHistory(subject.Series.QualityProfile, episode.Id); if (bestQualityInHistory != null) { _logger.Debug("Comparing history quality with report. History is {0}", bestQualityInHistory); if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.QualityProfile, bestQualityInHistory, subject.ParsedEpisodeInfo.Quality)) { return(false); } } } return(true); }
public bool IsSatisfiedBy(RemoteEpisode subject, SearchCriteriaBase searchCriteria) { var downloadClient = _downloadClientProvider.GetDownloadClient(); if (downloadClient == null) { _logger.Warn("Download client isn't configured yet."); return(true); } var queue = downloadClient.GetQueue().Select(q => q.RemoteEpisode); if (IsInQueue(subject, queue)) { _logger.Debug("Already in queue, rejecting."); return(false); } return(true); }
public override HealthCheck Check() { var downloadClient = _downloadClientProvider.GetDownloadClient(); if (downloadClient == null) { return(new HealthCheck(GetType(), HealthCheckResult.Warning, "No download client is available")); } try { downloadClient.GetQueue(); } catch (Exception) { return(new HealthCheck(GetType(), HealthCheckResult.Error, "Unable to communicate with download client")); } return(new HealthCheck(GetType())); }
public List <Queue> GetQueue() { var downloadClient = _downloadClientProvider.GetDownloadClient(); if (downloadClient == null) { _logger.Debug("Download client is not configured."); return(new List <Queue>()); } try { var queueItems = downloadClient.GetQueue(); return(MapQueue(queueItems)); } catch (Exception ex) { _logger.Error("Error getting queue from download client: " + downloadClient.ToString(), ex); return(new List <Queue>()); } }
public async Task SendReportToClient(ReleaseInfo release, string source, string host, bool redirect) { var downloadTitle = release.Title; var downloadClient = _downloadClientProvider.GetDownloadClient(release.DownloadProtocol); if (downloadClient == null) { throw new DownloadClientUnavailableException($"{release.DownloadProtocol} Download client isn't configured yet"); } // Get the seed configuration for this release. // remoteMovie.SeedConfiguration = _seedConfigProvider.GetSeedConfiguration(remoteMovie); // Limit grabs to 2 per second. if (release.DownloadUrl.IsNotNullOrWhiteSpace() && !release.DownloadUrl.StartsWith("magnet:")) { var url = new HttpUri(release.DownloadUrl); _rateLimitService.WaitAndPulse(url.Host, TimeSpan.FromSeconds(2)); } var indexer = _indexerFactory.GetInstance(_indexerFactory.Get(release.IndexerId)); string downloadClientId; try { downloadClientId = await downloadClient.Download(release, redirect, indexer); _downloadClientStatusService.RecordSuccess(downloadClient.Definition.Id); _indexerStatusService.RecordSuccess(release.IndexerId); } catch (ReleaseUnavailableException) { _logger.Trace("Release {0} no longer available on indexer.", release); _eventAggregator.PublishEvent(new IndexerDownloadEvent(release.IndexerId, false, source, host, release.Title, release.DownloadUrl, redirect)); throw; } catch (DownloadClientRejectedReleaseException) { _logger.Trace("Release {0} rejected by download client, possible duplicate.", release); _eventAggregator.PublishEvent(new IndexerDownloadEvent(release.IndexerId, false, source, host, release.Title, release.DownloadUrl, redirect)); throw; } catch (ReleaseDownloadException ex) { var http429 = ex.InnerException as TooManyRequestsException; if (http429 != null) { _indexerStatusService.RecordFailure(release.IndexerId, http429.RetryAfter); } else { _indexerStatusService.RecordFailure(release.IndexerId); } _eventAggregator.PublishEvent(new IndexerDownloadEvent(release.IndexerId, false, source, host, release.Title, release.DownloadUrl, redirect)); throw; } _logger.ProgressInfo("Report sent to {0}. {1}", downloadClient.Definition.Name, downloadTitle); _eventAggregator.PublishEvent(new IndexerDownloadEvent(release.IndexerId, true, source, host, release.Title, release.DownloadUrl, redirect)); }
public void DownloadReport(RemoteAlbum remoteAlbum) { Ensure.That(remoteAlbum.Artist, () => remoteAlbum.Artist).IsNotNull(); Ensure.That(remoteAlbum.Albums, () => remoteAlbum.Albums).HasItems(); var downloadTitle = remoteAlbum.Release.Title; var downloadClient = _downloadClientProvider.GetDownloadClient(remoteAlbum.Release.DownloadProtocol); if (downloadClient == null) { throw new DownloadClientUnavailableException($"{remoteAlbum.Release.DownloadProtocol} Download client isn't configured yet"); } // Get the seed configuration for this release. remoteAlbum.SeedConfiguration = _seedConfigProvider.GetSeedConfiguration(remoteAlbum); // Limit grabs to 2 per second. if (remoteAlbum.Release.DownloadUrl.IsNotNullOrWhiteSpace() && !remoteAlbum.Release.DownloadUrl.StartsWith("magnet:")) { var url = new HttpUri(remoteAlbum.Release.DownloadUrl); _rateLimitService.WaitAndPulse(url.Host, TimeSpan.FromSeconds(2)); } string downloadClientId; try { downloadClientId = downloadClient.Download(remoteAlbum); _downloadClientStatusService.RecordSuccess(downloadClient.Definition.Id); _indexerStatusService.RecordSuccess(remoteAlbum.Release.IndexerId); } catch (ReleaseUnavailableException) { _logger.Trace("Release {0} no longer available on indexer.", remoteAlbum); throw; } catch (DownloadClientRejectedReleaseException) { _logger.Trace("Release {0} rejected by download client, possible duplicate.", remoteAlbum); throw; } catch (ReleaseDownloadException ex) { var http429 = ex.InnerException as TooManyRequestsException; if (http429 != null) { _indexerStatusService.RecordFailure(remoteAlbum.Release.IndexerId, http429.RetryAfter); } else { _indexerStatusService.RecordFailure(remoteAlbum.Release.IndexerId); } throw; } var albumGrabbedEvent = new AlbumGrabbedEvent(remoteAlbum); albumGrabbedEvent.DownloadClient = downloadClient.Name; if (!string.IsNullOrWhiteSpace(downloadClientId)) { albumGrabbedEvent.DownloadId = downloadClientId; } _logger.ProgressInfo("Report sent to {0}. {1}", downloadClient.Definition.Name, downloadTitle); _eventAggregator.PublishEvent(albumGrabbedEvent); }