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); }
private string GetCacheKey(ReleaseResource resource) { return(string.Concat(resource.IndexerId, "_", resource.Guid)); }