1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-08-16 23:39:44 +02:00

New: Download client and ID for custom scripts

This commit is contained in:
Mark McDowall 2017-06-03 09:36:17 -07:00 committed by Mark McDowall
parent 62bc63312d
commit eea3419849
10 changed files with 58 additions and 59 deletions

View File

@ -14,7 +14,7 @@ namespace NzbDrone.Api.Episodes
{ {
public abstract class EpisodeModuleWithSignalR : NzbDroneRestModuleWithSignalR<EpisodeResource, Episode>, public abstract class EpisodeModuleWithSignalR : NzbDroneRestModuleWithSignalR<EpisodeResource, Episode>,
IHandle<EpisodeGrabbedEvent>, IHandle<EpisodeGrabbedEvent>,
IHandle<EpisodeDownloadedEvent> IHandle<EpisodeImportedEvent>
{ {
protected readonly IEpisodeService _episodeService; protected readonly IEpisodeService _episodeService;
protected readonly ISeriesService _seriesService; protected readonly ISeriesService _seriesService;
@ -115,9 +115,14 @@ public void Handle(EpisodeGrabbedEvent message)
} }
} }
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); BroadcastResourceChange(ModelAction.Updated, episode.Id);
} }

View File

@ -13,6 +13,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using NzbDrone.Core.Test.Qualities; using NzbDrone.Core.Test.Qualities;
using FluentAssertions; using FluentAssertions;
using NzbDrone.Core.Download;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.HistoryTests namespace NzbDrone.Core.Test.HistoryTests
@ -81,7 +82,13 @@ public void should_use_file_name_for_source_title_if_scene_name_is_null()
Path = @"C:\Test\Unsorted\Series.s01e01.mkv" 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>() Mocker.GetMock<IHistoryRepository>()
.Verify(v => v.Insert(It.Is<History.History>(h => h.SourceTitle == Path.GetFileNameWithoutExtension(localEpisode.Path)))); .Verify(v => v.Insert(It.Is<History.History>(h => h.SourceTitle == Path.GetFileNameWithoutExtension(localEpisode.Path))));

View File

@ -120,19 +120,7 @@ public List<ImportResult> Import(List<ImportDecision> decisions, bool newDownloa
_extraService.ImportExtraFiles(localEpisode, episodeFile, copyOnly); _extraService.ImportExtraFiles(localEpisode, episodeFile, copyOnly);
} }
if (downloadClientItem != null) _eventAggregator.PublishEvent(new EpisodeImportedEvent(localEpisode, episodeFile, oldFiles, newDownload, downloadClientItem));
{
_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));
}
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -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;
}
}
}

View File

@ -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; using NzbDrone.Core.Parser.Model;
namespace NzbDrone.Core.MediaFiles.Events namespace NzbDrone.Core.MediaFiles.Events
@ -7,24 +9,23 @@ public class EpisodeImportedEvent : IEvent
{ {
public LocalEpisode EpisodeInfo { get; private set; } public LocalEpisode EpisodeInfo { get; private set; }
public EpisodeFile ImportedEpisode { get; private set; } public EpisodeFile ImportedEpisode { get; private set; }
public List<EpisodeFile> OldFiles { get; private set; }
public bool NewDownload { get; private set; } public bool NewDownload { get; private set; }
public string DownloadClient { get; private set; } public string DownloadClient { get; private set; }
public string DownloadId { 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; EpisodeInfo = episodeInfo;
ImportedEpisode = importedEpisode; ImportedEpisode = importedEpisode;
OldFiles = oldFiles;
NewDownload = newDownload; NewDownload = newDownload;
}
public EpisodeImportedEvent(LocalEpisode episodeInfo, EpisodeFile importedEpisode, bool newDownload, string downloadClient, string downloadId) if (downloadClientItem != null)
{ {
EpisodeInfo = episodeInfo; DownloadClient = downloadClientItem.DownloadClient;
ImportedEpisode = importedEpisode; DownloadId = downloadClientItem.DownloadId;
NewDownload = newDownload; }
DownloadClient = downloadClient;
DownloadId = downloadId;
} }
} }
} }

View File

@ -54,6 +54,8 @@ public override void OnGrab(GrabMessage message)
environmentVariables.Add("Sonarr_Release_Quality", remoteEpisode.ParsedEpisodeInfo.Quality.Quality.Name); 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_QualityVersion", remoteEpisode.ParsedEpisodeInfo.Quality.Revision.Version.ToString());
environmentVariables.Add("Sonarr_Release_ReleaseGroup", releaseGroup); 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); ExecuteScript(environmentVariables);
} }
@ -89,6 +91,8 @@ public override void OnDownload(DownloadMessage message)
environmentVariables.Add("Sonarr_EpisodeFile_SceneName", episodeFile.SceneName ?? string.Empty); environmentVariables.Add("Sonarr_EpisodeFile_SceneName", episodeFile.SceneName ?? string.Empty);
environmentVariables.Add("Sonarr_EpisodeFile_SourcePath", sourcePath); environmentVariables.Add("Sonarr_EpisodeFile_SourcePath", sourcePath);
environmentVariables.Add("Sonarr_EpisodeFile_SourceFolder", Path.GetDirectoryName(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()) if (message.OldFiles.Any())
{ {

View File

@ -11,6 +11,8 @@ public class DownloadMessage
public EpisodeFile EpisodeFile { get; set; } public EpisodeFile EpisodeFile { get; set; }
public List<EpisodeFile> OldFiles { get; set; } public List<EpisodeFile> OldFiles { get; set; }
public string SourcePath { get; set; } public string SourcePath { get; set; }
public string DownloadClient { get; set; }
public string DownloadId { get; set; }
public override string ToString() public override string ToString()
{ {

View File

@ -10,6 +10,8 @@ public class GrabMessage
public Series Series { get; set; } public Series Series { get; set; }
public RemoteEpisode Episode { get; set; } public RemoteEpisode Episode { 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() public override string ToString()
{ {

View File

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

View File

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