diff --git a/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs b/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs index 9c96d5bd0..13a0e8765 100755 --- a/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs +++ b/src/NzbDrone.Core/Notifications/CustomScript/CustomScript.cs @@ -313,16 +313,16 @@ namespace NzbDrone.Core.Notifications.CustomScript environmentVariables.Add("Radarr_EventType", "ManualInteractionRequired"); environmentVariables.Add("Radarr_InstanceName", _configFileProvider.InstanceName); environmentVariables.Add("Radarr_ApplicationUrl", _configService.ApplicationUrl); - environmentVariables.Add("Radarr_Movie_Id", movie.Id.ToString()); - environmentVariables.Add("Radarr_Movie_Title", movie.MovieMetadata.Value.Title); - environmentVariables.Add("Radarr_Movie_Year", movie.MovieMetadata.Value.Year.ToString()); - environmentVariables.Add("Radarr_Movie_OriginalLanguage", IsoLanguages.Get(movie.MovieMetadata.Value.OriginalLanguage).ThreeLetterCode); - environmentVariables.Add("Radarr_Movie_Genres", string.Join("|", movie.MovieMetadata.Value.Genres)); + environmentVariables.Add("Radarr_Movie_Id", movie?.Id.ToString()); + environmentVariables.Add("Radarr_Movie_Title", movie?.MovieMetadata.Value.Title); + environmentVariables.Add("Radarr_Movie_Year", movie?.MovieMetadata.Value.Year.ToString()); + environmentVariables.Add("Radarr_Movie_OriginalLanguage", IsoLanguages.Get(movie?.MovieMetadata.Value.OriginalLanguage)?.ThreeLetterCode); + environmentVariables.Add("Radarr_Movie_Genres", string.Join("|", movie?.MovieMetadata.Value.Genres ?? new List())); environmentVariables.Add("Radarr_Movie_Tags", string.Join("|", GetTagLabels(movie))); - environmentVariables.Add("Radarr_Movie_Path", movie.Path); - environmentVariables.Add("Radarr_Movie_ImdbId", movie.MovieMetadata.Value.ImdbId ?? string.Empty); - environmentVariables.Add("Radarr_Movie_TmdbId", movie.MovieMetadata.Value.TmdbId.ToString()); - environmentVariables.Add("Radarr_Movie_Overview", movie.MovieMetadata.Value.Overview); + environmentVariables.Add("Radarr_Movie_Path", movie?.Path); + environmentVariables.Add("Radarr_Movie_ImdbId", movie?.MovieMetadata.Value.ImdbId ?? string.Empty); + environmentVariables.Add("Radarr_Movie_TmdbId", movie?.MovieMetadata.Value.TmdbId.ToString()); + environmentVariables.Add("Radarr_Movie_Overview", movie?.MovieMetadata.Value.Overview); environmentVariables.Add("Radarr_Download_Client", message.DownloadClientInfo?.Name ?? string.Empty); environmentVariables.Add("Radarr_Download_Client_Type", message.DownloadClientInfo?.Type ?? string.Empty); environmentVariables.Add("Radarr_Download_Id", message.DownloadId ?? string.Empty); @@ -388,6 +388,11 @@ namespace NzbDrone.Core.Notifications.CustomScript private List GetTagLabels(Movie movie) { + if (movie == null) + { + return null; + } + return _tagRepository.GetTags(movie.Tags) .Select(t => t.Label) .Where(l => l.IsNotNullOrWhiteSpace()) diff --git a/src/NzbDrone.Core/Notifications/Discord/Discord.cs b/src/NzbDrone.Core/Notifications/Discord/Discord.cs index e81fdae24..7c44bc4e0 100644 --- a/src/NzbDrone.Core/Notifications/Discord/Discord.cs +++ b/src/NzbDrone.Core/Notifications/Discord/Discord.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using FluentValidation.Results; using NzbDrone.Common.Extensions; @@ -448,7 +449,7 @@ namespace NzbDrone.Core.Notifications.Discord Name = Settings.Author.IsNullOrWhiteSpace() ? Environment.MachineName : Settings.Author, IconUrl = "https://raw.githubusercontent.com/Radarr/Radarr/develop/Logo/256.png" }, - Url = $"https://www.themoviedb.org/movie/{movie.MovieMetadata.Value.TmdbId}", + Url = movie?.MovieMetadata.Value.TmdbId > 0 ? $"https://www.themoviedb.org/movie/{movie.MovieMetadata.Value.TmdbId}" : null, Description = "Manual interaction needed", Title = GetTitle(movie), Color = (int)DiscordColors.Standard, @@ -460,7 +461,7 @@ namespace NzbDrone.Core.Notifications.Discord { embed.Thumbnail = new DiscordImage { - Url = movie.MovieMetadata.Value.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Poster)?.RemoteUrl + Url = movie?.MovieMetadata?.Value?.Images?.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Poster)?.RemoteUrl }; } @@ -468,7 +469,7 @@ namespace NzbDrone.Core.Notifications.Discord { embed.Image = new DiscordImage { - Url = movie.MovieMetadata.Value.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Fanart)?.RemoteUrl + Url = movie?.MovieMetadata?.Value?.Images?.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Fanart)?.RemoteUrl }; } @@ -479,26 +480,26 @@ namespace NzbDrone.Core.Notifications.Discord switch ((DiscordManualInteractionFieldType)field) { case DiscordManualInteractionFieldType.Overview: - var overview = movie.MovieMetadata.Value.Overview ?? ""; + var overview = movie?.MovieMetadata?.Value?.Overview ?? ""; discordField.Name = "Overview"; discordField.Value = overview.Length <= 300 ? overview : $"{overview.AsSpan(0, 300)}..."; break; case DiscordManualInteractionFieldType.Rating: discordField.Name = "Rating"; - discordField.Value = movie.MovieMetadata.Value.Ratings.Tmdb?.Value.ToString() ?? string.Empty; + discordField.Value = movie?.MovieMetadata?.Value?.Ratings?.Tmdb?.Value.ToString(CultureInfo.InvariantCulture) ?? string.Empty; break; case DiscordManualInteractionFieldType.Genres: discordField.Name = "Genres"; - discordField.Value = movie.MovieMetadata.Value.Genres.Take(5).Join(", "); + discordField.Value = movie?.MovieMetadata?.Value?.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.RemoteMovie.ParsedMovieInfo.ReleaseGroup; + discordField.Value = message.RemoteMovie?.ParsedMovieInfo?.ReleaseGroup; break; case DiscordManualInteractionFieldType.Size: discordField.Name = "Size"; @@ -507,7 +508,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"; @@ -596,28 +597,42 @@ namespace NzbDrone.Core.Notifications.Discord private static string GetLinksString(Movie movie) { - var links = string.Format("[{0}]({1})", "TMDb", $"https://themoviedb.org/movie/{movie.MovieMetadata.Value.TmdbId}"); - links += string.Format(" / [{0}]({1})", "Trakt", $"https://trakt.tv/search/tmdb/{movie.MovieMetadata.Value.TmdbId}?id_type=movie"); + if (movie?.MovieMetadata?.Value == null) + { + return null; + } + + var links = new List + { + $"[TMDb](https://themoviedb.org/movie/{movie.MovieMetadata.Value.TmdbId})", + $"[Trakt](https://trakt.tv/search/tmdb/{movie.MovieMetadata.Value.TmdbId}?id_type=movie)" + }; + if (movie.MovieMetadata.Value.ImdbId.IsNotNullOrWhiteSpace()) { - links += string.Format(" / [{0}]({1})", "IMDb", $"https://imdb.com/title/{movie.MovieMetadata.Value.ImdbId}/"); + links.Add($"[IMDb](https://imdb.com/title/{movie.MovieMetadata.Value.ImdbId}/)"); } if (movie.MovieMetadata.Value.YouTubeTrailerId.IsNotNullOrWhiteSpace()) { - links += string.Format(" / [{0}]({1})", "YouTube", $"https://www.youtube.com/watch?v={movie.MovieMetadata.Value.YouTubeTrailerId}"); + links.Add($"[YouTube](https://www.youtube.com/watch?v={movie.MovieMetadata.Value.YouTubeTrailerId})"); } if (movie.MovieMetadata.Value.Website.IsNotNullOrWhiteSpace()) { - links += string.Format(" / [{0}]({1})", "Website", movie.MovieMetadata.Value.Website); + links.Add($"[Website]({movie.MovieMetadata.Value.Website})"); } - return links; + return string.Join(" / ", links); } private string GetTitle(Movie movie) { + if (movie == null) + { + return null; + } + var title = movie.MovieMetadata.Value.Year > 0 ? $"{movie.MovieMetadata.Value.Title} ({movie.MovieMetadata.Value.Year})" : movie.MovieMetadata.Value.Title; return title.Length > 256 ? $"{title.AsSpan(0, 253)}..." : title; diff --git a/src/NzbDrone.Core/Notifications/Slack/Slack.cs b/src/NzbDrone.Core/Notifications/Slack/Slack.cs index 2cd448943..1f1fb2019 100644 --- a/src/NzbDrone.Core/Notifications/Slack/Slack.cs +++ b/src/NzbDrone.Core/Notifications/Slack/Slack.cs @@ -28,15 +28,15 @@ namespace NzbDrone.Core.Notifications.Slack public override void OnGrab(GrabMessage message) { var attachments = new List - { - new Attachment - { - Fallback = message.Message, - Title = message.Movie.Title, - Text = message.Message, - Color = "warning" - } - }; + { + new () + { + Fallback = message.Message, + Title = message.Movie.Title, + Text = message.Message, + Color = "warning" + } + }; var payload = CreatePayload($"Grabbed: {message.Message}", attachments); _proxy.SendPayload(payload, Settings); @@ -45,15 +45,15 @@ namespace NzbDrone.Core.Notifications.Slack public override void OnDownload(DownloadMessage message) { var attachments = new List - { - new Attachment - { - Fallback = message.Message, - Title = message.Movie.Title, - Text = message.Message, - Color = "good" - } - }; + { + new () + { + Fallback = message.Message, + Title = message.Movie.Title, + Text = message.Message, + Color = "good" + } + }; var payload = CreatePayload($"Imported: {message.Message}", attachments); _proxy.SendPayload(payload, Settings); @@ -80,13 +80,13 @@ namespace NzbDrone.Core.Notifications.Slack public override void OnMovieFileDelete(MovieFileDeleteMessage deleteMessage) { var attachments = new List - { - new Attachment - { - Title = deleteMessage.Movie.Title, - Text = Path.Combine(deleteMessage.Movie.Path, deleteMessage.MovieFile.RelativePath) - } - }; + { + new () + { + Title = deleteMessage.Movie.Title, + Text = Path.Combine(deleteMessage.Movie.Path, deleteMessage.MovieFile.RelativePath) + } + }; var payload = CreatePayload("Movie File Deleted", attachments); @@ -96,13 +96,13 @@ namespace NzbDrone.Core.Notifications.Slack public override void OnMovieDelete(MovieDeleteMessage deleteMessage) { var attachments = new List - { - new Attachment - { - Title = deleteMessage.Movie.Title, - Text = deleteMessage.DeletedFilesMessage - } - }; + { + new () + { + Title = deleteMessage.Movie.Title, + Text = deleteMessage.DeletedFilesMessage + } + }; var payload = CreatePayload("Movie Deleted", attachments); @@ -112,14 +112,14 @@ namespace NzbDrone.Core.Notifications.Slack public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck) { var attachments = new List - { - new Attachment - { - Title = healthCheck.Source.Name, - Text = healthCheck.Message, - Color = healthCheck.Type == HealthCheck.HealthCheckResult.Warning ? "warning" : "danger" - } - }; + { + new () + { + Title = healthCheck.Source.Name, + Text = healthCheck.Message, + Color = healthCheck.Type == HealthCheck.HealthCheckResult.Warning ? "warning" : "danger" + } + }; var payload = CreatePayload("Health Issue", attachments); @@ -129,14 +129,14 @@ namespace NzbDrone.Core.Notifications.Slack public override void OnHealthRestored(HealthCheck.HealthCheck previousCheck) { var attachments = new List - { - new Attachment - { - Title = previousCheck.Source.Name, - Text = $"The following issue is now resolved: {previousCheck.Message}", - Color = "good" - } - }; + { + new () + { + Title = previousCheck.Source.Name, + Text = $"The following issue is now resolved: {previousCheck.Message}", + Color = "good" + } + }; var payload = CreatePayload("Health Issue Resolved", attachments); @@ -146,14 +146,14 @@ namespace NzbDrone.Core.Notifications.Slack public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage) { var attachments = new List - { - new Attachment - { - Title = Environment.MachineName, - Text = updateMessage.Message, - Color = "good" - } - }; + { + new () + { + Title = Environment.MachineName, + Text = updateMessage.Message, + Color = "good" + } + }; var payload = CreatePayload("Application Updated", attachments); @@ -164,7 +164,7 @@ namespace NzbDrone.Core.Notifications.Slack { var attachments = new List { - new Attachment + new () { Title = Environment.MachineName, Text = message.Message, diff --git a/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs b/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs index 6de5d086c..017eb0746 100644 --- a/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs +++ b/src/NzbDrone.Core/Notifications/Webhook/WebhookBase.cs @@ -237,6 +237,11 @@ namespace NzbDrone.Core.Notifications.Webhook private WebhookMovie GetMovie(Movie movie) { + if (movie == null) + { + return null; + } + _mediaCoverService.ConvertToLocalUrls(movie.Id, movie.MovieMetadata.Value.Images); return new WebhookMovie(movie, GetTagLabels(movie)); @@ -244,6 +249,11 @@ namespace NzbDrone.Core.Notifications.Webhook private List GetTagLabels(Movie movie) { + if (movie == null) + { + return null; + } + return _tagRepository.GetTags(movie.Tags) .Select(t => t.Label) .Where(l => l.IsNotNullOrWhiteSpace())