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()); }
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)); }
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()); }
public virtual void Start(ProgressNotification notification, dynamic options) { if (options == null || options.EpisodeId <= 0) throw new ArgumentException("options"); _searchProvider.EpisodeSearch(notification, options.EpisodeId); }
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()); }
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); }
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); } } }
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); }
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"); }
public virtual void Start(ProgressNotification notification, int targetId, int secondaryTargetId) { if (targetId <= 0) throw new ArgumentOutOfRangeException("targetId"); _searchProvider.EpisodeSearch(notification, targetId); }
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); }
public void Start(ProgressNotification notification, dynamic options) { ExecutionCount++; Console.WriteLine("Begin " + Name); Start(); Console.WriteLine("End " + Name); }
public virtual void Start(ProgressNotification notification, dynamic options) { notification.CurrentMessage = "Restarting NzbDrone"; logger.Info("Restarting NzbDrone"); _iisProvider.StopServer(); }
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>(); }
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)); }
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>(); }
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); }
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"); }
public void Start(ProgressNotification notification, int targetId, int secondaryTargetId) { ExecutionCount++; Console.WriteLine("Begin " + Name); Start(); Console.WriteLine("End " + Name); }
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; }
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; }
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); } } }
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); }
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); }
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 }); } }
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(); }