1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-19 17:32:38 +01:00

Fixed: Sending Manual Interaction Required notifications for unknown movies

This commit is contained in:
Bogdan 2024-08-14 23:01:03 +03:00
parent b37cc42805
commit 1efe7db5f3
4 changed files with 111 additions and 81 deletions

View File

@ -313,16 +313,16 @@ public override void OnManualInteractionRequired(ManualInteractionRequiredMessag
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<string>()));
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 @@ private bool ValidatePathParent(string possibleParent, string path)
private List<string> GetTagLabels(Movie movie)
{
if (movie == null)
{
return null;
}
return _tagRepository.GetTags(movie.Tags)
.Select(t => t.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;
@ -448,7 +449,7 @@ public override void OnManualInteractionRequired(ManualInteractionRequiredMessag
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 @@ public override void OnManualInteractionRequired(ManualInteractionRequiredMessag
{
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 @@ public override void OnManualInteractionRequired(ManualInteractionRequiredMessag
{
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 @@ public override void OnManualInteractionRequired(ManualInteractionRequiredMessag
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 @@ public override void OnManualInteractionRequired(ManualInteractionRequiredMessag
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 @@ private static string BytesToString(long byteCount)
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<string>
{
$"[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;

View File

@ -28,15 +28,15 @@ public Slack(ISlackProxy proxy, ILocalizationService localizationService)
public override void OnGrab(GrabMessage message)
{
var attachments = new List<Attachment>
{
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 @@ public override void OnGrab(GrabMessage message)
public override void OnDownload(DownloadMessage message)
{
var attachments = new List<Attachment>
{
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 @@ public override void OnMovieRename(Movie movie, List<RenamedMovieFile> renamedFi
public override void OnMovieFileDelete(MovieFileDeleteMessage deleteMessage)
{
var attachments = new List<Attachment>
{
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 @@ public override void OnMovieFileDelete(MovieFileDeleteMessage deleteMessage)
public override void OnMovieDelete(MovieDeleteMessage deleteMessage)
{
var attachments = new List<Attachment>
{
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 @@ public override void OnMovieDelete(MovieDeleteMessage deleteMessage)
public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
{
var attachments = new List<Attachment>
{
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 @@ public override void OnHealthIssue(HealthCheck.HealthCheck healthCheck)
public override void OnHealthRestored(HealthCheck.HealthCheck previousCheck)
{
var attachments = new List<Attachment>
{
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 @@ public override void OnHealthRestored(HealthCheck.HealthCheck previousCheck)
public override void OnApplicationUpdate(ApplicationUpdateMessage updateMessage)
{
var attachments = new List<Attachment>
{
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 @@ public override void OnManualInteractionRequired(ManualInteractionRequiredMessag
{
var attachments = new List<Attachment>
{
new Attachment
new ()
{
Title = Environment.MachineName,
Text = message.Message,

View File

@ -237,6 +237,11 @@ protected WebhookPayload BuildTestPayload()
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 @@ private WebhookMovie GetMovie(Movie movie)
private List<string> GetTagLabels(Movie movie)
{
if (movie == null)
{
return null;
}
return _tagRepository.GetTags(movie.Tags)
.Select(t => t.Label)
.Where(l => l.IsNotNullOrWhiteSpace())