Fixed: Update AutoTags on movie add (#11079)

Co-authored-by: aden <aden@hughorse.net>
This commit is contained in:
Aden Northcote 2025-05-24 01:56:02 +10:00 committed by GitHub
parent b5b4d4b971
commit f5faf52469
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 65 additions and 5 deletions

View file

@ -56,6 +56,8 @@ public Movie AddMovie(Movie newMovie)
_movieMetadataService.Upsert(newMovie.MovieMetadata.Value); _movieMetadataService.Upsert(newMovie.MovieMetadata.Value);
newMovie.MovieMetadataId = newMovie.MovieMetadata.Value.Id; newMovie.MovieMetadataId = newMovie.MovieMetadata.Value.Id;
_movieService.UpdateTags(newMovie);
_movieService.AddMovie(newMovie); _movieService.AddMovie(newMovie);
return newMovie; return newMovie;

View file

@ -205,8 +205,14 @@ private void RescanMovie(Movie movie, bool isNew, CommandTrigger trigger)
} }
} }
private void UpdateTags(Movie movie) private void UpdateTags(Movie movie, bool isNew)
{ {
if (isNew)
{
_logger.Trace("Skipping tag update for {0}. Reason: New movie", movie);
return;
}
var tagsUpdated = _movieService.UpdateTags(movie); var tagsUpdated = _movieService.UpdateTags(movie);
if (tagsUpdated) if (tagsUpdated)
@ -230,7 +236,7 @@ public void Execute(RefreshMovieCommand message)
try try
{ {
movie = RefreshMovieInfo(movieId); movie = RefreshMovieInfo(movieId);
UpdateTags(movie); UpdateTags(movie, isNew);
RescanMovie(movie, isNew, trigger); RescanMovie(movie, isNew, trigger);
} }
catch (MovieNotFoundException) catch (MovieNotFoundException)
@ -240,7 +246,7 @@ public void Execute(RefreshMovieCommand message)
catch (Exception e) catch (Exception e)
{ {
_logger.Error(e, "Couldn't refresh info for {0}", movie); _logger.Error(e, "Couldn't refresh info for {0}", movie);
UpdateTags(movie); UpdateTags(movie, isNew);
RescanMovie(movie, isNew, trigger); RescanMovie(movie, isNew, trigger);
throw; throw;
} }
@ -277,13 +283,13 @@ public void Execute(RefreshMovieCommand message)
_logger.Error(e, "Couldn't refresh info for {0}", movieLocal); _logger.Error(e, "Couldn't refresh info for {0}", movieLocal);
} }
UpdateTags(movie); UpdateTags(movie, false);
RescanMovie(movieLocal, false, trigger); RescanMovie(movieLocal, false, trigger);
} }
else else
{ {
_logger.Debug("Skipping refresh of movie: {0}", movieLocal.Title); _logger.Debug("Skipping refresh of movie: {0}", movieLocal.Title);
UpdateTags(movie); UpdateTags(movie, false);
RescanMovie(movieLocal, false, trigger); RescanMovie(movieLocal, false, trigger);
} }
} }

View file

@ -3,6 +3,8 @@
using System.Linq; using System.Linq;
using FluentAssertions; using FluentAssertions;
using NUnit.Framework; using NUnit.Framework;
using Radarr.Api.V3.AutoTagging;
using Radarr.Http.ClientSchema;
namespace NzbDrone.Integration.Test.ApiTests namespace NzbDrone.Integration.Test.ApiTests
{ {
@ -29,6 +31,53 @@ public void add_movie_with_tags_should_store_them()
result.Tags.Should().Equal(tag.Id); result.Tags.Should().Equal(tag.Id);
} }
[Test]
[Order(0)]
public void add_movie_should_trigger_autotag()
{
var tag = EnsureTag("autotag-test");
var movie = Movies.Lookup("imdb:tt0110912").Single();
movie.Genres = new List<string> { "Thriller" };
var item = AutoTagging.Post(new AutoTaggingResource
{
Name = "Test",
RemoveTagsAutomatically = false,
Tags = new HashSet<int> { tag.Id },
Specifications = new List<AutoTaggingSpecificationSchema>
{
new AutoTaggingSpecificationSchema
{
Name = "Test",
Implementation = "GenreSpecification",
ImplementationName = "Genre",
Negate = false,
Required = false,
Fields = new List<Field>
{
new Field
{
Name = "value",
Label = "Genre(s)",
Type = "tag",
Value = new List<string> { "Thriller" }
}
}
}
}
});
EnsureNoMovie(680, "Pulp Fiction");
movie.QualityProfileId = 1;
movie.Path = Path.Combine(MovieRootFolder, movie.Title);
var result = Movies.Post(movie);
result.Should().NotBeNull();
result.Tags.Should().Contain(tag.Id);
}
[Test] [Test]
[Order(0)] [Order(0)]
public void add_movie_without_profileid_should_return_badrequest() public void add_movie_without_profileid_should_return_badrequest()

View file

@ -17,6 +17,7 @@
using NzbDrone.Integration.Test.Client; using NzbDrone.Integration.Test.Client;
using NzbDrone.SignalR; using NzbDrone.SignalR;
using NzbDrone.Test.Common.Categories; using NzbDrone.Test.Common.Categories;
using Radarr.Api.V3.AutoTagging;
using Radarr.Api.V3.Blocklist; using Radarr.Api.V3.Blocklist;
using Radarr.Api.V3.Config; using Radarr.Api.V3.Config;
using Radarr.Api.V3.DownloadClient; using Radarr.Api.V3.DownloadClient;
@ -36,6 +37,7 @@ public abstract class IntegrationTestBase
{ {
protected RestClient RestClient { get; private set; } protected RestClient RestClient { get; private set; }
public ClientBase<AutoTaggingResource> AutoTagging;
public ClientBase<BlocklistResource> Blocklist; public ClientBase<BlocklistResource> Blocklist;
public CommandClient Commands; public CommandClient Commands;
public ClientBase<TaskResource> Tasks; public ClientBase<TaskResource> Tasks;
@ -99,6 +101,7 @@ protected virtual void InitRestClients()
RestClient.AddDefaultHeader("Authentication", ApiKey); RestClient.AddDefaultHeader("Authentication", ApiKey);
RestClient.AddDefaultHeader("X-Api-Key", ApiKey); RestClient.AddDefaultHeader("X-Api-Key", ApiKey);
AutoTagging = new ClientBase<AutoTaggingResource>(RestClient, ApiKey);
Blocklist = new ClientBase<BlocklistResource>(RestClient, ApiKey); Blocklist = new ClientBase<BlocklistResource>(RestClient, ApiKey);
Commands = new CommandClient(RestClient, ApiKey); Commands = new CommandClient(RestClient, ApiKey);
Tasks = new ClientBase<TaskResource>(RestClient, ApiKey, "system/task"); Tasks = new ClientBase<TaskResource>(RestClient, ApiKey, "system/task");