Ejemplo n.º 1
0
        public void SeasonSearch_partial_season_success()
        {
            var episodes = Builder<Episode>.CreateListOfSize(5)
                .All()
                .With(e => e.SeriesId = 1)
                .With(e => e.SeasonNumber = 1)
                .Build();

            var notification = new ProgressNotification("Season Search");

            Mocker.GetMock<SearchProvider>()
                .Setup(c => c.SeasonSearch(notification, 1, 1)).Returns(false);

            Mocker.GetMock<EpisodeProvider>()
                .Setup(c => c.GetEpisodesBySeason(1, 1)).Returns(episodes);

            Mocker.GetMock<SearchProvider>()
                .Setup(c => c.PartialSeasonSearch(notification, 1, 1))
                .Returns(episodes.Select(e => e.EpisodeNumber).ToList());

            //Act
            Mocker.Resolve<SeasonSearchJob>().Start(notification, 1, 1);

            //Assert
            Mocker.VerifyAllMocks();
            Mocker.GetMock<SearchProvider>().Verify(c => c.SeasonSearch(notification, 1, 1), Times.Once());
            Mocker.GetMock<SearchProvider>().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Once());
            Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0), Times.Never());
        }
Ejemplo n.º 2
0
        public void BannerDownload_some_null_BannerUrl()
        {
            //Setup
            var fakeSeries = Builder<Series>.CreateListOfSize(10)
                .Random(2)
                .With(s => s.BannerUrl = null)
                .Build();

          var notification = new ProgressNotification("Banner Download");

            Mocker.GetMock<SeriesProvider>()
                .Setup(c => c.GetAllSeries())
                .Returns(fakeSeries);

            Mocker.GetMock<HttpProvider>()
                .Setup(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()));

            Mocker.GetMock<DiskProvider>()
                .Setup(S => S.CreateDirectory(It.IsAny<string>()))
                .Returns("");

            //Act
            Mocker.Resolve<BannerDownloadJob>().Start(notification, 0, 0);

            //Assert
            Mocker.VerifyAllMocks();
            Mocker.GetMock<HttpProvider>().Verify(s => s.DownloadFile(It.IsAny<string>(), It.IsAny<string>()),
                                                       Times.Exactly(8));
        }
Ejemplo n.º 3
0
        public void SeasonSearch_partial_season_failure()
        {
            var episodes = Builder<Episode>.CreateListOfSize(5)
                .All()
                .With(e => e.SeriesId = 1)
                .With(e => e.SeasonNumber = 1)
                .With(e => e.Ignored = false)
                .With(e => e.AirDate = DateTime.Today.AddDays(-1))
                .Build();

            var notification = new ProgressNotification("Season Search");

            Mocker.GetMock<SearchProvider>()
                .Setup(c => c.SeasonSearch(notification, 1, 1)).Returns(false);

            Mocker.GetMock<EpisodeProvider>()
                .Setup(c => c.GetEpisodesBySeason(1, 1)).Returns(episodes);

            Mocker.GetMock<SearchProvider>()
                .Setup(c => c.PartialSeasonSearch(notification, 1, 1))
                .Returns(new List<int>{1});

            //Act
            Mocker.Resolve<SeasonSearchJob>().Start(notification, 1, 1);

            //Assert
            Mocker.VerifyAllMocks();
            Mocker.GetMock<SearchProvider>().Verify(c => c.SeasonSearch(notification, 1, 1), Times.Once());
            Mocker.GetMock<SearchProvider>().Verify(c => c.PartialSeasonSearch(notification, 1, 1), Times.Once());
        }
Ejemplo n.º 4
0
        public virtual void Start(ProgressNotification notification, dynamic options)
        {
            if (options == null || options.EpisodeId <= 0)
                throw new ArgumentException("options");

            _searchProvider.EpisodeSearch(notification, options.EpisodeId);
        }
Ejemplo n.º 5
0
        public void individual_missing_episode()
        {
            //Setup
            var notification = new ProgressNotification("Backlog Search Job Test");

            var series = Builder<Series>.CreateNew()
                    .With(s => s.Monitored = true)
                    .With(s => s.BacklogSetting = BacklogSettingType.Enable)
                    .Build();

            var episodes = Builder<Episode>.CreateListOfSize(1)
                .All()
                .With(e => e.Series = series)
                .Build();

            WithStrictMocker();
            WithEnableBacklogSearching();

            Mocker.GetMock<EpisodeProvider>()
                .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);

            Mocker.GetMock<EpisodeSearchJob>()
                .Setup(s => s.Start(notification, It.IsAny<int>(), 0)).Verifiable();

            //Act
            Mocker.Resolve<BacklogSearchJob>().Start(notification, 0, 0);

            //Assert
            Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), It.IsAny<int>()),
                                                       Times.Never());

            Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.IsAny<int>(), 0),
                                                       Times.Once());
        }
Ejemplo n.º 6
0
        protected override void FinalizeSearch(Series series, dynamic options, Boolean reportsFound, ProgressNotification notification)
        {
            logger.Warn("Unable to find {0} in any of indexers.", options.Episode);

            notification.CurrentMessage = reportsFound ? String.Format("Sorry, couldn't find {0}, that matches your preferences.", options.Episode.AirDate)
                                                        : String.Format("Sorry, couldn't find {0} in any of indexers.", options.Episode);
        }
Ejemplo n.º 7
0
        public virtual void Start(ProgressNotification notification, dynamic options)
        {
            IList<Series> seriesToUpdate;
            if (options == null || options.SeriesId == 0)
            {
                seriesToUpdate = _seriesProvider.GetAllSeries().OrderBy(o => SortHelper.SkipArticles(o.Title)).ToList();
            }
            else
            {
                seriesToUpdate = new List<Series> { _seriesProvider.GetSeries(options.SeriesId) };
            }

            //Update any Daily Series in the DB with the IsDaily flag
            _referenceDataProvider.UpdateDailySeries();

            foreach (var series in seriesToUpdate)
            {
                try
                {
                    notification.CurrentMessage = "Updating " + series.Title;
                    _seriesProvider.UpdateSeriesInfo(series.SeriesId);
                    _episodeProvider.RefreshEpisodeInfo(series);
                    notification.CurrentMessage = "Update completed for " + series.Title;
                }

                catch(Exception ex)
                {
                    Logger.ErrorException("Failed to update episode info for series: " + series.Title, ex);
                }
                
            }
        }
Ejemplo n.º 8
0
        private void RefreshMetadata(ProgressNotification notification, Series series)
        {
            notification.CurrentMessage = String.Format("Refreshing episode metadata for '{0}'", series.Title);

            Logger.Debug("Getting episodes from database for series: {0}", series.SeriesId);
            var episodeFiles = _mediaFileProvider.GetSeriesFiles(series.SeriesId);

            if (episodeFiles == null || episodeFiles.Count == 0)
            {
                Logger.Warn("No episodes in database found for series: {0}", series.SeriesId);
                return;
            }

            try
            {
                _metadataProvider.CreateForEpisodeFiles(episodeFiles.ToList());
            }

            catch (Exception e)
            {
                Logger.WarnException("An error has occurred while refreshing episode metadata", e);
            }

            notification.CurrentMessage = String.Format("Epsiode metadata refresh completed for {0}", series.Title);
        }
Ejemplo n.º 9
0
        public virtual void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
        {
            Logger.Debug("Starting banner download job");


            _diskProvider.CreateDirectory(_enviromentProvider.GetBannerPath());

            if (targetId > 0)
            {
                var series = _seriesProvider.GetSeries(targetId);

                if (series != null && !String.IsNullOrEmpty(series.BannerUrl))
                    DownloadBanner(notification, series);

                return;
            }

            var seriesInDb = _seriesProvider.GetAllSeries();

            foreach (var series in seriesInDb.Where(s => !String.IsNullOrEmpty(s.BannerUrl)))
            {
                DownloadBanner(notification, series);
            }

            Logger.Debug("Finished banner download job");
        }
Ejemplo n.º 10
0
        public virtual void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
        {
            if (targetId <= 0)
                throw new ArgumentOutOfRangeException("targetId");

            _searchProvider.EpisodeSearch(notification, targetId);
        }
Ejemplo n.º 11
0
        public virtual List<int> PartialSeasonSearch(ProgressNotification notification, int seriesId, int seasonNumber)
        {
            var series = _seriesProvider.GetSeries(seriesId);

            if (series == null)
            {
                logger.Error("Unable to find an series {0} in database", seriesId);
                return new List<int>();
            }

            if (series.IsDaily)
            {
                logger.Trace("Daily series detected, skipping season search: {0}", series.Title);
                return new List<int>();
            }

            var episodes = _episodeProvider.GetEpisodesBySeason(seriesId, seasonNumber);

            if (episodes == null || episodes.Count == 0)
            {
                logger.Warn("No episodes in database found for series: {0} Season: {1}.", seriesId, seasonNumber);
                return new List<int>();
            }

            return _partialSeasonSearch.Search(series, new {SeasonNumber = seasonNumber, Episodes = episodes}, notification);
        }
Ejemplo n.º 12
0
 public void Start(ProgressNotification notification, dynamic options)
 {
     ExecutionCount++;
     Console.WriteLine("Begin " + Name);
     Start();
     Console.WriteLine("End " + Name);
 }
Ejemplo n.º 13
0
        public virtual void Start(ProgressNotification notification, dynamic options)
        {
            notification.CurrentMessage = "Restarting NzbDrone";
            logger.Info("Restarting NzbDrone");

            _iisProvider.StopServer();
        }
Ejemplo n.º 14
0
        public virtual List<int> SeasonSearch(ProgressNotification notification, int seriesId, int seasonNumber)
        {
            var series = _seriesProvider.GetSeries(seriesId);

            if (series == null)
            {
                logger.Error("Unable to find an series {0} in database", seriesId);
                return new List<int>();
            }

            if (series.IsDaily)
            {
                logger.Trace("Daily series detected, skipping season search: {0}", series.Title);
                return new List<int>();
            }

            logger.Debug("Getting episodes from database for series: {0} and season: {1}", seriesId, seasonNumber);
            var episodes = _episodeProvider.GetEpisodesBySeason(seriesId, seasonNumber);

            if (episodes == null || episodes.Count == 0)
            {
                logger.Warn("No episodes in database found for series: {0} and season: {1}.", seriesId, seasonNumber);
                return new List<int>();
            }

            //Todo: Support full season searching
            return new List<int>();
        }
Ejemplo n.º 15
0
        public void SeriesSearch_success()
        {
            var seasons = new List<int> { 1, 2, 3, 4, 5 };

            WithStrictMocker();

            var notification = new ProgressNotification("Series Search");

            Mocker.GetMock<SeasonProvider>()
                .Setup(c => c.GetSeasons(1)).Returns(seasons);

            Mocker.GetMock<SeasonProvider>()
                .Setup(c => c.IsIgnored(It.IsAny<int>(), It.IsAny<int>())).Returns(false);

            Mocker.GetMock<SeasonSearchJob>()
                .Setup(c => c.Start(notification, 1, It.IsAny<int>())).Verifiable();

            //Act
            Mocker.Resolve<SeriesSearchJob>().Start(notification, 1, 0);

            //Assert
            Mocker.VerifyAllMocks();
            Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, 1, It.IsAny<int>()),
                                                       Times.Exactly(seasons.Count));
        }
Ejemplo n.º 16
0
        public virtual List<Int32> Search(Series series, dynamic options, ProgressNotification notification)
        {
            if (options == null)
                throw new ArgumentNullException(options);

            var searchResult = new SearchHistory
            {
                SearchTime = DateTime.Now,
                SeriesId = series.SeriesId,
                EpisodeId = options.GetType().GetProperty("Episode") != null ? options.Episode.EpisodeId : null,
                SeasonNumber = options.GetType().GetProperty("SeasonNumber") != null ? options.SeasonNumber : null
            };

            List<EpisodeParseResult> reports = PerformSearch(series, options, notification);
            
            logger.Debug("Finished searching all indexers. Total {0}", reports.Count);
            notification.CurrentMessage = "Processing search results";
            
            ProcessReports(series, options, reports, searchResult, notification);
            _searchHistoryProvider.Add(searchResult);

            if(searchResult.Successes.Any())
                return searchResult.Successes;

            FinalizeSearch(series, options, reports.Any(), notification);
            return new List<Int32>();
        }
Ejemplo n.º 17
0
        public virtual void Start(ProgressNotification notification, dynamic options)
        {
            if (options == null || options.SeriesId <= 0)
                throw new ArgumentException("options");

            if (options.SeasonNumber < 0)
                throw new ArgumentException("options.SeasonNumber");

            //Perform a Partial Season Search - Because a full season search is a waste
            //3 searches should guarentee results, (24 eps) versus, a potential 4 to get the same eps.
            List<int> successes = _searchProvider.PartialSeasonSearch(notification, options.SeriesId, options.SeasonNumber);

            //This causes issues with Newznab
            //if (successes.Count == 0)
            //    return;

            Logger.Debug("Getting episodes from database for series: {0} and season: {1}", options.SeriesId, options.SeasonNumber);
            List<Episode> episodes = _episodeProvider.GetEpisodesBySeason(options.SeriesId, options.SeasonNumber);

            if (episodes == null || episodes.Count == 0)
            {
                Logger.Warn("No episodes in database found for series: {0} and season: {1}.", options.SeriesId, options.SeasonNumber);
                return;
            }

            if (episodes.Count == successes.Count)
                return;

            var missingEpisodes = episodes.Select(e => e.EpisodeNumber).Except(successes).ToList();

            foreach (var episode in episodes.Where(e => !e.Ignored && missingEpisodes.Contains(e.EpisodeNumber)).OrderBy(o => o.EpisodeNumber))
            {
                _episodeSearchJob.Start(notification, new { EpisodeId = episode.EpisodeId });
            }
        }
        public void should_return_current_on_active_notifications()
        {
            var fakeNotification = new ProgressNotification("Title");
            _notificationProvider.Register(fakeNotification);

            _notificationProvider.GetCurrent().Should().Be(fakeNotification);
        }
Ejemplo n.º 19
0
        public virtual void Start(ProgressNotification notification, dynamic options)
        {
            Logger.Debug("Starting banner download job");

            if (options != null)
            {
                Series series = _seriesProvider.GetSeries(options.SeriesId);

                if (series != null && !String.IsNullOrEmpty(series.BannerUrl))
                {
                    DownloadBanner(notification, series);
                }

                return;
            }

            var seriesInDb = _seriesProvider.GetAllSeries();

            foreach (var series in seriesInDb.Where(s => !String.IsNullOrEmpty(s.BannerUrl)))
            {
                DownloadBanner(notification, series);
            }

            Logger.Debug("Finished banner download job");
        }
Ejemplo n.º 20
0
 public void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
 {
     ExecutionCount++;
     Console.WriteLine("Begin " + Name);
     Start();
     Console.WriteLine("End " + Name);
 }
Ejemplo n.º 21
0
        public virtual string ConvertFile(Episode episode, ProgressNotification notification)
        {
            _notification = notification;
            _currentEpisode = episode;

            var outputFile = _configProvider.GetValue("iPodConvertDir", "");

            var handBrakePreset = _configProvider.GetValue("HandBrakePreset", "iPhone & iPod Touch");
            var handBrakeCommand = String.Format("-i \"{0}\" -o \"{1}\" --preset=\"{2}\"", episode.EpisodeFile.Path, outputFile, handBrakePreset);
            var handBrakeFile = @"C:\Program Files (x86)\Handbrake\HandBrakeCLI.exe";

            try
            {
                var process = new Process();
                process.StartInfo.FileName = handBrakeFile;
                process.StartInfo.Arguments = handBrakeCommand;
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.CreateNoWindow = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.OutputDataReceived += new DataReceivedEventHandler(HandBrakeOutputDataReceived);
                process.Start();
                process.BeginOutputReadLine();
                process.WaitForExit();
            }

            catch (Exception ex)
            {
                Logger.DebugException(ex.Message, ex);
                return String.Empty;
            }

            return outputFile;
        }
Ejemplo n.º 22
0
        public override List<EpisodeParseResult> PerformSearch(Series series, dynamic options, ProgressNotification notification)
        {
            if (options.Episode == null)
                throw new ArgumentException("Episode is invalid");

            notification.CurrentMessage = "Looking for " + options.Episode;

            var reports = new List<EpisodeParseResult>();
            var title = GetSearchTitle(series);

            Parallel.ForEach(_indexerProvider.GetEnabledIndexers(), indexer =>
            {
                try
                {
                    reports.AddRange(indexer.FetchDailyEpisode(title, options.Episode.AirDate));
                }

                catch (Exception e)
                {
                    logger.ErrorException(String.Format("An error has occurred while searching for {0} - {1:yyyy-MM-dd} from: {2}",
                                                         series.Title, options.Episode.AirDate, indexer.Name), e);
                }
            });

            return reports;
        }
Ejemplo n.º 23
0
        public virtual void Start(ProgressNotification notification, dynamic options)
        {
            IList<Series> seriesToScan;
            if (options == null || options.SeriesId == 0)
            {
                seriesToScan = _seriesProvider.GetAllSeries().OrderBy(o => SortHelper.SkipArticles(o.Title)).ToList();
            }
            else
            {
                seriesToScan = new List<Series>() { _seriesProvider.GetSeries(options.SeriesId) };
            }

            foreach (var series in seriesToScan)
            {
                try
                {
                    notification.CurrentMessage = string.Format("Scanning disk for '{0}'", series.Title);
                    _diskScanProvider.Scan(series);
                    notification.CurrentMessage = string.Format("Disk Scan completed for '{0}'", series.Title);
                }
                catch (Exception e)
                {
                    Logger.ErrorException("An error has occurred while scanning " + series.Title, e);
                }
            }
        }
Ejemplo n.º 24
0
        public void import_new_series_succesfull()
        {
            var series = Builder<Series>.CreateListOfSize(2)
                     .All().With(s => s.LastInfoSync = null)
                     .TheFirst(1).With(s => s.SeriesId = 12)
                     .TheNext(1).With(s => s.SeriesId = 15)
                        .Build();

            var notification = new ProgressNotification("Test");

            WithStrictMocker();

            Mocker.GetMock<SeriesProvider>()
                .Setup(p => p.GetAllSeries())
                .Returns(series);


            Mocker.GetMock<DiskScanJob>()
                .Setup(j => j.Start(notification, series[0].SeriesId, 0))
                .Callback(() => series[0].LastDiskSync = DateTime.Now);


            Mocker.GetMock<DiskScanJob>()
                .Setup(j => j.Start(notification, series[1].SeriesId, 0))
                .Callback(() => series[1].LastDiskSync = DateTime.Now);

            Mocker.GetMock<BannerDownloadJob>()
                .Setup(j => j.Start(notification, It.IsAny<int>(), 0));

            Mocker.GetMock<UpdateInfoJob>()
                .Setup(j => j.Start(notification, series[0].SeriesId, 0))
                .Callback(() => series[0].LastInfoSync = DateTime.Now);

            Mocker.GetMock<UpdateInfoJob>()
                .Setup(j => j.Start(notification, series[1].SeriesId, 0))
                .Callback(() => series[1].LastInfoSync = DateTime.Now);

            Mocker.GetMock<SeriesProvider>()
                .Setup(s => s.GetSeries(series[0].SeriesId)).Returns(series[0]);

            Mocker.GetMock<SeriesProvider>()
                .Setup(s => s.GetSeries(series[1].SeriesId)).Returns(series[1]);

            Mocker.GetMock<MediaFileProvider>()
                .Setup(s => s.GetSeriesFiles(It.IsAny<int>())).Returns(new List<EpisodeFile>());

            //Act
            Mocker.Resolve<ImportNewSeriesJob>().Start(notification, 0, 0);

            //Assert
            Mocker.VerifyAllMocks();

            Mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, series[0].SeriesId, 0), Times.Once());
            Mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, series[1].SeriesId, 0), Times.Once());

            Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, series[0].SeriesId, 0), Times.Once());
            Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, series[1].SeriesId, 0), Times.Once());

        }
        public void should_return_last_if_recently_completed()
        {
            var fakeNotification = new ProgressNotification("Title");
            _notificationProvider.Register(fakeNotification);
            fakeNotification.Dispose();

            _notificationProvider.GetCurrent().Should().Be(fakeNotification);
        }
Ejemplo n.º 26
0
        public void Start(ProgressNotification notification, dynamic options)
        {
            if (options == null)
                throw new ArgumentNullException("options");

            if (options.SeriesId == 0)
                throw new ArgumentNullException("options.SeriesId");

            DeleteSeries(notification, options.SeriesId, options.DeleteFiles);
        }
Ejemplo n.º 27
0
        public void Start(ProgressNotification notification, dynamic options)
        {
            var missingEpisodes = GetMissingForEnabledSeries();

            Logger.Debug("Processing missing episodes from the past week, count: {0}", missingEpisodes.Count);
            foreach (var episode in missingEpisodes)
            {
                _episodeSearchJob.Start(notification, new { EpisodeId = episode.EpisodeId });
            }
        }
Ejemplo n.º 28
0
        public void Start(ProgressNotification notification, int targetId, int secondaryTargetId)
        {
            var missingEpisodes = GetMissingForEnabledSeries();

            Logger.Debug("Processing missing episodes from the last 30 days, count: {0}", missingEpisodes.Count);
            foreach (var episode in missingEpisodes)
            {
                _episodeSearchJob.Start(notification, episode.EpisodeId, 0);
            }
        }
        public void new_notification_should_replace_old_one()
        {
            var oldNotification = new ProgressNotification("Title");
            _notificationProvider.Register(oldNotification);

            var newNotification = new ProgressNotification("Title");
            _notificationProvider.Register(newNotification);

            _notificationProvider.GetCurrent().Should().Be(newNotification);
        }
        public void should_return_null_if_completed_long_time_ago()
        {
            var fakeNotification = new ProgressNotification("Title");
            _notificationProvider.Register(fakeNotification);
            fakeNotification.Dispose();

            Thread.Sleep(7000);

            _notificationProvider.GetCurrent().Should().BeNull();
        }