parent
7e863d61ff
commit
6af1ffba50
@ -0,0 +1,10 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Notifications.Webhook
|
||||||
|
{
|
||||||
|
public class WebhookGrabPayload : WebhookPayload
|
||||||
|
{
|
||||||
|
public List<WebhookAlbum> Albums { get; set; }
|
||||||
|
public WebhookRelease Release { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Notifications.Webhook
|
||||||
|
{
|
||||||
|
public class WebhookImportPayload : WebhookPayload
|
||||||
|
{
|
||||||
|
public List<WebhookTrack> Tracks { get; set; }
|
||||||
|
public WebhookTrackFile TrackFile { get; set; }
|
||||||
|
public bool IsUpgrade { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,8 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Notifications.Webhook
|
namespace NzbDrone.Core.Notifications.Webhook
|
||||||
{
|
{
|
||||||
public class WebhookPayload
|
public class WebhookPayload
|
||||||
{
|
{
|
||||||
public string EventType { get; set; }
|
public string EventType { get; set; }
|
||||||
public WebhookArtist Artist { get; set; }
|
public WebhookArtist Artist { get; set; }
|
||||||
public List<WebhookAlbum> Albums { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
using NzbDrone.Common.Http;
|
||||||
|
using NzbDrone.Common.Serializer;
|
||||||
|
using NzbDrone.Core.Rest;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Notifications.Webhook
|
||||||
|
{
|
||||||
|
public interface IWebhookProxy
|
||||||
|
{
|
||||||
|
void SendWebhook(WebhookPayload payload, WebhookSettings settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WebhookProxy : IWebhookProxy
|
||||||
|
{
|
||||||
|
private readonly IHttpClient _httpClient;
|
||||||
|
|
||||||
|
public WebhookProxy(IHttpClient httpClient)
|
||||||
|
{
|
||||||
|
_httpClient = httpClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SendWebhook(WebhookPayload body, WebhookSettings settings)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var request = new HttpRequestBuilder(settings.Url)
|
||||||
|
.Accept(HttpAccept.Json)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
request.Method = (HttpMethod)settings.Method;
|
||||||
|
request.Headers.ContentType = "application/json";
|
||||||
|
request.SetContent(body.ToJson());
|
||||||
|
|
||||||
|
_httpClient.Execute(request);
|
||||||
|
}
|
||||||
|
catch (RestException ex)
|
||||||
|
{
|
||||||
|
throw new WebhookException("Unable to post to webhook: {0}", ex, ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
using NzbDrone.Core.Parser.Model;
|
||||||
|
using NzbDrone.Core.Qualities;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Notifications.Webhook
|
||||||
|
{
|
||||||
|
public class WebhookRelease
|
||||||
|
{
|
||||||
|
public WebhookRelease() { }
|
||||||
|
|
||||||
|
public WebhookRelease(QualityModel quality, RemoteAlbum remoteAlbum)
|
||||||
|
{
|
||||||
|
Quality = quality.Quality.Name;
|
||||||
|
QualityVersion = quality.Revision.Version;
|
||||||
|
ReleaseGroup = remoteAlbum.ParsedAlbumInfo.ReleaseGroup;
|
||||||
|
ReleaseTitle = remoteAlbum.Release.Title;
|
||||||
|
Indexer = remoteAlbum.Release.Indexer;
|
||||||
|
Size = remoteAlbum.Release.Size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Quality { get; set; }
|
||||||
|
public int QualityVersion { get; set; }
|
||||||
|
public string ReleaseGroup { get; set; }
|
||||||
|
public string ReleaseTitle { get; set; }
|
||||||
|
public string Indexer { get; set; }
|
||||||
|
public long Size { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -1,116 +0,0 @@
|
|||||||
using FluentValidation.Results;
|
|
||||||
using NzbDrone.Core.MediaFiles;
|
|
||||||
using NzbDrone.Core.Music;
|
|
||||||
using NzbDrone.Core.Validation;
|
|
||||||
using NzbDrone.Core.Rest;
|
|
||||||
using RestSharp;
|
|
||||||
using NzbDrone.Core.Qualities;
|
|
||||||
using NzbDrone.Core.Parser.Model;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Notifications.Webhook
|
|
||||||
{
|
|
||||||
public interface IWebhookService
|
|
||||||
{
|
|
||||||
void OnDownload(Artist artist, TrackFile trackFile, WebhookSettings settings);
|
|
||||||
void OnRename(Artist artist, WebhookSettings settings);
|
|
||||||
void OnGrab(Artist artist, RemoteAlbum album, QualityModel quality, WebhookSettings settings);
|
|
||||||
ValidationFailure Test(WebhookSettings settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class WebhookService : IWebhookService
|
|
||||||
{
|
|
||||||
public void OnDownload(Artist artist, TrackFile trackFile, WebhookSettings settings)
|
|
||||||
{
|
|
||||||
var payload = new WebhookPayload
|
|
||||||
{
|
|
||||||
EventType = "Download",
|
|
||||||
Artist = new WebhookArtist(artist),
|
|
||||||
Albums = trackFile.Tracks.Value.ConvertAll(x => new WebhookAlbum(x.Album) {
|
|
||||||
Quality = trackFile.Quality.Quality.Name,
|
|
||||||
QualityVersion = trackFile.Quality.Revision.Version,
|
|
||||||
ReleaseGroup = trackFile.ReleaseGroup,
|
|
||||||
SceneName = trackFile.SceneName
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
NotifyWebhook(payload, settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnRename(Artist artist, WebhookSettings settings)
|
|
||||||
{
|
|
||||||
var payload = new WebhookPayload
|
|
||||||
{
|
|
||||||
EventType = "Rename",
|
|
||||||
Artist = new WebhookArtist(artist)
|
|
||||||
};
|
|
||||||
|
|
||||||
NotifyWebhook(payload, settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnGrab(Artist artist, RemoteAlbum album, QualityModel quality, WebhookSettings settings)
|
|
||||||
{
|
|
||||||
var payload = new WebhookPayload
|
|
||||||
{
|
|
||||||
EventType = "Grab",
|
|
||||||
Artist = new WebhookArtist(artist),
|
|
||||||
Albums = album.Albums.ConvertAll(x => new WebhookAlbum(x)
|
|
||||||
{
|
|
||||||
Quality = quality.Quality.Name,
|
|
||||||
QualityVersion = quality.Revision.Version,
|
|
||||||
ReleaseGroup = album.ParsedAlbumInfo.ReleaseGroup
|
|
||||||
})
|
|
||||||
};
|
|
||||||
NotifyWebhook(payload, settings);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void NotifyWebhook(WebhookPayload body, WebhookSettings settings)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
var client = RestClientFactory.BuildClient(settings.Url);
|
|
||||||
var request = new RestRequest((Method) settings.Method);
|
|
||||||
request.RequestFormat = DataFormat.Json;
|
|
||||||
request.AddBody(body);
|
|
||||||
client.ExecuteAndValidate(request);
|
|
||||||
}
|
|
||||||
catch (RestException ex)
|
|
||||||
{
|
|
||||||
throw new WebhookException("Unable to post to webhook: {0}", ex, ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public ValidationFailure Test(WebhookSettings settings)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
NotifyWebhook(
|
|
||||||
new WebhookPayload
|
|
||||||
{
|
|
||||||
EventType = "Test",
|
|
||||||
Artist = new WebhookArtist()
|
|
||||||
{
|
|
||||||
Id = 1,
|
|
||||||
Title = "Test Title",
|
|
||||||
Path = "C:\\testpath",
|
|
||||||
MBId = "1234"
|
|
||||||
},
|
|
||||||
Albums = new List<WebhookAlbum>() {
|
|
||||||
new WebhookAlbum()
|
|
||||||
{
|
|
||||||
Id = 123,
|
|
||||||
Title = "Test title"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
settings
|
|
||||||
);
|
|
||||||
}
|
|
||||||
catch (WebhookException ex)
|
|
||||||
{
|
|
||||||
return new NzbDroneValidationFailure("Url", ex.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,26 @@
|
|||||||
|
using NzbDrone.Core.Music;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Notifications.Webhook
|
||||||
|
{
|
||||||
|
public class WebhookTrack
|
||||||
|
{
|
||||||
|
public WebhookTrack() { }
|
||||||
|
|
||||||
|
public WebhookTrack(Track track)
|
||||||
|
{
|
||||||
|
Id = track.Id;
|
||||||
|
Title = track.Title;
|
||||||
|
TrackNumber = track.TrackNumber;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Title { get; set; }
|
||||||
|
public int TrackNumber { get; set; }
|
||||||
|
|
||||||
|
public string Quality { get; set; }
|
||||||
|
public int QualityVersion { get; set; }
|
||||||
|
public string ReleaseGroup { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
using NzbDrone.Core.MediaFiles;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Notifications.Webhook
|
||||||
|
{
|
||||||
|
public class WebhookTrackFile
|
||||||
|
{
|
||||||
|
public WebhookTrackFile() { }
|
||||||
|
|
||||||
|
public WebhookTrackFile(TrackFile trackFile)
|
||||||
|
{
|
||||||
|
Id = trackFile.Id;
|
||||||
|
RelativePath = trackFile.RelativePath;
|
||||||
|
Path = trackFile.Path;
|
||||||
|
Quality = trackFile.Quality.Quality.Name;
|
||||||
|
QualityVersion = trackFile.Quality.Revision.Version;
|
||||||
|
ReleaseGroup = trackFile.ReleaseGroup;
|
||||||
|
SceneName = trackFile.SceneName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string RelativePath { get; set; }
|
||||||
|
public string Path { get; set; }
|
||||||
|
public string Quality { get; set; }
|
||||||
|
public int QualityVersion { get; set; }
|
||||||
|
public string ReleaseGroup { get; set; }
|
||||||
|
public string SceneName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue