New: Download client and ID for custom scripts

pull/2279/head
Mark McDowall 8 years ago committed by Mark McDowall
parent 62bc63312d
commit eea3419849

@ -14,7 +14,7 @@ namespace NzbDrone.Api.Episodes
{
public abstract class EpisodeModuleWithSignalR : NzbDroneRestModuleWithSignalR<EpisodeResource, Episode>,
IHandle<EpisodeGrabbedEvent>,
IHandle<EpisodeDownloadedEvent>
IHandle<EpisodeImportedEvent>
{
protected readonly IEpisodeService _episodeService;
protected readonly ISeriesService _seriesService;
@ -115,9 +115,14 @@ namespace NzbDrone.Api.Episodes
}
}
public void Handle(EpisodeDownloadedEvent message)
public void Handle(EpisodeImportedEvent message)
{
foreach (var episode in message.Episode.Episodes)
if (!message.NewDownload)
{
return;
}
foreach (var episode in message.EpisodeInfo.Episodes)
{
BroadcastResourceChange(ModelAction.Updated, episode.Id);
}

@ -13,6 +13,7 @@ using NzbDrone.Core.Qualities;
using System.Collections.Generic;
using NzbDrone.Core.Test.Qualities;
using FluentAssertions;
using NzbDrone.Core.Download;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.HistoryTests
@ -81,7 +82,13 @@ namespace NzbDrone.Core.Test.HistoryTests
Path = @"C:\Test\Unsorted\Series.s01e01.mkv"
};
Subject.Handle(new EpisodeImportedEvent(localEpisode, episodeFile, true, "sab", "abcd"));
var downloadClientItem = new DownloadClientItem
{
DownloadClient = "sab",
DownloadId = "abcd"
};
Subject.Handle(new EpisodeImportedEvent(localEpisode, episodeFile, new List<EpisodeFile>(), true, downloadClientItem));
Mocker.GetMock<IHistoryRepository>()
.Verify(v => v.Insert(It.Is<History.History>(h => h.SourceTitle == Path.GetFileNameWithoutExtension(localEpisode.Path))));

@ -120,19 +120,7 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport
_extraService.ImportExtraFiles(localEpisode, episodeFile, copyOnly);
}
if (downloadClientItem != null)
{
_eventAggregator.PublishEvent(new EpisodeImportedEvent(localEpisode, episodeFile, newDownload, downloadClientItem.DownloadClient, downloadClientItem.DownloadId));
}
else
{
_eventAggregator.PublishEvent(new EpisodeImportedEvent(localEpisode, episodeFile, newDownload));
}
if (newDownload)
{
_eventAggregator.PublishEvent(new EpisodeDownloadedEvent(localEpisode, episodeFile, oldFiles));
}
_eventAggregator.PublishEvent(new EpisodeImportedEvent(localEpisode, episodeFile, oldFiles, newDownload, downloadClientItem));
}
catch (Exception e)
{

@ -1,20 +0,0 @@
using System.Collections.Generic;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.Events
{
public class EpisodeDownloadedEvent : IEvent
{
public LocalEpisode Episode { get; private set; }
public EpisodeFile EpisodeFile { get; private set; }
public List<EpisodeFile> OldFiles { get; private set; }
public EpisodeDownloadedEvent(LocalEpisode episode, EpisodeFile episodeFile, List<EpisodeFile> oldFiles)
{
Episode = episode;
EpisodeFile = episodeFile;
OldFiles = oldFiles;
}
}
}

@ -1,4 +1,6 @@
using NzbDrone.Common.Messaging;
using System.Collections.Generic;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.Events
@ -7,24 +9,23 @@ namespace NzbDrone.Core.MediaFiles.Events
{
public LocalEpisode EpisodeInfo { get; private set; }
public EpisodeFile ImportedEpisode { get; private set; }
public List<EpisodeFile> OldFiles { get; private set; }
public bool NewDownload { get; private set; }
public string DownloadClient { get; private set; }
public string DownloadId { get; private set; }
public EpisodeImportedEvent(LocalEpisode episodeInfo, EpisodeFile importedEpisode, bool newDownload)
public EpisodeImportedEvent(LocalEpisode episodeInfo, EpisodeFile importedEpisode, List<EpisodeFile> oldFiles, bool newDownload, DownloadClientItem downloadClientItem)
{
EpisodeInfo = episodeInfo;
ImportedEpisode = importedEpisode;
OldFiles = oldFiles;
NewDownload = newDownload;
}
public EpisodeImportedEvent(LocalEpisode episodeInfo, EpisodeFile importedEpisode, bool newDownload, string downloadClient, string downloadId)
if (downloadClientItem != null)
{
EpisodeInfo = episodeInfo;
ImportedEpisode = importedEpisode;
NewDownload = newDownload;
DownloadClient = downloadClient;
DownloadId = downloadId;
DownloadClient = downloadClientItem.DownloadClient;
DownloadId = downloadClientItem.DownloadId;
}
}
}
}

@ -54,6 +54,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
environmentVariables.Add("Sonarr_Release_Quality", remoteEpisode.ParsedEpisodeInfo.Quality.Quality.Name);
environmentVariables.Add("Sonarr_Release_QualityVersion", remoteEpisode.ParsedEpisodeInfo.Quality.Revision.Version.ToString());
environmentVariables.Add("Sonarr_Release_ReleaseGroup", releaseGroup);
environmentVariables.Add("Sonarr_Download_Client", message.DownloadClient ?? string.Empty);
environmentVariables.Add("Sonarr_Download_Id", message.DownloadId ?? string.Empty);
ExecuteScript(environmentVariables);
}
@ -89,6 +91,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
environmentVariables.Add("Sonarr_EpisodeFile_SceneName", episodeFile.SceneName ?? string.Empty);
environmentVariables.Add("Sonarr_EpisodeFile_SourcePath", sourcePath);
environmentVariables.Add("Sonarr_EpisodeFile_SourceFolder", Path.GetDirectoryName(sourcePath));
environmentVariables.Add("Sonarr_Download_Client", message.DownloadClient ?? string.Empty);
environmentVariables.Add("Sonarr_Download_Id", message.DownloadId ?? string.Empty);
if (message.OldFiles.Any())
{

@ -11,6 +11,8 @@ namespace NzbDrone.Core.Notifications
public EpisodeFile EpisodeFile { get; set; }
public List<EpisodeFile> OldFiles { get; set; }
public string SourcePath { get; set; }
public string DownloadClient { get; set; }
public string DownloadId { get; set; }
public override string ToString()
{

@ -10,6 +10,8 @@ namespace NzbDrone.Core.Notifications
public Series Series { get; set; }
public RemoteEpisode Episode { get; set; }
public QualityModel Quality { get; set; }
public string DownloadClient { get; set; }
public string DownloadId { get; set; }
public override string ToString()
{

@ -14,7 +14,7 @@ namespace NzbDrone.Core.Notifications
{
public class NotificationService
: IHandle<EpisodeGrabbedEvent>,
IHandle<EpisodeDownloadedEvent>,
IHandle<EpisodeImportedEvent>,
IHandle<SeriesRenamedEvent>
{
private readonly INotificationFactory _notificationFactory;
@ -95,7 +95,9 @@ namespace NzbDrone.Core.Notifications
Message = GetMessage(message.Episode.Series, message.Episode.Episodes, message.Episode.ParsedEpisodeInfo.Quality),
Series = message.Episode.Series,
Quality = message.Episode.ParsedEpisodeInfo.Quality,
Episode = message.Episode
Episode = message.Episode,
DownloadClient = message.DownloadClient,
DownloadId = message.DownloadId
};
foreach (var notification in _notificationFactory.OnGrabEnabled())
@ -113,20 +115,29 @@ namespace NzbDrone.Core.Notifications
}
}
public void Handle(EpisodeDownloadedEvent message)
public void Handle(EpisodeImportedEvent message)
{
var downloadMessage = new DownloadMessage();
downloadMessage.Message = GetMessage(message.Episode.Series, message.Episode.Episodes, message.Episode.Quality);
downloadMessage.Series = message.Episode.Series;
downloadMessage.EpisodeFile = message.EpisodeFile;
downloadMessage.OldFiles = message.OldFiles;
downloadMessage.SourcePath = message.Episode.Path;
if (!message.NewDownload)
{
return;
}
var downloadMessage = new DownloadMessage
{
Message = GetMessage(message.EpisodeInfo.Series, message.EpisodeInfo.Episodes, message.EpisodeInfo.Quality),
Series = message.EpisodeInfo.Series,
EpisodeFile = message.ImportedEpisode,
OldFiles = message.OldFiles,
SourcePath = message.EpisodeInfo.Path,
DownloadClient = message.DownloadClient,
DownloadId = message.DownloadId
};
foreach (var notification in _notificationFactory.OnDownloadEnabled())
{
try
{
if (ShouldHandleSeries(notification.Definition, message.Episode.Series))
if (ShouldHandleSeries(notification.Definition, message.EpisodeInfo.Series))
{
if (downloadMessage.OldFiles.Empty() || ((NotificationDefinition)notification.Definition).OnUpgrade)
{

@ -782,7 +782,6 @@
<Compile Include="MediaFiles\EpisodeImport\Specifications\SameEpisodesImportSpecification.cs" />
<Compile Include="MediaFiles\EpisodeImport\Specifications\UnverifiedSceneNumberingSpecification.cs" />
<Compile Include="MediaFiles\EpisodeImport\Specifications\UpgradeSpecification.cs" />
<Compile Include="MediaFiles\Events\EpisodeDownloadedEvent.cs" />
<Compile Include="MediaFiles\Events\EpisodeFileAddedEvent.cs" />
<Compile Include="MediaFiles\Events\EpisodeFileDeletedEvent.cs" />
<Compile Include="MediaFiles\Events\EpisodeFolderCreatedEvent.cs" />

Loading…
Cancel
Save