public override SearchHistoryItem CheckReport(Series series, dynamic options, EpisodeParseResult episodeParseResult,
                                                                SearchHistoryItem item)
        {
            if(options.SeasonNumber != episodeParseResult.SeasonNumber)
            {
                logger.Trace("Season number does not match searched season number, skipping.");
                item.SearchError = ReportRejectionType.WrongSeason;

                return item;
            }

            return item;
        }
        public override SearchHistoryItem CheckReport(Series series, dynamic options, EpisodeParseResult episodeParseResult,
                                                                SearchHistoryItem item)
        {
            Episode episode = options.Episode;

            if (!episodeParseResult.AirDate.HasValue || episodeParseResult.AirDate.Value != episode.AirDate.Value)
            {
                logger.Trace("Episode AirDate does not match searched episode number, skipping.");
                item.SearchError = ReportRejectionType.WrongEpisode;

                return item;
            }

            return item;
        }
示例#3
0
        public override SearchHistoryItem CheckReport(Series series, dynamic options, EpisodeParseResult episodeParseResult,
                                                                SearchHistoryItem item)
        {
            if(series.UseSceneNumbering && options.Episode.SeasonNumber > 0 && options.Episode.EpisodeNumber > 0)
            {
                if (options.Episode.SceneSeasonNumber != episodeParseResult.SeasonNumber)
                {
                    logger.Trace("Season number does not match searched season number, skipping.");
                    item.SearchError = ReportRejectionType.WrongSeason;

                    return item;
                }

                if (!episodeParseResult.EpisodeNumbers.Contains(options.Episode.SceneEpisodeNumber))
                {
                    logger.Trace("Episode number does not match searched episode number, skipping.");
                    item.SearchError = ReportRejectionType.WrongEpisode;

                    return item;
                }

                return item;
            }

            if(options.Episode.SeasonNumber != episodeParseResult.SeasonNumber)
            {
                logger.Trace("Season number does not match searched season number, skipping.");
                item.SearchError = ReportRejectionType.WrongSeason;

                return item;
            }

            if (!episodeParseResult.EpisodeNumbers.Contains(options.Episode.EpisodeNumber))
            {
                logger.Trace("Episode number does not match searched episode number, skipping.");
                item.SearchError = ReportRejectionType.WrongEpisode;

                return item;
            }

            return item;
        }
        public void Setup()
        {
            _series = Builder<Series>
                    .CreateNew()
                    .Build();

            _episodes = Builder<Episode>
                    .CreateListOfSize(10)
                    .All()
                    .With(e => e.SeriesId = _series.SeriesId)
                    .With(e => e.Series = _series)
                    .Build()
                    .ToList();

            _episodeParseResult = Builder<EpisodeParseResult>
                    .CreateNew()
                    .With(p => p.SeasonNumber = 1)
                    .Build();

            _searchHistoryItem = new SearchHistoryItem();
        }
        public void Setup()
        {
            _series = Builder<Series>
                    .CreateNew()
                    .Build();

            _episode = Builder<Episode>
                    .CreateNew()
                    .With(e => e.SeriesId = _series.SeriesId)
                    .With(e => e.Series = _series)
                    .Build();

            _episodeParseResult = Builder<EpisodeParseResult>
                    .CreateNew()
                    .With(p => p.AirDate = _episode.AirDate)
                    .With(p => p.Episodes = new List<Episode> { _episode })
                    .With(p => p.Series = _series)
                    .Build();

            _searchHistoryItem = new SearchHistoryItem();
        }
示例#6
0
        public List<SearchHistoryItem> ProcessSearchResults(ProgressNotification notification, IEnumerable<EpisodeParseResult> reports, Series series, DateTime airDate)
        {
            var items = new List<SearchHistoryItem>();
            var skip = false;

            foreach (var episodeParseResult in reports.OrderByDescending(c => c.Quality))
            {
                try
                {
                    var item = new SearchHistoryItem
                    {
                        ReportTitle = episodeParseResult.OriginalString,
                        NzbUrl = episodeParseResult.NzbUrl,
                        Indexer = episodeParseResult.Indexer,
                        Quality = episodeParseResult.Quality.Quality,
                        Proper = episodeParseResult.Quality.Proper,
                        Size = episodeParseResult.Size,
                        Age = episodeParseResult.Age,
                        Language = episodeParseResult.Language
                    };

                    items.Add(item);

                    if (skip)
                    {
                        item.SearchError = ReportRejectionType.Skipped;
                        continue;
                    }

                    logger.Trace("Analysing report " + episodeParseResult);

                    //Get the matching series
                    episodeParseResult.Series = _seriesProvider.FindSeries(episodeParseResult.CleanTitle);

                    //If series is null or doesn't match the series we're looking for return
                    if (episodeParseResult.Series == null || episodeParseResult.Series.SeriesId != series.SeriesId)
                    {
                        item.SearchError = ReportRejectionType.WrongSeries;
                        continue;
                    }

                    //If parse result doesn't have an air date or it doesn't match passed in airdate, skip the report.
                    if (!episodeParseResult.AirDate.HasValue || episodeParseResult.AirDate.Value.Date != airDate.Date)
                    {
                        item.SearchError = ReportRejectionType.WrongEpisode;
                        continue;
                    }

                    episodeParseResult.Episodes = _episodeProvider.GetEpisodesByParseResult(episodeParseResult);

                    item.SearchError = _allowedDownloadSpecification.IsSatisfiedBy(episodeParseResult);
                    if (item.SearchError == ReportRejectionType.None)
                    {
                        logger.Debug("Found '{0}'. Adding to download queue.", episodeParseResult);
                        try
                        {
                            if (_downloadProvider.DownloadReport(episodeParseResult))
                            {
                                notification.CurrentMessage =
                                        String.Format("{0} - {1} {2} Added to download queue",
                                                      episodeParseResult.Series.Title, episodeParseResult.AirDate.Value.ToShortDateString(), episodeParseResult.Quality);

                                item.Success = true;
                                skip = true;
                            }
                            else
                            {
                                item.SearchError = ReportRejectionType.DownloadClientFailure;
                            }
                        }
                        catch (Exception e)
                        {
                            logger.ErrorException("Unable to add report to download queue." + episodeParseResult, e);
                            notification.CurrentMessage = String.Format("Unable to add report to download queue. {0}", episodeParseResult);
                            item.SearchError = ReportRejectionType.DownloadClientFailure;
                        }
                    }
                }
                catch (Exception e)
                {
                    logger.ErrorException("An error has occurred while processing parse result items from " + episodeParseResult, e);
                }
            }

            return items;
        }
示例#7
0
        public List<SearchHistoryItem> ProcessSearchResults(ProgressNotification notification, IEnumerable<EpisodeParseResult> reports, SearchHistory searchResult, Series series, int seasonNumber, int? episodeNumber = null)
        {
            var items = new List<SearchHistoryItem>();
            searchResult.Successes = new List<int>();

            foreach (var episodeParseResult in reports.OrderByDescending(c => c.Quality)
                                                        .ThenBy(c => c.EpisodeNumbers.MinOrDefault())
                                                        .ThenBy(c => c.Age))
            {
                try
                {
                    logger.Trace("Analysing report " + episodeParseResult);

                    var item = new SearchHistoryItem
                    {
                        ReportTitle = episodeParseResult.OriginalString,
                        NzbUrl = episodeParseResult.NzbUrl,
                        Indexer = episodeParseResult.Indexer,
                        Quality = episodeParseResult.Quality.Quality,
                        Proper = episodeParseResult.Quality.Proper,
                        Size = episodeParseResult.Size,
                        Age = episodeParseResult.Age,
                        Language = episodeParseResult.Language
                    };

                    items.Add(item);

                    //Get the matching series
                    episodeParseResult.Series = _seriesProvider.FindSeries(episodeParseResult.CleanTitle);

                    //If series is null or doesn't match the series we're looking for return
                    if (episodeParseResult.Series == null || episodeParseResult.Series.SeriesId != series.SeriesId)
                    {
                        logger.Trace("Unexpected series for search: {0}. Skipping.", episodeParseResult.CleanTitle);
                        item.SearchError = ReportRejectionType.WrongSeries;
                        continue;
                    }

                    //If SeasonNumber doesn't match or episode is not in the in the list in the parse result, skip the report.
                    if (episodeParseResult.SeasonNumber != seasonNumber)
                    {
                        logger.Trace("Season number does not match searched season number, skipping.");
                        item.SearchError = ReportRejectionType.WrongSeason;
                        continue;
                    }

                    //If the EpisodeNumber was passed in and it is not contained in the parseResult, skip the report.
                    if (episodeNumber.HasValue && !episodeParseResult.EpisodeNumbers.Contains(episodeNumber.Value))
                    {
                        logger.Trace("Searched episode number is not contained in post, skipping.");
                        item.SearchError = ReportRejectionType.WrongEpisode;
                        continue;
                    }

                    //Make sure we haven't already downloaded a report with this episodenumber, if we have, skip the report.
                    if (searchResult.Successes.Intersect(episodeParseResult.EpisodeNumbers).Any())
                    {
                        logger.Trace("Episode has already been downloaded in this search, skipping.");
                        item.SearchError = ReportRejectionType.Skipped;
                        continue;
                    }

                    episodeParseResult.Episodes = _episodeProvider.GetEpisodesByParseResult(episodeParseResult);

                    item.SearchError = _allowedDownloadSpecification.IsSatisfiedBy(episodeParseResult);
                    if (item.SearchError == ReportRejectionType.None)
                    {
                        logger.Debug("Found '{0}'. Adding to download queue.", episodeParseResult);
                        try
                        {
                            if (_downloadProvider.DownloadReport(episodeParseResult))
                            {
                                notification.CurrentMessage = String.Format("{0} Added to download queue", episodeParseResult);

                                //Add the list of episode numbers from this release
                                searchResult.Successes.AddRange(episodeParseResult.EpisodeNumbers);
                                item.Success = true;
                            }
                            else
                            {
                                item.SearchError = ReportRejectionType.DownloadClientFailure;
                            }
                        }
                        catch (Exception e)
                        {
                            logger.ErrorException("Unable to add report to download queue." + episodeParseResult, e);
                            notification.CurrentMessage = String.Format("Unable to add report to download queue. {0}", episodeParseResult);
                            item.SearchError = ReportRejectionType.DownloadClientFailure;
                        }
                    }
                }
                catch (Exception e)
                {
                    logger.ErrorException("An error has occurred while processing parse result items from " + episodeParseResult, e);
                }
            }

            return items;
        }
示例#8
0
        public virtual SearchHistory ProcessReports(Series series, dynamic options, List<EpisodeParseResult> episodeParseResults,
                                                              SearchHistory searchResult, ProgressNotification notification)
        {
            var items = new List<SearchHistoryItem>();
            searchResult.Successes = new List<Int32>();

            foreach(var episodeParseResult in episodeParseResults
                                                        .OrderByDescending(c => c.Quality)
                                                        .ThenBy(c => c.EpisodeNumbers.MinOrDefault())
                                                        .ThenBy(c => c.Age))
            {
                try
                {
                    var item = new SearchHistoryItem
                        {
                                ReportTitle = episodeParseResult.OriginalString,
                                NzbUrl = episodeParseResult.NzbUrl,
                                Indexer = episodeParseResult.Indexer,
                                Quality = episodeParseResult.Quality.Quality,
                                Proper = episodeParseResult.Quality.Proper,
                                Size = episodeParseResult.Size,
                                Age = episodeParseResult.Age,
                                Language = episodeParseResult.Language
                        };

                    items.Add(item);

                    logger.Trace("Analysing report " + episodeParseResult);
                    episodeParseResult.Series = _seriesProvider.FindSeries(episodeParseResult.CleanTitle);

                    if(episodeParseResult.Series == null || episodeParseResult.Series.SeriesId != series.SeriesId)
                    {
                        item.SearchError = ReportRejectionType.WrongSeries;
                        continue;
                    }

                    episodeParseResult.Episodes = _episodeProvider.GetEpisodesByParseResult(episodeParseResult);

                    if (searchResult.Successes.Intersect(episodeParseResult.Episodes.Select(e => e.EpisodeId)).Any())
                    {
                        item.SearchError = ReportRejectionType.Skipped;
                        continue;
                    }

                    CheckReport(series, options, episodeParseResult, item);
                    if (item.SearchError != ReportRejectionType.None)
                        continue;

                    item.SearchError = _allowedDownloadSpecification.IsSatisfiedBy(episodeParseResult);

                    if(item.SearchError == ReportRejectionType.None)
                    {
                        if(DownloadReport(notification, episodeParseResult, item))
                            searchResult.Successes.AddRange(episodeParseResult.Episodes.Select(e => e.EpisodeId));
                    }
                }
                catch(Exception e)
                {
                    logger.ErrorException("An error has occurred while processing parse result items from " + episodeParseResult, e);
                }
            }

            searchResult.SearchHistoryItems = items;
            return searchResult;
        }
示例#9
0
 public abstract SearchHistoryItem CheckReport(Series series, dynamic options, EpisodeParseResult episodeParseResult,
                                                         SearchHistoryItem item);
示例#10
0
        public virtual Boolean DownloadReport(ProgressNotification notification, EpisodeParseResult episodeParseResult, SearchHistoryItem item)
        {
            logger.Debug("Found '{0}'. Adding to download queue.", episodeParseResult);
            try
            {
                if (_downloadProvider.DownloadReport(episodeParseResult))
                {
                    notification.CurrentMessage = String.Format("{0} Added to download queue", episodeParseResult);
                    item.Success = true;
                    return true;
                }

                item.SearchError = ReportRejectionType.DownloadClientFailure;
            }
            catch (Exception e)
            {
                logger.ErrorException("Unable to add report to download queue." + episodeParseResult, e);
                notification.CurrentMessage = String.Format("Unable to add report to download queue. {0}", episodeParseResult);
                item.SearchError = ReportRejectionType.DownloadClientFailure;
            }

            return false;
        }