mirror of https://github.com/lidarr/Lidarr
New: Download client and ID for custom scripts
This commit is contained in:
parent
cb9af37c39
commit
d6bb4c29d0
|
@ -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<TrackFile>(), true, downloadClientItem));
|
||||
|
||||
Mocker.GetMock<IHistoryRepository>()
|
||||
.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 NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
|
||||
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<TrackFile> 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<TrackFile> 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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())
|
||||
{
|
||||
|
|
|
@ -11,6 +11,8 @@ namespace NzbDrone.Core.Notifications
|
|||
public TrackFile TrackFile { get; set; }
|
||||
public List<TrackFile> 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 @@ 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()
|
||||
{
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace NzbDrone.Core.Notifications
|
|||
{
|
||||
public class NotificationService
|
||||
: IHandle<AlbumGrabbedEvent>,
|
||||
IHandle<TrackDownloadedEvent>,
|
||||
IHandle<TrackImportedEvent>,
|
||||
IHandle<ArtistRenamedEvent>
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
|
|
@ -620,7 +620,6 @@
|
|||
<Compile Include="MediaFiles\Commands\DownloadedAlbumsScanCommand.cs" />
|
||||
<Compile Include="MediaFiles\Commands\RenameArtistCommand.cs" />
|
||||
<Compile Include="MediaFiles\Events\TrackFolderCreatedEvent.cs" />
|
||||
<Compile Include="MediaFiles\Events\TrackDownloadedEvent.cs" />
|
||||
<Compile Include="MediaFiles\MediaFileDeletionService.cs" />
|
||||
<Compile Include="MediaFiles\MediaInfo\MediaInfoFormatter.cs" />
|
||||
<Compile Include="MediaFiles\RenameTrackFilePreview.cs" />
|
||||
|
|
Loading…
Reference in New Issue