mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
New: Download client and ID for custom scripts
This commit is contained in:
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 @@ 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);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
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 @@ public void should_use_file_name_for_source_title_if_scene_name_is_null()
|
||||
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 @@ public List<ImportResult> Import(List<ImportDecision> decisions, bool newDownloa
|
||||
_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 @@ public class EpisodeImportedEvent : IEvent
|
||||
{
|
||||
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)
|
||||
{
|
||||
EpisodeInfo = episodeInfo;
|
||||
ImportedEpisode = importedEpisode;
|
||||
NewDownload = newDownload;
|
||||
DownloadClient = downloadClient;
|
||||
DownloadId = downloadId;
|
||||
if (downloadClientItem != null)
|
||||
{
|
||||
DownloadClient = downloadClientItem.DownloadClient;
|
||||
DownloadId = downloadClientItem.DownloadId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -54,6 +54,8 @@ public override void OnGrab(GrabMessage message)
|
||||
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 @@ public override void OnDownload(DownloadMessage message)
|
||||
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 @@ public class DownloadMessage
|
||||
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()
|
||||
{
|
||||
|
@ -9,7 +9,9 @@ public class GrabMessage
|
||||
public string Message { get; set; }
|
||||
public Series Series { 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()
|
||||
{
|
||||
|
@ -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 @@ public void Handle(EpisodeGrabbedEvent message)
|
||||
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 @@ public void Handle(EpisodeGrabbedEvent message)
|
||||
}
|
||||
}
|
||||
|
||||
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…
Reference in New Issue
Block a user