Fixed: Wrong translation mapping can be used for file naming and metadata

Fixes #7243
pull/7192/head
Qstick 3 years ago
parent 89e25a6241
commit 3125b038d5

@ -45,7 +45,7 @@ namespace NzbDrone.Core.Test.IndexerSearchTests
.Returns(_movie); .Returns(_movie);
Mocker.GetMock<IMovieTranslationService>() Mocker.GetMock<IMovieTranslationService>()
.Setup(s => s.GetAllTranslationsForMovie(It.IsAny<int>())) .Setup(s => s.GetAllTranslationsForMovieMetadata(It.IsAny<int>()))
.Returns(new List<MovieTranslation>()); .Returns(new List<MovieTranslation>());
} }

@ -70,7 +70,7 @@ namespace NzbDrone.Core.Test.OrganizerTests.FileNameBuilderTests
.Returns(new List<CustomFormat>()); .Returns(new List<CustomFormat>());
Mocker.GetMock<IMovieTranslationService>() Mocker.GetMock<IMovieTranslationService>()
.Setup(v => v.GetAllTranslationsForMovie(It.IsAny<int>())) .Setup(v => v.GetAllTranslationsForMovieMetadata(It.IsAny<int>()))
.Returns(_movieTranslations); .Returns(_movieTranslations);
} }

@ -126,11 +126,11 @@ namespace NzbDrone.Core.Extras.Metadata.Consumers.Xbmc
(int)movie.MovieMetadata.Value.OriginalLanguage : (int)movie.MovieMetadata.Value.OriginalLanguage :
Settings.MovieMetadataLanguage; Settings.MovieMetadataLanguage;
var movieTranslations = _movieTranslationsService.GetAllTranslationsForMovie(movie.Id); var movieTranslations = _movieTranslationsService.GetAllTranslationsForMovieMetadata(movie.MovieMetadataId);
var selectedSettingsLanguage = Language.FindById(movieMetadataLanguage); var selectedSettingsLanguage = Language.FindById(movieMetadataLanguage);
var movieTranslation = movieTranslations.FirstOrDefault(mt => mt.Language == selectedSettingsLanguage); var movieTranslation = movieTranslations.FirstOrDefault(mt => mt.Language == selectedSettingsLanguage);
var credits = _creditService.GetAllCreditsForMovie(movie.MovieMetadataId); var credits = _creditService.GetAllCreditsForMovieMetadata(movie.MovieMetadataId);
var watched = GetExistingWatchedStatus(movie, movieFile.RelativePath); var watched = GetExistingWatchedStatus(movie, movieFile.RelativePath);

@ -49,7 +49,7 @@ namespace NzbDrone.Core.IndexerSearch
public List<DownloadDecision> MovieSearch(int movieId, bool userInvokedSearch, bool interactiveSearch) public List<DownloadDecision> MovieSearch(int movieId, bool userInvokedSearch, bool interactiveSearch)
{ {
var movie = _movieService.GetMovie(movieId); var movie = _movieService.GetMovie(movieId);
movie.MovieMetadata.Value.Translations = _movieTranslationService.GetAllTranslationsForMovie(movie.Id); movie.MovieMetadata.Value.Translations = _movieTranslationService.GetAllTranslationsForMovieMetadata(movie.MovieMetadataId);
return MovieSearch(movie, userInvokedSearch, interactiveSearch); return MovieSearch(movie, userInvokedSearch, interactiveSearch);
} }
@ -77,7 +77,7 @@ namespace NzbDrone.Core.IndexerSearch
}; };
var wantedLanguages = _profileService.GetAcceptableLanguages(movie.ProfileId); var wantedLanguages = _profileService.GetAcceptableLanguages(movie.ProfileId);
var translations = _movieTranslationService.GetAllTranslationsForMovie(movie.Id); var translations = _movieTranslationService.GetAllTranslationsForMovieMetadata(movie.MovieMetadataId);
var queryTranlations = new List<string> var queryTranlations = new List<string>
{ {

@ -464,7 +464,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
} }
else else
{ {
movie.MovieMetadata.Value.Translations = _movieTranslationService.GetAllTranslationsForMovie(movie.MovieMetadataId); movie.MovieMetadata.Value.Translations = _movieTranslationService.GetAllTranslationsForMovieMetadata(movie.MovieMetadataId);
} }
return movie; return movie;

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Movies.AlternativeTitles
{ {
public interface IAlternativeTitleService public interface IAlternativeTitleService
{ {
List<AlternativeTitle> GetAllTitlesForMovie(int movieId); List<AlternativeTitle> GetAllTitlesForMovieMetadata(int movieMetadataId);
AlternativeTitle AddAltTitle(AlternativeTitle title, MovieMetadata movie); AlternativeTitle AddAltTitle(AlternativeTitle title, MovieMetadata movie);
List<AlternativeTitle> AddAltTitles(List<AlternativeTitle> titles, MovieMetadata movie); List<AlternativeTitle> AddAltTitles(List<AlternativeTitle> titles, MovieMetadata movie);
AlternativeTitle GetById(int id); AlternativeTitle GetById(int id);
@ -36,9 +36,9 @@ namespace NzbDrone.Core.Movies.AlternativeTitles
_logger = logger; _logger = logger;
} }
public List<AlternativeTitle> GetAllTitlesForMovie(int movieId) public List<AlternativeTitle> GetAllTitlesForMovieMetadata(int movieMetadataId)
{ {
return _titleRepo.FindByMovieMetadataId(movieId).ToList(); return _titleRepo.FindByMovieMetadataId(movieMetadataId).ToList();
} }
public AlternativeTitle AddAltTitle(AlternativeTitle title, MovieMetadata movie) public AlternativeTitle AddAltTitle(AlternativeTitle title, MovieMetadata movie)
@ -69,15 +69,15 @@ namespace NzbDrone.Core.Movies.AlternativeTitles
_titleRepo.Delete(title); _titleRepo.Delete(title);
} }
public List<AlternativeTitle> UpdateTitles(List<AlternativeTitle> titles, MovieMetadata movie) public List<AlternativeTitle> UpdateTitles(List<AlternativeTitle> titles, MovieMetadata movieMetadata)
{ {
int movieId = movie.Id; int movieMetadataId = movieMetadata.Id;
// First update the movie ids so we can correlate them later. // First update the movie ids so we can correlate them later.
titles.ForEach(t => t.MovieMetadataId = movieId); titles.ForEach(t => t.MovieMetadataId = movieMetadataId);
// Then make sure none of them are the same as the main title. // Then make sure none of them are the same as the main title.
titles = titles.Where(t => t.CleanTitle != movie.CleanTitle).ToList(); titles = titles.Where(t => t.CleanTitle != movieMetadata.CleanTitle).ToList();
// Then make sure they are all distinct titles // Then make sure they are all distinct titles
titles = titles.DistinctBy(t => t.CleanTitle).ToList(); titles = titles.DistinctBy(t => t.CleanTitle).ToList();
@ -86,7 +86,7 @@ namespace NzbDrone.Core.Movies.AlternativeTitles
titles = titles.Where(t => !_titleRepo.All().Any(e => e.CleanTitle == t.CleanTitle && e.MovieMetadataId != t.MovieMetadataId)).ToList(); titles = titles.Where(t => !_titleRepo.All().Any(e => e.CleanTitle == t.CleanTitle && e.MovieMetadataId != t.MovieMetadataId)).ToList();
// Now find titles to delete, update and insert. // Now find titles to delete, update and insert.
var existingTitles = _titleRepo.FindByMovieMetadataId(movieId); var existingTitles = _titleRepo.FindByMovieMetadataId(movieMetadataId);
var insert = titles.Where(t => !existingTitles.Contains(t)); var insert = titles.Where(t => !existingTitles.Contains(t));
var update = existingTitles.Where(t => titles.Contains(t)); var update = existingTitles.Where(t => titles.Contains(t));

@ -8,7 +8,7 @@ namespace NzbDrone.Core.Movies.Credits
{ {
public interface ICreditService public interface ICreditService
{ {
List<Credit> GetAllCreditsForMovie(int movieId); List<Credit> GetAllCreditsForMovieMetadata(int movieMetadataId);
Credit AddCredit(Credit credit, MovieMetadata movie); Credit AddCredit(Credit credit, MovieMetadata movie);
List<Credit> AddCredits(List<Credit> credits, MovieMetadata movie); List<Credit> AddCredits(List<Credit> credits, MovieMetadata movie);
Credit GetById(int id); Credit GetById(int id);
@ -25,9 +25,9 @@ namespace NzbDrone.Core.Movies.Credits
_creditRepo = creditRepo; _creditRepo = creditRepo;
} }
public List<Credit> GetAllCreditsForMovie(int movieId) public List<Credit> GetAllCreditsForMovieMetadata(int movieMetadataId)
{ {
return _creditRepo.FindByMovieMetadataId(movieId).ToList(); return _creditRepo.FindByMovieMetadataId(movieMetadataId).ToList();
} }
public Credit AddCredit(Credit credit, MovieMetadata movie) public Credit AddCredit(Credit credit, MovieMetadata movie)
@ -58,15 +58,15 @@ namespace NzbDrone.Core.Movies.Credits
_creditRepo.Delete(credit); _creditRepo.Delete(credit);
} }
public List<Credit> UpdateCredits(List<Credit> credits, MovieMetadata movie) public List<Credit> UpdateCredits(List<Credit> credits, MovieMetadata movieMetadata)
{ {
int movieId = movie.Id; int movieMetadataId = movieMetadata.Id;
// First update the movie ids so we can correlate them later. // First update the movie ids so we can correlate them later.
credits.ForEach(t => t.MovieMetadataId = movieId); credits.ForEach(t => t.MovieMetadataId = movieMetadataId);
// Now find credits to delete, update and insert. // Now find credits to delete, update and insert.
var existingCredits = _creditRepo.FindByMovieMetadataId(movieId); var existingCredits = _creditRepo.FindByMovieMetadataId(movieMetadataId);
// Should never have multiple credits with same credit_id, but check to ensure incase TMDB is on fritz // Should never have multiple credits with same credit_id, but check to ensure incase TMDB is on fritz
var dupeFreeCredits = credits.DistinctBy(m => m.CreditTmdbId).ToList(); var dupeFreeCredits = credits.DistinctBy(m => m.CreditTmdbId).ToList();

@ -7,7 +7,7 @@ namespace NzbDrone.Core.Movies.Translations
{ {
public interface IMovieTranslationRepository : IBasicRepository<MovieTranslation> public interface IMovieTranslationRepository : IBasicRepository<MovieTranslation>
{ {
List<MovieTranslation> FindByMovieMetadataId(int movieId); List<MovieTranslation> FindByMovieMetadataId(int movieMetadataId);
List<MovieTranslation> FindByLanguage(Language language); List<MovieTranslation> FindByLanguage(Language language);
void DeleteForMovies(List<int> movieIds); void DeleteForMovies(List<int> movieIds);
} }
@ -19,9 +19,9 @@ namespace NzbDrone.Core.Movies.Translations
{ {
} }
public List<MovieTranslation> FindByMovieMetadataId(int movieId) public List<MovieTranslation> FindByMovieMetadataId(int movieMetadataId)
{ {
return Query(x => x.MovieMetadataId == movieId); return Query(x => x.MovieMetadataId == movieMetadataId);
} }
public List<MovieTranslation> FindByLanguage(Language language) public List<MovieTranslation> FindByLanguage(Language language)

@ -10,7 +10,7 @@ namespace NzbDrone.Core.Movies.Translations
{ {
public interface IMovieTranslationService public interface IMovieTranslationService
{ {
List<MovieTranslation> GetAllTranslationsForMovie(int movieId); List<MovieTranslation> GetAllTranslationsForMovieMetadata(int movieMetadataId);
List<MovieTranslation> GetAllTranslationsForLanguage(Language language); List<MovieTranslation> GetAllTranslationsForLanguage(Language language);
List<MovieTranslation> UpdateTranslations(List<MovieTranslation> titles, MovieMetadata movie); List<MovieTranslation> UpdateTranslations(List<MovieTranslation> titles, MovieMetadata movie);
} }
@ -27,9 +27,9 @@ namespace NzbDrone.Core.Movies.Translations
_logger = logger; _logger = logger;
} }
public List<MovieTranslation> GetAllTranslationsForMovie(int movieId) public List<MovieTranslation> GetAllTranslationsForMovieMetadata(int movieMetadataId)
{ {
return _translationRepo.FindByMovieMetadataId(movieId).ToList(); return _translationRepo.FindByMovieMetadataId(movieMetadataId).ToList();
} }
public List<MovieTranslation> GetAllTranslationsForLanguage(Language language) public List<MovieTranslation> GetAllTranslationsForLanguage(Language language)
@ -42,12 +42,12 @@ namespace NzbDrone.Core.Movies.Translations
_translationRepo.Delete(title); _translationRepo.Delete(title);
} }
public List<MovieTranslation> UpdateTranslations(List<MovieTranslation> translations, MovieMetadata movie) public List<MovieTranslation> UpdateTranslations(List<MovieTranslation> translations, MovieMetadata movieMetadata)
{ {
int movieId = movie.Id; int movieMetadataId = movieMetadata.Id;
// First update the movie ids so we can correlate them later // First update the movie ids so we can correlate them later
translations.ForEach(t => t.MovieMetadataId = movieId); translations.ForEach(t => t.MovieMetadataId = movieMetadataId);
// Then throw out any we don't have languages for // Then throw out any we don't have languages for
translations = translations.Where(t => t.Language != null).ToList(); translations = translations.Where(t => t.Language != null).ToList();
@ -56,7 +56,7 @@ namespace NzbDrone.Core.Movies.Translations
translations = translations.DistinctBy(t => t.Language).ToList(); translations = translations.DistinctBy(t => t.Language).ToList();
// Now find translations to delete, update and insert // Now find translations to delete, update and insert
var existingTranslations = _translationRepo.FindByMovieMetadataId(movieId); var existingTranslations = _translationRepo.FindByMovieMetadataId(movieMetadataId);
translations.ForEach(c => c.Id = existingTranslations.FirstOrDefault(t => t.Language == c.Language)?.Id ?? 0); translations.ForEach(c => c.Id = existingTranslations.FirstOrDefault(t => t.Language == c.Language)?.Id ?? 0);

@ -288,7 +288,7 @@ namespace NzbDrone.Core.Organizer
if (!movie.MovieMetadata.Value.Translations.Any()) if (!movie.MovieMetadata.Value.Translations.Any())
{ {
titles = _movieTranslationService.GetAllTranslationsForMovie(movie.Id).Where(t => t.Language == language).ToList(); titles = _movieTranslationService.GetAllTranslationsForMovieMetadata(movie.MovieMetadataId).Where(t => t.Language == language).ToList();
} }
return titles.FirstOrDefault()?.Title ?? movie.Title; return titles.FirstOrDefault()?.Title ?? movie.Title;

@ -59,7 +59,7 @@ namespace Radarr.Api.V3.Calendar
} }
var availDelay = _configService.AvailabilityDelay; var availDelay = _configService.AvailabilityDelay;
var translations = _movieTranslationService.GetAllTranslationsForMovie(movie.Id); var translations = _movieTranslationService.GetAllTranslationsForMovieMetadata(movie.Id);
var translation = GetMovieTranslation(translations, movie.MovieMetadata); var translation = GetMovieTranslation(translations, movie.MovieMetadata);
var resource = movie.ToResource(availDelay, translation, _qualityUpgradableSpecification); var resource = movie.ToResource(availDelay, translation, _qualityUpgradableSpecification);

@ -29,13 +29,13 @@ namespace Radarr.Api.V3.Credits
{ {
if (movieMetadataId.HasValue) if (movieMetadataId.HasValue)
{ {
return _creditService.GetAllCreditsForMovie(movieMetadataId.Value).ToResource(); return _creditService.GetAllCreditsForMovieMetadata(movieMetadataId.Value).ToResource();
} }
if (movieId.HasValue) if (movieId.HasValue)
{ {
var movie = _movieService.GetMovie(movieId.Value); var movie = _movieService.GetMovie(movieId.Value);
return _creditService.GetAllCreditsForMovie(movie.MovieMetadataId).ToResource(); return _creditService.GetAllCreditsForMovieMetadata(movie.MovieMetadataId).ToResource();
} }
return _creditService.GetAllCredits().ToResource(); return _creditService.GetAllCredits().ToResource();

@ -30,13 +30,13 @@ namespace Radarr.Api.V3.Movies
{ {
if (movieMetadataId.HasValue) if (movieMetadataId.HasValue)
{ {
return _altTitleService.GetAllTitlesForMovie(movieMetadataId.Value).ToResource(); return _altTitleService.GetAllTitlesForMovieMetadata(movieMetadataId.Value).ToResource();
} }
if (movieId.HasValue) if (movieId.HasValue)
{ {
var movie = _movieService.GetMovie(movieId.Value); var movie = _movieService.GetMovie(movieId.Value);
return _altTitleService.GetAllTitlesForMovie(movie.MovieMetadataId).ToResource(); return _altTitleService.GetAllTitlesForMovieMetadata(movie.MovieMetadataId).ToResource();
} }
return _altTitleService.GetAllTitles().ToResource(); return _altTitleService.GetAllTitles().ToResource();

@ -165,7 +165,7 @@ namespace Radarr.Api.V3.Movies
var availDelay = _configService.AvailabilityDelay; var availDelay = _configService.AvailabilityDelay;
var translations = _movieTranslationService.GetAllTranslationsForMovie(movie.MovieMetadataId); var translations = _movieTranslationService.GetAllTranslationsForMovieMetadata(movie.MovieMetadataId);
var translation = GetMovieTranslation(translations, movie.MovieMetadata, (Language)_configService.MovieInfoLanguage); var translation = GetMovieTranslation(translations, movie.MovieMetadata, (Language)_configService.MovieInfoLanguage);
var resource = movie.ToResource(availDelay, translation, _qualityUpgradableSpecification); var resource = movie.ToResource(availDelay, translation, _qualityUpgradableSpecification);
@ -236,7 +236,7 @@ namespace Radarr.Api.V3.Movies
var updatedMovie = _moviesService.UpdateMovie(model); var updatedMovie = _moviesService.UpdateMovie(model);
var availDelay = _configService.AvailabilityDelay; var availDelay = _configService.AvailabilityDelay;
var translations = _movieTranslationService.GetAllTranslationsForMovie(movie.Id); var translations = _movieTranslationService.GetAllTranslationsForMovieMetadata(movie.MovieMetadataId);
var translation = GetMovieTranslation(translations, movie.MovieMetadata, (Language)_configService.MovieInfoLanguage); var translation = GetMovieTranslation(translations, movie.MovieMetadata, (Language)_configService.MovieInfoLanguage);
BroadcastResourceChange(ModelAction.Updated, updatedMovie.ToResource(availDelay, translation, _qualityUpgradableSpecification)); BroadcastResourceChange(ModelAction.Updated, updatedMovie.ToResource(availDelay, translation, _qualityUpgradableSpecification));
@ -267,7 +267,7 @@ namespace Radarr.Api.V3.Movies
public void Handle(MovieImportedEvent message) public void Handle(MovieImportedEvent message)
{ {
var availDelay = _configService.AvailabilityDelay; var availDelay = _configService.AvailabilityDelay;
var translations = _movieTranslationService.GetAllTranslationsForMovie(message.ImportedMovie.Movie.Id); var translations = _movieTranslationService.GetAllTranslationsForMovieMetadata(message.ImportedMovie.Movie.MovieMetadataId);
var translation = GetMovieTranslation(translations, message.ImportedMovie.Movie.MovieMetadata, (Language)_configService.MovieInfoLanguage); var translation = GetMovieTranslation(translations, message.ImportedMovie.Movie.MovieMetadata, (Language)_configService.MovieInfoLanguage);
BroadcastResourceChange(ModelAction.Updated, message.ImportedMovie.Movie.ToResource(availDelay, translation, _qualityUpgradableSpecification)); BroadcastResourceChange(ModelAction.Updated, message.ImportedMovie.Movie.ToResource(availDelay, translation, _qualityUpgradableSpecification));
} }
@ -287,7 +287,7 @@ namespace Radarr.Api.V3.Movies
public void Handle(MovieUpdatedEvent message) public void Handle(MovieUpdatedEvent message)
{ {
var availDelay = _configService.AvailabilityDelay; var availDelay = _configService.AvailabilityDelay;
var translations = _movieTranslationService.GetAllTranslationsForMovie(message.Movie.Id); var translations = _movieTranslationService.GetAllTranslationsForMovieMetadata(message.Movie.MovieMetadataId);
var translation = GetMovieTranslation(translations, message.Movie.MovieMetadata, (Language)_configService.MovieInfoLanguage); var translation = GetMovieTranslation(translations, message.Movie.MovieMetadata, (Language)_configService.MovieInfoLanguage);
BroadcastResourceChange(ModelAction.Updated, message.Movie.ToResource(availDelay, translation, _qualityUpgradableSpecification)); BroadcastResourceChange(ModelAction.Updated, message.Movie.ToResource(availDelay, translation, _qualityUpgradableSpecification));
} }
@ -296,7 +296,7 @@ namespace Radarr.Api.V3.Movies
public void Handle(MovieEditedEvent message) public void Handle(MovieEditedEvent message)
{ {
var availDelay = _configService.AvailabilityDelay; var availDelay = _configService.AvailabilityDelay;
var translations = _movieTranslationService.GetAllTranslationsForMovie(message.Movie.Id); var translations = _movieTranslationService.GetAllTranslationsForMovieMetadata(message.Movie.MovieMetadataId);
var translation = GetMovieTranslation(translations, message.Movie.MovieMetadata, (Language)_configService.MovieInfoLanguage); var translation = GetMovieTranslation(translations, message.Movie.MovieMetadata, (Language)_configService.MovieInfoLanguage);
BroadcastResourceChange(ModelAction.Updated, message.Movie.ToResource(availDelay, translation, _qualityUpgradableSpecification)); BroadcastResourceChange(ModelAction.Updated, message.Movie.ToResource(availDelay, translation, _qualityUpgradableSpecification));
} }
@ -314,7 +314,7 @@ namespace Radarr.Api.V3.Movies
public void Handle(MovieRenamedEvent message) public void Handle(MovieRenamedEvent message)
{ {
var availDelay = _configService.AvailabilityDelay; var availDelay = _configService.AvailabilityDelay;
var translations = _movieTranslationService.GetAllTranslationsForMovie(message.Movie.Id); var translations = _movieTranslationService.GetAllTranslationsForMovieMetadata(message.Movie.MovieMetadataId);
var translation = GetMovieTranslation(translations, message.Movie.MovieMetadata, (Language)_configService.MovieInfoLanguage); var translation = GetMovieTranslation(translations, message.Movie.MovieMetadata, (Language)_configService.MovieInfoLanguage);
BroadcastResourceChange(ModelAction.Updated, message.Movie.ToResource(availDelay, translation, _qualityUpgradableSpecification)); BroadcastResourceChange(ModelAction.Updated, message.Movie.ToResource(availDelay, translation, _qualityUpgradableSpecification));
} }

Loading…
Cancel
Save