mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 13:33:34 -07:00
New: Add artist tags to Webhook and Notifiarr events
(cherry picked from commit cc0a284660f139d5f47b27a2c389973e5e888587) Closes #4805
This commit is contained in:
parent
261f30d268
commit
860bd04c59
6 changed files with 59 additions and 15 deletions
|
@ -63,7 +63,7 @@ namespace NzbDrone.Core.Notifications.CustomScript
|
|||
environmentVariables.Add("Lidarr_Artist_MBId", artist.Metadata.Value.ForeignArtistId);
|
||||
environmentVariables.Add("Lidarr_Artist_Type", artist.Metadata.Value.Type);
|
||||
environmentVariables.Add("Lidarr_Artist_Genres", string.Join("|", artist.Metadata.Value.Genres));
|
||||
environmentVariables.Add("Lidarr_Artist_Tags", string.Join("|", artist.Tags.Select(t => _tagRepository.Get(t).Label)));
|
||||
environmentVariables.Add("Lidarr_Artist_Tags", string.Join("|", GetTagLabels(artist)));
|
||||
environmentVariables.Add("Lidarr_Release_AlbumCount", remoteAlbum.Albums.Count.ToString());
|
||||
environmentVariables.Add("Lidarr_Release_AlbumReleaseDates", string.Join(",", remoteAlbum.Albums.Select(e => e.ReleaseDate)));
|
||||
environmentVariables.Add("Lidarr_Release_AlbumTitles", string.Join("|", remoteAlbum.Albums.Select(e => e.Title)));
|
||||
|
@ -101,7 +101,7 @@ namespace NzbDrone.Core.Notifications.CustomScript
|
|||
environmentVariables.Add("Lidarr_Artist_MBId", artist.Metadata.Value.ForeignArtistId);
|
||||
environmentVariables.Add("Lidarr_Artist_Type", artist.Metadata.Value.Type);
|
||||
environmentVariables.Add("Lidarr_Artist_Genres", string.Join("|", artist.Metadata.Value.Genres));
|
||||
environmentVariables.Add("Lidarr_Artist_Tags", string.Join("|", artist.Tags.Select(t => _tagRepository.Get(t).Label)));
|
||||
environmentVariables.Add("Lidarr_Artist_Tags", string.Join("|", GetTagLabels(artist)));
|
||||
environmentVariables.Add("Lidarr_Album_Id", album.Id.ToString());
|
||||
environmentVariables.Add("Lidarr_Album_Title", album.Title);
|
||||
environmentVariables.Add("Lidarr_Album_Overview", album.Overview);
|
||||
|
@ -139,7 +139,7 @@ namespace NzbDrone.Core.Notifications.CustomScript
|
|||
environmentVariables.Add("Lidarr_Artist_MBId", artist.Metadata.Value.ForeignArtistId);
|
||||
environmentVariables.Add("Lidarr_Artist_Type", artist.Metadata.Value.Type);
|
||||
environmentVariables.Add("Lidarr_Artist_Genres", string.Join("|", artist.Metadata.Value.Genres));
|
||||
environmentVariables.Add("Lidarr_Artist_Tags", string.Join("|", artist.Tags.Select(t => _tagRepository.Get(t).Label)));
|
||||
environmentVariables.Add("Lidarr_Artist_Tags", string.Join("|", GetTagLabels(artist)));
|
||||
environmentVariables.Add("Lidarr_TrackFile_Ids", string.Join(",", renamedFiles.Select(e => e.TrackFile.Id)));
|
||||
environmentVariables.Add("Lidarr_TrackFile_Paths", string.Join("|", renamedFiles.Select(e => e.TrackFile.Path)));
|
||||
environmentVariables.Add("Lidarr_TrackFile_PreviousPaths", string.Join("|", renamedFiles.Select(e => e.PreviousPath)));
|
||||
|
@ -164,7 +164,7 @@ namespace NzbDrone.Core.Notifications.CustomScript
|
|||
environmentVariables.Add("Lidarr_Artist_MBId", artist.Metadata.Value.ForeignArtistId);
|
||||
environmentVariables.Add("Lidarr_Artist_Type", artist.Metadata.Value.Type);
|
||||
environmentVariables.Add("Lidarr_Artist_Genres", string.Join("|", artist.Metadata.Value.Genres));
|
||||
environmentVariables.Add("Lidarr_Artist_Tags", string.Join("|", artist.Tags.Select(t => _tagRepository.Get(t).Label)));
|
||||
environmentVariables.Add("Lidarr_Artist_Tags", string.Join("|", GetTagLabels(artist)));
|
||||
environmentVariables.Add("Lidarr_Album_Id", album.Id.ToString());
|
||||
environmentVariables.Add("Lidarr_Album_Title", album.Title);
|
||||
environmentVariables.Add("Lidarr_Album_Overview", album.Overview);
|
||||
|
@ -201,7 +201,7 @@ namespace NzbDrone.Core.Notifications.CustomScript
|
|||
environmentVariables.Add("Lidarr_Artist_MBId", artist.Metadata.Value.ForeignArtistId.ToString());
|
||||
environmentVariables.Add("Lidarr_Artist_Type", artist.Metadata.Value.Type);
|
||||
environmentVariables.Add("Lidarr_Artist_Genres", string.Join("|", artist.Metadata.Value.Genres));
|
||||
environmentVariables.Add("Lidarr_Artist_Tags", string.Join("|", artist.Tags.Select(t => _tagRepository.Get(t).Label)));
|
||||
environmentVariables.Add("Lidarr_Artist_Tags", string.Join("|", GetTagLabels(artist)));
|
||||
|
||||
ExecuteScript(environmentVariables);
|
||||
}
|
||||
|
@ -220,7 +220,7 @@ namespace NzbDrone.Core.Notifications.CustomScript
|
|||
environmentVariables.Add("Lidarr_Artist_MBId", artist.Metadata.Value.ForeignArtistId.ToString());
|
||||
environmentVariables.Add("Lidarr_Artist_Type", artist.Metadata.Value.Type);
|
||||
environmentVariables.Add("Lidarr_Artist_Genres", string.Join("|", artist.Metadata.Value.Genres));
|
||||
environmentVariables.Add("Lidarr_Artist_Tags", string.Join("|", artist.Tags.Select(t => _tagRepository.Get(t).Label)));
|
||||
environmentVariables.Add("Lidarr_Artist_Tags", string.Join("|", GetTagLabels(artist)));
|
||||
environmentVariables.Add("Lidarr_Artist_DeletedFiles", deleteMessage.DeletedFiles.ToString());
|
||||
|
||||
ExecuteScript(environmentVariables);
|
||||
|
@ -241,7 +241,7 @@ namespace NzbDrone.Core.Notifications.CustomScript
|
|||
environmentVariables.Add("Lidarr_Artist_MBId", artist.Metadata.Value.ForeignArtistId);
|
||||
environmentVariables.Add("Lidarr_Artist_Type", artist.Metadata.Value.Type);
|
||||
environmentVariables.Add("Lidarr_Artist_Genres", string.Join("|", artist.Metadata.Value.Genres));
|
||||
environmentVariables.Add("Lidarr_Artist_Tags", string.Join("|", artist.Tags.Select(t => _tagRepository.Get(t).Label)));
|
||||
environmentVariables.Add("Lidarr_Artist_Tags", string.Join("|", GetTagLabels(artist)));
|
||||
environmentVariables.Add("Lidarr_Album_Id", album.Id.ToString());
|
||||
environmentVariables.Add("Lidarr_Album_Title", album.Title);
|
||||
environmentVariables.Add("Lidarr_Album_Overview", album.Overview);
|
||||
|
@ -342,5 +342,19 @@ namespace NzbDrone.Core.Notifications.CustomScript
|
|||
|
||||
return processOutput;
|
||||
}
|
||||
|
||||
private List<string> GetTagLabels(Artist artist)
|
||||
{
|
||||
if (artist == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _tagRepository.GetTags(artist.Tags)
|
||||
.Select(s => s.Label)
|
||||
.Where(l => l.IsNotNullOrWhiteSpace())
|
||||
.OrderBy(l => l)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ using NzbDrone.Core.MediaCover;
|
|||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Notifications.Webhook;
|
||||
using NzbDrone.Core.Tags;
|
||||
using NzbDrone.Core.Validation;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Notifiarr
|
||||
|
@ -14,8 +15,8 @@ namespace NzbDrone.Core.Notifications.Notifiarr
|
|||
{
|
||||
private readonly INotifiarrProxy _proxy;
|
||||
|
||||
public Notifiarr(INotifiarrProxy proxy, IConfigFileProvider configFileProvider, IConfigService configService, IMapCoversToLocal mediaCoverService)
|
||||
: base(configFileProvider, configService, mediaCoverService)
|
||||
public Notifiarr(INotifiarrProxy proxy, IConfigFileProvider configFileProvider, IConfigService configService, ITagRepository tagRepository, IMapCoversToLocal mediaCoverService)
|
||||
: base(configFileProvider, configService, tagRepository, mediaCoverService)
|
||||
{
|
||||
_proxy = proxy;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ using NzbDrone.Core.Configuration;
|
|||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Tags;
|
||||
using NzbDrone.Core.Validation;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Webhook
|
||||
|
@ -13,8 +14,8 @@ namespace NzbDrone.Core.Notifications.Webhook
|
|||
{
|
||||
private readonly IWebhookProxy _proxy;
|
||||
|
||||
public Webhook(IWebhookProxy proxy, IConfigFileProvider configFileProvider, IConfigService configService, IMapCoversToLocal mediaCoverService)
|
||||
: base(configFileProvider, configService, mediaCoverService)
|
||||
public Webhook(IWebhookProxy proxy, IConfigFileProvider configFileProvider, IConfigService configService, ITagRepository tagRepository, IMapCoversToLocal mediaCoverService)
|
||||
: base(configFileProvider, configService, tagRepository, mediaCoverService)
|
||||
{
|
||||
_proxy = proxy;
|
||||
}
|
||||
|
|
|
@ -15,12 +15,13 @@ namespace NzbDrone.Core.Notifications.Webhook
|
|||
public string Overview { get; set; }
|
||||
public List<string> Genres { get; set; }
|
||||
public List<WebhookImage> Images { get; set; }
|
||||
public List<string> Tags { get; set; }
|
||||
|
||||
public WebhookArtist()
|
||||
{
|
||||
}
|
||||
|
||||
public WebhookArtist(Artist artist)
|
||||
public WebhookArtist(Artist artist, List<string> tags)
|
||||
{
|
||||
Id = artist.Id;
|
||||
Name = artist.Name;
|
||||
|
@ -31,6 +32,7 @@ namespace NzbDrone.Core.Notifications.Webhook
|
|||
Overview = artist.Metadata.Value.Overview;
|
||||
Genres = artist.Metadata.Value.Genres;
|
||||
Images = artist.Metadata.Value.Images.Select(i => new WebhookImage(i)).ToList();
|
||||
Tags = tags;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.MediaCover;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Tags;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Webhook
|
||||
|
@ -13,12 +15,14 @@ namespace NzbDrone.Core.Notifications.Webhook
|
|||
{
|
||||
private readonly IConfigFileProvider _configFileProvider;
|
||||
private readonly IConfigService _configService;
|
||||
private readonly ITagRepository _tagRepository;
|
||||
private readonly IMapCoversToLocal _mediaCoverService;
|
||||
|
||||
protected WebhookBase(IConfigFileProvider configFileProvider, IConfigService configService, IMapCoversToLocal mediaCoverService)
|
||||
protected WebhookBase(IConfigFileProvider configFileProvider, IConfigService configService, ITagRepository tagRepository, IMapCoversToLocal mediaCoverService)
|
||||
{
|
||||
_configFileProvider = configFileProvider;
|
||||
_configService = configService;
|
||||
_tagRepository = tagRepository;
|
||||
_mediaCoverService = mediaCoverService;
|
||||
}
|
||||
|
||||
|
@ -221,7 +225,8 @@ namespace NzbDrone.Core.Notifications.Webhook
|
|||
Id = 1,
|
||||
Name = "Test Name",
|
||||
Path = "C:\\testpath",
|
||||
MBId = "aaaaa-aaa-aaaa-aaaaaa"
|
||||
MBId = "aaaaa-aaa-aaaa-aaaaaa",
|
||||
Tags = new List<string> { "test-tag" }
|
||||
},
|
||||
Albums = new List<WebhookAlbum>
|
||||
{
|
||||
|
@ -243,7 +248,7 @@ namespace NzbDrone.Core.Notifications.Webhook
|
|||
|
||||
_mediaCoverService.ConvertToLocalUrls(artist.Id, MediaCoverEntity.Artist, artist.Metadata.Value.Images);
|
||||
|
||||
return new WebhookArtist(artist);
|
||||
return new WebhookArtist(artist, GetTagLabels(artist));
|
||||
}
|
||||
|
||||
private WebhookAlbum GetAlbum(Album album)
|
||||
|
@ -257,5 +262,19 @@ namespace NzbDrone.Core.Notifications.Webhook
|
|||
|
||||
return new WebhookAlbum(album);
|
||||
}
|
||||
|
||||
private List<string> GetTagLabels(Artist artist)
|
||||
{
|
||||
if (artist == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _tagRepository.GetTags(artist.Tags)
|
||||
.Select(s => s.Label)
|
||||
.Where(l => l.IsNotNullOrWhiteSpace())
|
||||
.OrderBy(l => l)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
@ -9,6 +10,7 @@ namespace NzbDrone.Core.Tags
|
|||
{
|
||||
Tag GetByLabel(string label);
|
||||
Tag FindByLabel(string label);
|
||||
List<Tag> GetTags(HashSet<int> tagIds);
|
||||
}
|
||||
|
||||
public class TagRepository : BasicRepository<Tag>, ITagRepository
|
||||
|
@ -34,5 +36,10 @@ namespace NzbDrone.Core.Tags
|
|||
{
|
||||
return Query(c => c.Label == label).SingleOrDefault();
|
||||
}
|
||||
|
||||
public List<Tag> GetTags(HashSet<int> tagIds)
|
||||
{
|
||||
return Query(t => tagIds.Contains(t.Id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue