From eaa7b390251ca67d96528cb4777207f1bdf732a7 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 1 Aug 2013 00:11:42 -0700 Subject: [PATCH] Better notification messages --- .../NotificationServiceFixture.cs | 9 ++++- .../MediaFiles/EpisodeFileMovingService.cs | 2 +- .../Events/EpisodeDownloadedEvent.cs | 8 ++--- .../Notifications/NotificationService.cs | 35 ++++++++++++------- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/NzbDrone.Core.Test/NotificationTests/NotificationServiceFixture.cs b/NzbDrone.Core.Test/NotificationTests/NotificationServiceFixture.cs index 86b96d582..3569f2766 100644 --- a/NzbDrone.Core.Test/NotificationTests/NotificationServiceFixture.cs +++ b/NzbDrone.Core.Test/NotificationTests/NotificationServiceFixture.cs @@ -102,6 +102,13 @@ namespace NzbDrone.Core.Test.NotificationTests .With(p => p.EpisodeNumbers = new int[] {1}) .Build(); + var localEpisode = Builder.CreateNew() + .With(e => e.Series = series) + .With(e => e.ParsedEpisodeInfo = parsedEpisodeInfo) + .With(e => e.Episodes = Builder.CreateListOfSize(1) + .Build().ToList()) + .Build(); + Mocker.GetMock() .Setup(s => s.All()) .Returns(notifications); @@ -111,7 +118,7 @@ namespace NzbDrone.Core.Test.NotificationTests .Setup(s => s.OnDownload(It.IsAny(), series)) .Throws(new SocketException()); - Subject.Handle(new EpisodeDownloadedEvent(parsedEpisodeInfo, series)); + Subject.Handle(new EpisodeDownloadedEvent(localEpisode)); Mocker.GetMock() .Verify(v => v.OnDownload(It.IsAny(), series), Times.Once()); diff --git a/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs b/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs index b050c8add..463e0959b 100644 --- a/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs +++ b/NzbDrone.Core/MediaFiles/EpisodeFileMovingService.cs @@ -77,7 +77,7 @@ namespace NzbDrone.Core.MediaFiles var destinationFilename = _buildFileNames.BuildFilePath(localEpisode.Series, localEpisode.SeasonNumber, newFileName, Path.GetExtension(episodeFile.Path)); episodeFile = MoveFile(episodeFile, destinationFilename); - _messageAggregator.PublishEvent(new EpisodeDownloadedEvent(localEpisode.ParsedEpisodeInfo, localEpisode.Series)); + _messageAggregator.PublishEvent(new EpisodeDownloadedEvent(localEpisode)); return episodeFile; } diff --git a/NzbDrone.Core/MediaFiles/Events/EpisodeDownloadedEvent.cs b/NzbDrone.Core/MediaFiles/Events/EpisodeDownloadedEvent.cs index 09c3d0c4b..eb2ecee77 100644 --- a/NzbDrone.Core/MediaFiles/Events/EpisodeDownloadedEvent.cs +++ b/NzbDrone.Core/MediaFiles/Events/EpisodeDownloadedEvent.cs @@ -6,13 +6,11 @@ namespace NzbDrone.Core.MediaFiles.Events { public class EpisodeDownloadedEvent : IEvent { - public ParsedEpisodeInfo ParsedEpisodeInfo { get; private set; } - public Series Series { get; set; } + public LocalEpisode Episode { get; private set; } - public EpisodeDownloadedEvent(ParsedEpisodeInfo parsedEpisodeInfo, Series series) + public EpisodeDownloadedEvent(LocalEpisode episode) { - ParsedEpisodeInfo = parsedEpisodeInfo; - Series = series; + Episode = episode; } } } \ No newline at end of file diff --git a/NzbDrone.Core/Notifications/NotificationService.cs b/NzbDrone.Core/Notifications/NotificationService.cs index 753788f07..d66d00752 100644 --- a/NzbDrone.Core/Notifications/NotificationService.cs +++ b/NzbDrone.Core/Notifications/NotificationService.cs @@ -135,24 +135,35 @@ namespace NzbDrone.Core.Notifications return instance; } - private string GetMessage(ParsedEpisodeInfo parsedEpisodeInfo, Series series) + private string GetMessage(Series series, List episodes, QualityModel quality) { if (series.SeriesType == SeriesTypes.Daily) { - return String.Format("{0} - {1}", - series.Title, - parsedEpisodeInfo.AirDate.Value.ToString(Episode.AIR_DATE_FORMAT)); + var episode = episodes.First(); + + return String.Format("{0} - {1} - {2} [{3}]", + series.Title, + episode.AirDate, + episode.Title, + quality); } - - return String.Format("{0} - {1}{2}", - series.Title, - parsedEpisodeInfo.SeasonNumber, - String.Concat(parsedEpisodeInfo.EpisodeNumbers.Select(i => String.Format("x{0:00}", i)))); + + var episodeNumbers = String.Concat(episodes.Select(e => e.EpisodeNumber) + .Select(i => String.Format("x{0:00}", i))); + + var episodeTitles = String.Join(" + ", episodes.Select(e => e.Title)); + + return String.Format("{0} - {1}{2} - {3} {4}", + series.Title, + episodes.First().SeasonNumber, + episodeNumbers, + episodeTitles, + quality); } public void Handle(EpisodeGrabbedEvent message) { - var messageBody = GetMessage(message.Episode.ParsedEpisodeInfo, message.Episode.Series); + var messageBody = GetMessage(message.Episode.Series, message.Episode.Episodes, message.Episode.ParsedEpisodeInfo.Quality); foreach (var notification in All().Where(n => n.OnGrab)) { @@ -170,13 +181,13 @@ namespace NzbDrone.Core.Notifications public void Handle(EpisodeDownloadedEvent message) { - var messageBody = GetMessage(message.ParsedEpisodeInfo, message.Series); + var messageBody = GetMessage(message.Episode.Series, message.Episode.Episodes, message.Episode.ParsedEpisodeInfo.Quality); foreach (var notification in All().Where(n => n.OnDownload)) { try { - notification.Instance.OnDownload(messageBody, message.Series); + notification.Instance.OnDownload(messageBody, message.Episode.Series); } catch (Exception ex)