New: Download client and ID for custom scripts

pull/110/head
Qstick 7 years ago
parent cb9af37c39
commit d6bb4c29d0

@ -10,7 +10,9 @@ using NzbDrone.Core.Profiles.Qualities;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.History; using NzbDrone.Core.History;
using NzbDrone.Core.Qualities; using NzbDrone.Core.Qualities;
using System.Collections.Generic;
using NzbDrone.Core.Test.Qualities; using NzbDrone.Core.Test.Qualities;
using NzbDrone.Core.Download;
using NzbDrone.Core.Music; using NzbDrone.Core.Music;
using NzbDrone.Core.Languages; using NzbDrone.Core.Languages;
using NzbDrone.Core.Profiles.Languages; using NzbDrone.Core.Profiles.Languages;
@ -67,7 +69,13 @@ namespace NzbDrone.Core.Test.HistoryTests
Path = @"C:\Test\Unsorted\Artist.01.Hymn.mp3" 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<TrackFile>(), true, downloadClientItem));
Mocker.GetMock<IHistoryRepository>() Mocker.GetMock<IHistoryRepository>()
.Verify(v => v.Insert(It.Is<History.History>(h => h.SourceTitle == Path.GetFileNameWithoutExtension(localTrack.Path)))); .Verify(v => v.Insert(It.Is<History.History>(h => h.SourceTitle == Path.GetFileNameWithoutExtension(localTrack.Path))));

@ -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<TrackFile> OldFiles { get; private set; }
public TrackDownloadedEvent(LocalTrack track, TrackFile trackFile, List<TrackFile> oldFiles)
{
Track = track;
TrackFile = trackFile;
OldFiles = oldFiles;
}
}
}

@ -1,9 +1,7 @@
using System.Collections.Generic;
using NzbDrone.Common.Messaging; using NzbDrone.Common.Messaging;
using NzbDrone.Core.Download;
using NzbDrone.Core.Parser.Model; using NzbDrone.Core.Parser.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Core.MediaFiles.Events namespace NzbDrone.Core.MediaFiles.Events
{ {
@ -11,24 +9,24 @@ namespace NzbDrone.Core.MediaFiles.Events
{ {
public LocalTrack TrackInfo { get; private set; } public LocalTrack TrackInfo { get; private set; }
public TrackFile ImportedTrack { get; private set; } public TrackFile ImportedTrack { get; private set; }
public List<TrackFile> 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 TrackImportedEvent(LocalTrack trackInfo, TrackFile importedTrack, bool newDownload) public TrackImportedEvent(LocalTrack trackInfo, TrackFile importedTrack, List<TrackFile> oldFiles, bool newDownload, DownloadClientItem downloadClientItem)
{ {
TrackInfo = trackInfo; TrackInfo = trackInfo;
ImportedTrack = importedTrack; ImportedTrack = importedTrack;
OldFiles = oldFiles;
NewDownload = newDownload; NewDownload = newDownload;
}
public TrackImportedEvent(LocalTrack trackInfo, TrackFile importedTrack, bool newDownload, string downloadClient, string downloadId) if (downloadClientItem != null)
{ {
TrackInfo = trackInfo; DownloadClient = downloadClientItem.DownloadClient;
ImportedTrack = importedTrack; DownloadId = downloadClientItem.DownloadId;
NewDownload = newDownload; }
DownloadClient = downloadClient;
DownloadId = downloadId;
} }
} }
} }

@ -124,19 +124,8 @@ namespace NzbDrone.Core.MediaFiles.TrackImport
// _extraService.ImportExtraFiles(localTrack, trackFile, copyOnly); // TODO: Import Music Extras // _extraService.ImportExtraFiles(localTrack, trackFile, copyOnly); // TODO: Import Music Extras
//} //}
if (downloadClientItem != null) _eventAggregator.PublishEvent(new TrackImportedEvent(localTrack, trackFile, oldFiles, newDownload, downloadClientItem));
{
_eventAggregator.PublishEvent(new TrackImportedEvent(localTrack, trackFile, newDownload, downloadClientItem.DownloadClient, downloadClientItem.DownloadId));
}
else
{
_eventAggregator.PublishEvent(new TrackImportedEvent(localTrack, trackFile, newDownload));
}
if (newDownload)
{
_eventAggregator.PublishEvent(new TrackDownloadedEvent(localTrack, trackFile, oldFiles));
}
} }
catch (Exception e) catch (Exception e)
{ {

@ -49,6 +49,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
environmentVariables.Add("Lidarr_Release_Quality", remoteAlbum.ParsedAlbumInfo.Quality.Quality.Name); 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_QualityVersion", remoteAlbum.ParsedAlbumInfo.Quality.Revision.Version.ToString());
environmentVariables.Add("Lidarr_Release_ReleaseGroup", releaseGroup); 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); ExecuteScript(environmentVariables);
} }
@ -80,6 +82,8 @@ namespace NzbDrone.Core.Notifications.CustomScript
environmentVariables.Add("Lidarr_TrackFile_SceneName", trackFile.SceneName ?? string.Empty); environmentVariables.Add("Lidarr_TrackFile_SceneName", trackFile.SceneName ?? string.Empty);
environmentVariables.Add("Lidarr_TrackFile_SourcePath", sourcePath); environmentVariables.Add("Lidarr_TrackFile_SourcePath", sourcePath);
environmentVariables.Add("Lidarr_TrackFile_SourceFolder", Path.GetDirectoryName(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()) if (message.OldFiles.Any())
{ {

@ -11,6 +11,8 @@ namespace NzbDrone.Core.Notifications
public TrackFile TrackFile { get; set; } public TrackFile TrackFile { get; set; }
public List<TrackFile> OldFiles { get; set; } public List<TrackFile> 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()
{ {

@ -10,6 +10,8 @@ namespace NzbDrone.Core.Notifications
public Artist Artist { get; set; } public Artist Artist { get; set; }
public RemoteAlbum Album { 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() public override string ToString()
{ {

@ -14,7 +14,7 @@ namespace NzbDrone.Core.Notifications
{ {
public class NotificationService public class NotificationService
: IHandle<AlbumGrabbedEvent>, : IHandle<AlbumGrabbedEvent>,
IHandle<TrackDownloadedEvent>, IHandle<TrackImportedEvent>,
IHandle<ArtistRenamedEvent> IHandle<ArtistRenamedEvent>
{ {
private readonly INotificationFactory _notificationFactory; private readonly INotificationFactory _notificationFactory;
@ -88,7 +88,9 @@ namespace NzbDrone.Core.Notifications
Message = GetMessage(message.Album.Artist, message.Album.Albums, message.Album.ParsedAlbumInfo.Quality), Message = GetMessage(message.Album.Artist, message.Album.Albums, message.Album.ParsedAlbumInfo.Quality),
Artist = message.Album.Artist, Artist = message.Album.Artist,
Quality = message.Album.ParsedAlbumInfo.Quality, Quality = message.Album.ParsedAlbumInfo.Quality,
Album = message.Album Album = message.Album,
DownloadClient = message.DownloadClient,
DownloadId = message.DownloadId
}; };
foreach (var notification in _notificationFactory.OnGrabEnabled()) 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(); if (!message.NewDownload)
downloadMessage.Message = GetTrackMessage(message.Track.Artist, message.Track.Tracks, message.Track.Quality); {
downloadMessage.Artist = message.Track.Artist; return;
downloadMessage.TrackFile = message.TrackFile; }
downloadMessage.OldFiles = message.OldFiles;
downloadMessage.SourcePath = message.Track.Path; 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()) foreach (var notification in _notificationFactory.OnDownloadEnabled())
{ {
try try
{ {
if (ShouldHandleArtist(notification.Definition, message.Track.Artist)) if (ShouldHandleArtist(notification.Definition, message.TrackInfo.Artist))
{ {
if (downloadMessage.OldFiles.Empty() || ((NotificationDefinition)notification.Definition).OnUpgrade) if (downloadMessage.OldFiles.Empty() || ((NotificationDefinition)notification.Definition).OnUpgrade)
{ {

@ -620,7 +620,6 @@
<Compile Include="MediaFiles\Commands\DownloadedAlbumsScanCommand.cs" /> <Compile Include="MediaFiles\Commands\DownloadedAlbumsScanCommand.cs" />
<Compile Include="MediaFiles\Commands\RenameArtistCommand.cs" /> <Compile Include="MediaFiles\Commands\RenameArtistCommand.cs" />
<Compile Include="MediaFiles\Events\TrackFolderCreatedEvent.cs" /> <Compile Include="MediaFiles\Events\TrackFolderCreatedEvent.cs" />
<Compile Include="MediaFiles\Events\TrackDownloadedEvent.cs" />
<Compile Include="MediaFiles\MediaFileDeletionService.cs" /> <Compile Include="MediaFiles\MediaFileDeletionService.cs" />
<Compile Include="MediaFiles\MediaInfo\MediaInfoFormatter.cs" /> <Compile Include="MediaFiles\MediaInfo\MediaInfoFormatter.cs" />
<Compile Include="MediaFiles\RenameTrackFilePreview.cs" /> <Compile Include="MediaFiles\RenameTrackFilePreview.cs" />

Loading…
Cancel
Save