New: Genres and Images for Webhooks and Notifiarr

(cherry picked from commit fd3dd1ab7dc86cd9e231fa432cc8d2772d5a4bad)

Closes #4832
pull/5107/head
Mark McDowall 11 months ago committed by Bogdan
parent 36998abba0
commit 261f30d268

@ -2,6 +2,7 @@ using System.Collections.Generic;
using FluentValidation.Results;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaCover;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Music;
using NzbDrone.Core.Notifications.Webhook;
@ -13,8 +14,8 @@ namespace NzbDrone.Core.Notifications.Notifiarr
{
private readonly INotifiarrProxy _proxy;
public Notifiarr(INotifiarrProxy proxy, IConfigFileProvider configFileProvider, IConfigService configService)
: base(configFileProvider, configService)
public Notifiarr(INotifiarrProxy proxy, IConfigFileProvider configFileProvider, IConfigService configService, IMapCoversToLocal mediaCoverService)
: base(configFileProvider, configService, mediaCoverService)
{
_proxy = proxy;
}

@ -2,6 +2,7 @@ using System.Collections.Generic;
using FluentValidation.Results;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaCover;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Music;
using NzbDrone.Core.Validation;
@ -12,8 +13,8 @@ namespace NzbDrone.Core.Notifications.Webhook
{
private readonly IWebhookProxy _proxy;
public Webhook(IWebhookProxy proxy, IConfigFileProvider configFileProvider, IConfigService configService)
: base(configFileProvider, configService)
public Webhook(IWebhookProxy proxy, IConfigFileProvider configFileProvider, IConfigService configService, IMapCoversToLocal mediaCoverService)
: base(configFileProvider, configService, mediaCoverService)
{
_proxy = proxy;
}

@ -7,6 +7,17 @@ namespace NzbDrone.Core.Notifications.Webhook
{
public class WebhookAlbum
{
public int Id { get; set; }
public string MBId { get; set; }
public string Title { get; set; }
public string Disambiguation { get; set; }
public string Overview { get; set; }
public string AlbumType { get; set; }
public List<string> SecondaryAlbumTypes { get; set; }
public DateTime? ReleaseDate { get; set; }
public List<string> Genres { get; set; }
public List<WebhookImage> Images { get; set; }
public WebhookAlbum()
{
}
@ -20,18 +31,9 @@ namespace NzbDrone.Core.Notifications.Webhook
Overview = album.Overview;
AlbumType = album.AlbumType;
SecondaryAlbumTypes = album.SecondaryTypes.Select(x => x.Name).ToList();
Genres = album.Genres;
ReleaseDate = album.ReleaseDate;
Genres = album.Genres;
Images = album.Images.Select(i => new WebhookImage(i)).ToList();
}
public int Id { get; set; }
public string MBId { get; set; }
public string Title { get; set; }
public string Disambiguation { get; set; }
public string Overview { get; set; }
public string AlbumType { get; set; }
public List<string> SecondaryAlbumTypes { get; set; }
public List<string> Genres { get; set; }
public DateTime? ReleaseDate { get; set; }
}
}

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Core.Music;
namespace NzbDrone.Core.Notifications.Webhook
@ -13,6 +14,7 @@ namespace NzbDrone.Core.Notifications.Webhook
public string Type { get; set; }
public string Overview { get; set; }
public List<string> Genres { get; set; }
public List<WebhookImage> Images { get; set; }
public WebhookArtist()
{
@ -24,10 +26,11 @@ namespace NzbDrone.Core.Notifications.Webhook
Name = artist.Name;
Disambiguation = artist.Metadata.Value.Disambiguation;
Path = artist.Path;
MBId = artist.Metadata.Value.ForeignArtistId;
Type = artist.Metadata.Value.Type;
Overview = artist.Metadata.Value.Overview;
Genres = artist.Metadata.Value.Genres;
MBId = artist.Metadata.Value.ForeignArtistId;
Images = artist.Metadata.Value.Images.Select(i => new WebhookImage(i)).ToList();
}
}
}

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaCover;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Music;
using NzbDrone.Core.ThingiProvider;
@ -12,11 +13,13 @@ namespace NzbDrone.Core.Notifications.Webhook
{
private readonly IConfigFileProvider _configFileProvider;
private readonly IConfigService _configService;
private readonly IMapCoversToLocal _mediaCoverService;
protected WebhookBase(IConfigFileProvider configFileProvider, IConfigService configService)
protected WebhookBase(IConfigFileProvider configFileProvider, IConfigService configService, IMapCoversToLocal mediaCoverService)
{
_configFileProvider = configFileProvider;
_configService = configService;
_mediaCoverService = mediaCoverService;
}
public WebhookGrabPayload BuildOnGrabPayload(GrabMessage message)
@ -29,8 +32,8 @@ namespace NzbDrone.Core.Notifications.Webhook
EventType = WebhookEventType.Grab,
InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Artist = new WebhookArtist(message.Artist),
Albums = remoteAlbum.Albums.Select(x => new WebhookAlbum(x)).ToList(),
Artist = GetArtist(message.Artist),
Albums = remoteAlbum.Albums.Select(GetAlbum).ToList(),
Release = new WebhookRelease(quality, remoteAlbum),
DownloadClient = message.DownloadClientName,
DownloadClientType = message.DownloadClientType,
@ -47,8 +50,8 @@ namespace NzbDrone.Core.Notifications.Webhook
EventType = WebhookEventType.Download,
InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Artist = new WebhookArtist(message.Artist),
Album = new WebhookAlbum(message.Album),
Artist = GetArtist(message.Artist),
Album = GetAlbum(message.Album),
Tracks = trackFiles.SelectMany(x => x.Tracks.Value.Select(y => new WebhookTrack(y))).ToList(),
TrackFiles = trackFiles.ConvertAll(x => new WebhookTrackFile(x)),
IsUpgrade = message.OldFiles.Any(),
@ -89,7 +92,7 @@ namespace NzbDrone.Core.Notifications.Webhook
EventType = WebhookEventType.ImportFailure,
InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Artist = new WebhookArtist(message.Artist),
Artist = GetArtist(message.Artist),
Tracks = trackFiles.SelectMany(x => x.Tracks.Value.Select(y => new WebhookTrack(y))).ToList(),
TrackFiles = trackFiles.ConvertAll(x => new WebhookTrackFile(x)),
IsUpgrade = message.OldFiles.Any(),
@ -113,7 +116,7 @@ namespace NzbDrone.Core.Notifications.Webhook
EventType = WebhookEventType.Rename,
InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Artist = new WebhookArtist(artist),
Artist = GetArtist(artist),
RenamedTrackFiles = renamedFiles.ConvertAll(x => new WebhookRenamedTrackFile(x))
};
}
@ -125,7 +128,7 @@ namespace NzbDrone.Core.Notifications.Webhook
EventType = WebhookEventType.Retag,
InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Artist = new WebhookArtist(message.Artist),
Artist = GetArtist(message.Artist),
TrackFile = new WebhookTrackFile(message.TrackFile)
};
}
@ -137,7 +140,7 @@ namespace NzbDrone.Core.Notifications.Webhook
EventType = WebhookEventType.ArtistAdd,
InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Artist = new WebhookArtist(addMessage.Artist),
Artist = GetArtist(addMessage.Artist),
};
}
@ -148,7 +151,7 @@ namespace NzbDrone.Core.Notifications.Webhook
EventType = WebhookEventType.ArtistDelete,
InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Artist = new WebhookArtist(deleteMessage.Artist),
Artist = GetArtist(deleteMessage.Artist),
DeletedFiles = deleteMessage.DeletedFiles
};
}
@ -160,8 +163,8 @@ namespace NzbDrone.Core.Notifications.Webhook
EventType = WebhookEventType.AlbumDelete,
InstanceName = _configFileProvider.InstanceName,
ApplicationUrl = _configService.ApplicationUrl,
Artist = new WebhookArtist(deleteMessage.Album.Artist),
Album = new WebhookAlbum(deleteMessage.Album),
Artist = GetArtist(deleteMessage.Album.Artist),
Album = GetAlbum(deleteMessage.Album),
DeletedFiles = deleteMessage.DeletedFiles
};
}
@ -230,5 +233,29 @@ namespace NzbDrone.Core.Notifications.Webhook
}
};
}
private WebhookArtist GetArtist(Artist artist)
{
if (artist == null)
{
return null;
}
_mediaCoverService.ConvertToLocalUrls(artist.Id, MediaCoverEntity.Artist, artist.Metadata.Value.Images);
return new WebhookArtist(artist);
}
private WebhookAlbum GetAlbum(Album album)
{
if (album == null)
{
return null;
}
_mediaCoverService.ConvertToLocalUrls(album.Id, MediaCoverEntity.Album, album.Images);
return new WebhookAlbum(album);
}
}
}

@ -0,0 +1,18 @@
using NzbDrone.Core.MediaCover;
namespace NzbDrone.Core.Notifications.Webhook
{
public class WebhookImage
{
public MediaCoverTypes CoverType { get; set; }
public string Url { get; set; }
public string RemoteUrl { get; set; }
public WebhookImage(MediaCover.MediaCover image)
{
CoverType = image.CoverType;
RemoteUrl = image.RemoteUrl;
Url = image.Url;
}
}
}
Loading…
Cancel
Save