From d6bb4c29d089860ac1551b4960c120e9c394a472 Mon Sep 17 00:00:00 2001 From: Qstick Date: Sat, 28 Oct 2017 16:30:38 -0400 Subject: [PATCH] New: Download client and ID for custom scripts --- .../HistoryTests/HistoryServiceFixture.cs | 10 +++++- .../MediaFiles/Events/TrackDownloadedEvent.cs | 23 ------------- .../MediaFiles/Events/TrackImportedEvent.cs | 24 +++++++------- .../TrackImport/ImportApprovedTracks.cs | 13 +------- .../CustomScript/CustomScript.cs | 4 +++ .../Notifications/DownloadMessage.cs | 2 ++ .../Notifications/GrabMessage.cs | 4 ++- .../Notifications/NotificationService.cs | 32 +++++++++++++------ src/NzbDrone.Core/NzbDrone.Core.csproj | 1 - 9 files changed, 52 insertions(+), 61 deletions(-) delete mode 100644 src/NzbDrone.Core/MediaFiles/Events/TrackDownloadedEvent.cs diff --git a/src/NzbDrone.Core.Test/HistoryTests/HistoryServiceFixture.cs b/src/NzbDrone.Core.Test/HistoryTests/HistoryServiceFixture.cs index 513017414..898d43033 100644 --- a/src/NzbDrone.Core.Test/HistoryTests/HistoryServiceFixture.cs +++ b/src/NzbDrone.Core.Test/HistoryTests/HistoryServiceFixture.cs @@ -10,7 +10,9 @@ using NzbDrone.Core.Profiles.Qualities; using NzbDrone.Core.Test.Framework; using NzbDrone.Core.History; using NzbDrone.Core.Qualities; +using System.Collections.Generic; using NzbDrone.Core.Test.Qualities; +using NzbDrone.Core.Download; using NzbDrone.Core.Music; using NzbDrone.Core.Languages; using NzbDrone.Core.Profiles.Languages; @@ -67,7 +69,13 @@ namespace NzbDrone.Core.Test.HistoryTests Path = @"C:\Test\Unsorted\Artist.01.Hymn.mp3" }; - Subject.Handle(new TrackImportedEvent(localTrack, trackFile, true, "sab", "abcd")); + var downloadClientItem = new DownloadClientItem + { + DownloadClient = "sab", + DownloadId = "abcd" + }; + + Subject.Handle(new TrackImportedEvent(localTrack, trackFile, new List(), true, downloadClientItem)); Mocker.GetMock() .Verify(v => v.Insert(It.Is(h => h.SourceTitle == Path.GetFileNameWithoutExtension(localTrack.Path)))); diff --git a/src/NzbDrone.Core/MediaFiles/Events/TrackDownloadedEvent.cs b/src/NzbDrone.Core/MediaFiles/Events/TrackDownloadedEvent.cs deleted file mode 100644 index 82ea9f788..000000000 --- a/src/NzbDrone.Core/MediaFiles/Events/TrackDownloadedEvent.cs +++ /dev/null @@ -1,23 +0,0 @@ -using NzbDrone.Common.Messaging; -using NzbDrone.Core.Parser.Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace NzbDrone.Core.MediaFiles.Events -{ - public class TrackDownloadedEvent : IEvent - { - public LocalTrack Track { get; private set; } - public TrackFile TrackFile { get; private set; } - public List OldFiles { get; private set; } - - public TrackDownloadedEvent(LocalTrack track, TrackFile trackFile, List oldFiles) - { - Track = track; - TrackFile = trackFile; - OldFiles = oldFiles; - } - } -} diff --git a/src/NzbDrone.Core/MediaFiles/Events/TrackImportedEvent.cs b/src/NzbDrone.Core/MediaFiles/Events/TrackImportedEvent.cs index b7b4f5610..eeb00398b 100644 --- a/src/NzbDrone.Core/MediaFiles/Events/TrackImportedEvent.cs +++ b/src/NzbDrone.Core/MediaFiles/Events/TrackImportedEvent.cs @@ -1,9 +1,7 @@ +using System.Collections.Generic; using NzbDrone.Common.Messaging; +using NzbDrone.Core.Download; using NzbDrone.Core.Parser.Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace NzbDrone.Core.MediaFiles.Events { @@ -11,24 +9,24 @@ namespace NzbDrone.Core.MediaFiles.Events { public LocalTrack TrackInfo { get; private set; } public TrackFile ImportedTrack { get; private set; } + public List OldFiles { get; private set; } public bool NewDownload { get; private set; } public string DownloadClient { get; private set; } public string DownloadId { get; private set; } - public TrackImportedEvent(LocalTrack trackInfo, TrackFile importedTrack, bool newDownload) + public TrackImportedEvent(LocalTrack trackInfo, TrackFile importedTrack, List oldFiles, bool newDownload, DownloadClientItem downloadClientItem) { TrackInfo = trackInfo; ImportedTrack = importedTrack; + OldFiles = oldFiles; NewDownload = newDownload; - } - public TrackImportedEvent(LocalTrack trackInfo, TrackFile importedTrack, bool newDownload, string downloadClient, string downloadId) - { - TrackInfo = trackInfo; - ImportedTrack = importedTrack; - NewDownload = newDownload; - DownloadClient = downloadClient; - DownloadId = downloadId; + if (downloadClientItem != null) + { + DownloadClient = downloadClientItem.DownloadClient; + DownloadId = downloadClientItem.DownloadId; + } + } } } diff --git a/src/NzbDrone.Core/MediaFiles/TrackImport/ImportApprovedTracks.cs b/src/NzbDrone.Core/MediaFiles/TrackImport/ImportApprovedTracks.cs index 07bc555c7..8757bd16a 100644 --- a/src/NzbDrone.Core/MediaFiles/TrackImport/ImportApprovedTracks.cs +++ b/src/NzbDrone.Core/MediaFiles/TrackImport/ImportApprovedTracks.cs @@ -124,19 +124,8 @@ namespace NzbDrone.Core.MediaFiles.TrackImport // _extraService.ImportExtraFiles(localTrack, trackFile, copyOnly); // TODO: Import Music Extras //} - if (downloadClientItem != null) - { - _eventAggregator.PublishEvent(new TrackImportedEvent(localTrack, trackFile, newDownload, downloadClientItem.DownloadClient, downloadClientItem.DownloadId)); - } - else - { - _eventAggregator.PublishEvent(new TrackImportedEvent(localTrack, trackFile, newDownload)); - } + _eventAggregator.PublishEvent(new TrackImportedEvent(localTrack, trackFile, oldFiles, newDownload, downloadClientItem)); - if (newDownload) - { - _eventAggregator.PublishEvent(new TrackDownloadedEvent(localTrack, trackFile, oldFiles)); - } } catch (Exception e) { diff --git a/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs b/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs index 666ae0d3f..446f442c1 100644 --- a/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs +++ b/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs @@ -49,6 +49,8 @@ namespace NzbDrone.Core.Notifications.CustomScript environmentVariables.Add("Lidarr_Release_Quality", remoteAlbum.ParsedAlbumInfo.Quality.Quality.Name); environmentVariables.Add("Lidarr_Release_QualityVersion", remoteAlbum.ParsedAlbumInfo.Quality.Revision.Version.ToString()); environmentVariables.Add("Lidarr_Release_ReleaseGroup", releaseGroup); + environmentVariables.Add("Lidarr_Download_Client", message.DownloadClient ?? string.Empty); + environmentVariables.Add("Lidarr_Download_Id", message.DownloadId ?? string.Empty); ExecuteScript(environmentVariables); } @@ -80,6 +82,8 @@ namespace NzbDrone.Core.Notifications.CustomScript environmentVariables.Add("Lidarr_TrackFile_SceneName", trackFile.SceneName ?? string.Empty); environmentVariables.Add("Lidarr_TrackFile_SourcePath", sourcePath); environmentVariables.Add("Lidarr_TrackFile_SourceFolder", Path.GetDirectoryName(sourcePath)); + environmentVariables.Add("Lidarr_Download_Client", message.DownloadClient ?? string.Empty); + environmentVariables.Add("Lidarr_Download_Id", message.DownloadId ?? string.Empty); if (message.OldFiles.Any()) { diff --git a/src/NzbDrone.Core/Notifications/DownloadMessage.cs b/src/NzbDrone.Core/Notifications/DownloadMessage.cs index b16725fc8..b88cb4694 100644 --- a/src/NzbDrone.Core/Notifications/DownloadMessage.cs +++ b/src/NzbDrone.Core/Notifications/DownloadMessage.cs @@ -11,6 +11,8 @@ namespace NzbDrone.Core.Notifications public TrackFile TrackFile { get; set; } public List OldFiles { get; set; } public string SourcePath { get; set; } + public string DownloadClient { get; set; } + public string DownloadId { get; set; } public override string ToString() { diff --git a/src/NzbDrone.Core/Notifications/GrabMessage.cs b/src/NzbDrone.Core/Notifications/GrabMessage.cs index c0dcfa574..b9eda36cd 100644 --- a/src/NzbDrone.Core/Notifications/GrabMessage.cs +++ b/src/NzbDrone.Core/Notifications/GrabMessage.cs @@ -9,7 +9,9 @@ namespace NzbDrone.Core.Notifications public string Message { get; set; } public Artist Artist { get; set; } public RemoteAlbum Album { get; set; } - public QualityModel Quality { get; set; } + public QualityModel Quality { get; set; } + public string DownloadClient { get; set; } + public string DownloadId { get; set; } public override string ToString() { diff --git a/src/NzbDrone.Core/Notifications/NotificationService.cs b/src/NzbDrone.Core/Notifications/NotificationService.cs index 8c3c39f52..47f1a4210 100644 --- a/src/NzbDrone.Core/Notifications/NotificationService.cs +++ b/src/NzbDrone.Core/Notifications/NotificationService.cs @@ -14,7 +14,7 @@ namespace NzbDrone.Core.Notifications { public class NotificationService : IHandle, - IHandle, + IHandle, IHandle { private readonly INotificationFactory _notificationFactory; @@ -88,7 +88,9 @@ namespace NzbDrone.Core.Notifications Message = GetMessage(message.Album.Artist, message.Album.Albums, message.Album.ParsedAlbumInfo.Quality), Artist = message.Album.Artist, Quality = message.Album.ParsedAlbumInfo.Quality, - Album = message.Album + Album = message.Album, + DownloadClient = message.DownloadClient, + DownloadId = message.DownloadId }; foreach (var notification in _notificationFactory.OnGrabEnabled()) @@ -106,20 +108,30 @@ namespace NzbDrone.Core.Notifications } } - public void Handle(TrackDownloadedEvent message) + public void Handle(TrackImportedEvent message) { - var downloadMessage = new DownloadMessage(); - downloadMessage.Message = GetTrackMessage(message.Track.Artist, message.Track.Tracks, message.Track.Quality); - downloadMessage.Artist = message.Track.Artist; - downloadMessage.TrackFile = message.TrackFile; - downloadMessage.OldFiles = message.OldFiles; - downloadMessage.SourcePath = message.Track.Path; + if (!message.NewDownload) + { + return; + } + + var downloadMessage = new DownloadMessage + + { + Message = GetTrackMessage(message.TrackInfo.Artist, message.TrackInfo.Tracks, message.TrackInfo.Quality), + Artist = message.TrackInfo.Artist, + TrackFile = message.ImportedTrack, + OldFiles = message.OldFiles, + SourcePath = message.TrackInfo.Path, + DownloadClient = message.DownloadClient, + DownloadId = message.DownloadId + }; foreach (var notification in _notificationFactory.OnDownloadEnabled()) { try { - if (ShouldHandleArtist(notification.Definition, message.Track.Artist)) + if (ShouldHandleArtist(notification.Definition, message.TrackInfo.Artist)) { if (downloadMessage.OldFiles.Empty() || ((NotificationDefinition)notification.Definition).OnUpgrade) { diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index a38629225..f1fd4c39b 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -620,7 +620,6 @@ -