Esempio n. 1
0
        public void Execute(MissingEpisodeSearchCommand message)
        {
            List <Episode> episodes;

            if (message.SeriesId.HasValue)
            {
                episodes = _episodeService.GetEpisodeBySeries(message.SeriesId.Value)
                           .Where(e => e.Monitored &&
                                  !e.HasFile &&
                                  e.AirDateUtc.HasValue &&
                                  e.AirDateUtc.Value.Before(DateTime.UtcNow))
                           .ToList();
            }

            else
            {
                episodes = _episodeService.EpisodesWithoutFiles(new PagingSpec <Episode>
                {
                    Page             = 1,
                    PageSize         = 100000,
                    SortDirection    = SortDirection.Ascending,
                    SortKey          = "Id",
                    FilterExpression =
                        v =>
                        v.Monitored == true &&
                        v.Series.Monitored == true
                }).Records.ToList();
            }

            var queue   = _queueService.GetQueue().Select(q => q.Episode.Id);
            var missing = episodes.Where(e => !queue.Contains(e.Id)).ToList();

            SearchForMissingEpisodes(missing);
        }
Esempio n. 2
0
        public void Execute(MissingEpisodeSearchCommand message)
        {
            //TODO: Look at ways to make this more efficient (grouping by series/season)

            var episodes =
                _episodeService.EpisodesWithoutFiles(new PagingSpec <Episode>
            {
                Page             = 1,
                PageSize         = 100000,
                SortDirection    = SortDirection.Ascending,
                SortKey          = "Id",
                FilterExpression = v => v.Monitored == true && v.Series.Monitored == true
            }).Records.ToList();

            var missing = episodes.Where(e => !_queueService.GetQueue().Select(q => q.Episode.Id).Contains(e.Id)).ToList();

            _logger.ProgressInfo("Performing missing search for {0} episodes", missing.Count);
            var downloadedCount = 0;

            //Limit requests to indexers at 100 per minute
            using (var rateGate = new RateGate(100, TimeSpan.FromSeconds(60)))
            {
                foreach (var episode in missing)
                {
                    rateGate.WaitToProceed();
                    var decisions  = _nzbSearchService.EpisodeSearch(episode);
                    var downloaded = _downloadApprovedReports.DownloadApproved(decisions);
                    downloadedCount += downloaded.Count;
                }
            }

            _logger.ProgressInfo("Completed missing search for {0} episodes. {1} reports downloaded.", missing.Count, downloadedCount);
        }
Esempio n. 3
0
        public void Execute(MissingEpisodeSearchCommand message)
        {
            var            monitored = message.Monitored;
            List <Episode> episodes;

            if (message.SeriesId.HasValue)
            {
                episodes = _episodeService.GetEpisodeBySeries(message.SeriesId.Value)
                           .Where(e => e.Monitored == monitored &&
                                  !e.HasFile &&
                                  e.AirDateUtc.HasValue &&
                                  e.AirDateUtc.Value.Before(DateTime.UtcNow))
                           .ToList();
            }

            else
            {
                var pagingSpec = new PagingSpec <Episode>
                {
                    Page          = 1,
                    PageSize      = 100000,
                    SortDirection = SortDirection.Ascending,
                    SortKey       = "Id"
                };

                if (monitored)
                {
                    pagingSpec.FilterExpressions.Add(v => v.Monitored == true && v.Series.Monitored == true);
                }
                else
                {
                    pagingSpec.FilterExpressions.Add(v => v.Monitored == false || v.Series.Monitored == false);
                }

                episodes = _episodeService.EpisodesWithoutFiles(pagingSpec).Records.ToList();
            }

            var queue   = _queueService.GetQueue().Where(q => q.Episode != null).Select(q => q.Episode.Id);
            var missing = episodes.Where(e => !queue.Contains(e.Id)).ToList();

            SearchForEpisodes(missing, monitored, message.Trigger == CommandTrigger.Manual);
        }