Fixed: Sending Manual Interaction Required notifications for unknown series

For Discord/Slack/Webhooks/CustomScript
This commit is contained in:
Bogdan 2024-07-19 18:46:09 +03:00
parent 80ca1a6ac2
commit 2ebf89a6ab
4 changed files with 135 additions and 108 deletions

View File

@ -406,18 +406,18 @@ namespace NzbDrone.Core.Notifications.CustomScript
environmentVariables.Add("Sonarr_EventType", "ManualInteractionRequired");
environmentVariables.Add("Sonarr_InstanceName", _configFileProvider.InstanceName);
environmentVariables.Add("Sonarr_ApplicationUrl", _configService.ApplicationUrl);
environmentVariables.Add("Sonarr_Series_Id", series.Id.ToString());
environmentVariables.Add("Sonarr_Series_Title", series.Title);
environmentVariables.Add("Sonarr_Series_TitleSlug", series.TitleSlug);
environmentVariables.Add("Sonarr_Series_Path", series.Path);
environmentVariables.Add("Sonarr_Series_TvdbId", series.TvdbId.ToString());
environmentVariables.Add("Sonarr_Series_TvMazeId", series.TvMazeId.ToString());
environmentVariables.Add("Sonarr_Series_TmdbId", series.TmdbId.ToString());
environmentVariables.Add("Sonarr_Series_ImdbId", series.ImdbId ?? string.Empty);
environmentVariables.Add("Sonarr_Series_Type", series.SeriesType.ToString());
environmentVariables.Add("Sonarr_Series_Year", series.Year.ToString());
environmentVariables.Add("Sonarr_Series_OriginalLanguage", IsoLanguages.Get(series.OriginalLanguage).ThreeLetterCode);
environmentVariables.Add("Sonarr_Series_Genres", string.Join("|", series.Genres));
environmentVariables.Add("Sonarr_Series_Id", series?.Id.ToString());
environmentVariables.Add("Sonarr_Series_Title", series?.Title);
environmentVariables.Add("Sonarr_Series_TitleSlug", series?.TitleSlug);
environmentVariables.Add("Sonarr_Series_Path", series?.Path);
environmentVariables.Add("Sonarr_Series_TvdbId", series?.TvdbId.ToString());
environmentVariables.Add("Sonarr_Series_TvMazeId", series?.TvMazeId.ToString());
environmentVariables.Add("Sonarr_Series_TmdbId", series?.TmdbId.ToString());
environmentVariables.Add("Sonarr_Series_ImdbId", series?.ImdbId ?? string.Empty);
environmentVariables.Add("Sonarr_Series_Type", series?.SeriesType.ToString());
environmentVariables.Add("Sonarr_Series_Year", series?.Year.ToString());
environmentVariables.Add("Sonarr_Series_OriginalLanguage", IsoLanguages.Get(series?.OriginalLanguage)?.ThreeLetterCode);
environmentVariables.Add("Sonarr_Series_Genres", string.Join("|", series?.Genres ?? new List<string>()));
environmentVariables.Add("Sonarr_Series_Tags", string.Join("|", GetTagLabels(series)));
environmentVariables.Add("Sonarr_Download_Client", message.DownloadClientInfo?.Name ?? string.Empty);
environmentVariables.Add("Sonarr_Download_Client_Type", message.DownloadClientInfo?.Type ?? string.Empty);
@ -482,6 +482,11 @@ namespace NzbDrone.Core.Notifications.CustomScript
private List<string> GetTagLabels(Series series)
{
if (series == null)
{
return null;
}
return _tagRepository.GetTags(series.Tags)
.Select(s => s.Label)
.Where(l => l.IsNotNullOrWhiteSpace())

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using FluentValidation.Results;
using NzbDrone.Common.Extensions;
@ -330,7 +331,7 @@ namespace NzbDrone.Core.Notifications.Discord
{
var attachments = new List<Embed>
{
new Embed
new ()
{
Title = series.Title,
}
@ -361,8 +362,8 @@ namespace NzbDrone.Core.Notifications.Discord
Color = (int)DiscordColors.Danger,
Fields = new List<DiscordField>
{
new DiscordField { Name = "Reason", Value = reason.ToString() },
new DiscordField { Name = "File name", Value = string.Format("```{0}```", deletedFile) }
new () { Name = "Reason", Value = reason.ToString() },
new () { Name = "File name", Value = string.Format("```{0}```", deletedFile) }
},
Timestamp = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ"),
};
@ -386,7 +387,7 @@ namespace NzbDrone.Core.Notifications.Discord
Title = series.Title,
Description = "Series Added",
Color = (int)DiscordColors.Success,
Fields = new List<DiscordField> { new DiscordField { Name = "Links", Value = GetLinksString(series) } }
Fields = new List<DiscordField> { new () { Name = "Links", Value = GetLinksString(series) } }
};
if (Settings.ImportFields.Contains((int)DiscordImportFieldType.Poster))
@ -425,7 +426,7 @@ namespace NzbDrone.Core.Notifications.Discord
Title = series.Title,
Description = deleteMessage.DeletedFilesMessage,
Color = (int)DiscordColors.Danger,
Fields = new List<DiscordField> { new DiscordField { Name = "Links", Value = GetLinksString(series) } }
Fields = new List<DiscordField> { new () { Name = "Links", Value = GetLinksString(series) } }
};
if (Settings.ImportFields.Contains((int)DiscordImportFieldType.Poster))
@ -503,12 +504,12 @@ namespace NzbDrone.Core.Notifications.Discord
Color = (int)DiscordColors.Standard,
Fields = new List<DiscordField>()
{
new DiscordField()
new ()
{
Name = "Previous Version",
Value = updateMessage.PreviousVersion.ToString()
},
new DiscordField()
new ()
{
Name = "New Version",
Value = updateMessage.NewVersion.ToString()
@ -533,7 +534,7 @@ namespace NzbDrone.Core.Notifications.Discord
Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author,
IconUrl = "https://raw.githubusercontent.com/Sonarr/Sonarr/develop/Logo/256.png"
},
Url = $"http://thetvdb.com/?tab=series&id={series.TvdbId}",
Url = series?.TvdbId > 0 ? $"http://thetvdb.com/?tab=series&id={series.TvdbId}" : null,
Description = "Manual interaction needed",
Title = GetTitle(series, episodes),
Color = (int)DiscordColors.Standard,
@ -545,7 +546,7 @@ namespace NzbDrone.Core.Notifications.Discord
{
embed.Thumbnail = new DiscordImage
{
Url = series.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Poster)?.Url
Url = series?.Images?.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Poster)?.Url
};
}
@ -553,7 +554,7 @@ namespace NzbDrone.Core.Notifications.Discord
{
embed.Image = new DiscordImage
{
Url = series.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Fanart)?.Url
Url = series?.Images?.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Fanart)?.Url
};
}
@ -564,26 +565,26 @@ namespace NzbDrone.Core.Notifications.Discord
switch ((DiscordManualInteractionFieldType)field)
{
case DiscordManualInteractionFieldType.Overview:
var overview = episodes.First().Overview ?? "";
var overview = episodes.FirstOrDefault()?.Overview ?? "";
discordField.Name = "Overview";
discordField.Value = overview.Length <= 300 ? overview : $"{overview.AsSpan(0, 300)}...";
break;
case DiscordManualInteractionFieldType.Rating:
discordField.Name = "Rating";
discordField.Value = episodes.First().Ratings.Value.ToString();
discordField.Value = episodes.FirstOrDefault()?.Ratings?.Value.ToString(CultureInfo.InvariantCulture);
break;
case DiscordManualInteractionFieldType.Genres:
discordField.Name = "Genres";
discordField.Value = series.Genres.Take(5).Join(", ");
discordField.Value = series?.Genres.Take(5).Join(", ");
break;
case DiscordManualInteractionFieldType.Quality:
discordField.Name = "Quality";
discordField.Inline = true;
discordField.Value = message.Quality.Quality.Name;
discordField.Value = message.Quality?.Quality?.Name;
break;
case DiscordManualInteractionFieldType.Group:
discordField.Name = "Group";
discordField.Value = message.Episode.ParsedEpisodeInfo.ReleaseGroup;
discordField.Value = message.Episode?.ParsedEpisodeInfo?.ReleaseGroup;
break;
case DiscordManualInteractionFieldType.Size:
discordField.Name = "Size";
@ -592,7 +593,7 @@ namespace NzbDrone.Core.Notifications.Discord
break;
case DiscordManualInteractionFieldType.DownloadTitle:
discordField.Name = "Download";
discordField.Value = string.Format("```{0}```", message.TrackedDownload.DownloadItem.Title);
discordField.Value = $"```{message.TrackedDownload.DownloadItem.Title}```";
break;
case DiscordManualInteractionFieldType.Links:
discordField.Name = "Links";
@ -677,10 +678,16 @@ namespace NzbDrone.Core.Notifications.Discord
private string GetLinksString(Series series)
{
var links = new List<string>();
if (series == null)
{
return null;
}
links.Add($"[The TVDB](https://thetvdb.com/?tab=series&id={series.TvdbId})");
links.Add($"[Trakt](https://trakt.tv/search/tvdb/{series.TvdbId}?id_type=show)");
var links = new List<string>
{
$"[The TVDB](https://thetvdb.com/?tab=series&id={series.TvdbId})",
$"[Trakt](https://trakt.tv/search/tvdb/{series.TvdbId}?id_type=show)"
};
if (series.ImdbId.IsNotNullOrWhiteSpace())
{
@ -692,6 +699,11 @@ namespace NzbDrone.Core.Notifications.Discord
private string GetTitle(Series series, List<Episode> episodes)
{
if (series == null)
{
return null;
}
if (series.SeriesType == SeriesTypes.Daily)
{
var episode = episodes.First();

View File

@ -29,7 +29,7 @@ namespace NzbDrone.Core.Notifications.Slack
{
var attachments = new List<Attachment>
{
new Attachment
new ()
{
Fallback = message.Message,
Title = message.Series.Title,
@ -46,7 +46,7 @@ namespace NzbDrone.Core.Notifications.Slack
{
var attachments = new List<Attachment>
{
new Attachment
new ()
{
Fallback = message.Message,
Title = message.Series.Title,
@ -63,7 +63,7 @@ namespace NzbDrone.Core.Notifications.Slack
{
var attachments = new List<Attachment>
{
new Attachment
new ()
{
Fallback = message.Message,
Title = message.Series.Title,
@ -80,7 +80,7 @@ namespace NzbDrone.Core.Notifications.Slack
{
var attachments = new List<Attachment>
{
new Attachment
new ()
{
Title = series.Title,
}
@ -95,7 +95,7 @@ namespace NzbDrone.Core.Notifications.Slack
{
var attachments = new List<Attachment>
{
new Attachment
new ()
{
Title = GetTitle(deleteMessage.Series, deleteMessage.EpisodeFile.Episodes),
}
@ -110,7 +110,7 @@ namespace NzbDrone.Core.Notifications.Slack
{
var attachments = new List<Attachment>
{
new Attachment
new ()
{
Title = message.Series.Title,
}
@ -125,7 +125,7 @@ namespace NzbDrone.Core.Notifications.Slack
{
var attachments = new List<Attachment>
{
new Attachment
new ()
{
Title = deleteMessage.Series.Title,
Text = deleteMessage.DeletedFilesMessage
@ -141,7 +141,7 @@ namespace NzbDrone.Core.Notifications.Slack
{
var attachments = new List<Attachment>
{
new Attachment
new ()
{
Title = healthCheck.Source.Name,
Text = healthCheck.Message,
@ -158,7 +158,7 @@ namespace NzbDrone.Core.Notifications.Slack
{
var attachments = new List<Attachment>
{
new Attachment
new ()
{
Title = previousCheck.Source.Name,
Text = $"The following issue is now resolved: {previousCheck.Message}",
@ -175,7 +175,7 @@ namespace NzbDrone.Core.Notifications.Slack
{
var attachments = new List<Attachment>
{
new Attachment
new ()
{
Title = Environment.MachineName,
Text = updateMessage.Message,
@ -192,9 +192,9 @@ namespace NzbDrone.Core.Notifications.Slack
{
var attachments = new List<Attachment>
{
new Attachment
new ()
{
Title = Environment.MachineName,
Title = GetTitle(message.Series, message.Episode.Episodes),
Text = message.Message,
Color = "warning"
}

View File

@ -229,9 +229,9 @@ namespace NzbDrone.Core.Notifications.Webhook
TvdbId = 1234,
Tags = new List<string> { "test-tag" }
},
Episodes = new List<WebhookEpisode>()
Episodes = new List<WebhookEpisode>
{
new WebhookEpisode()
new ()
{
Id = 123,
EpisodeNumber = 1,
@ -244,6 +244,11 @@ namespace NzbDrone.Core.Notifications.Webhook
private WebhookSeries GetSeries(Series series)
{
if (series == null)
{
return null;
}
_mediaCoverService.ConvertToLocalUrls(series.Id, series.Images);
return new WebhookSeries(series, GetTagLabels(series));
@ -251,6 +256,11 @@ namespace NzbDrone.Core.Notifications.Webhook
private List<string> GetTagLabels(Series series)
{
if (series == null)
{
return null;
}
return _tagRepository.GetTags(series.Tags)
.Select(s => s.Label)
.Where(l => l.IsNotNullOrWhiteSpace())