Fixed: Alt titles with less than 4 votes being used.

Leonardo Galli 7 years ago
parent 349be2c454
commit 8caf648a0b

@ -1,11 +1,15 @@
using NzbDrone.Core.Datastore;
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Messaging.Events;
namespace NzbDrone.Core.Movies.AlternativeTitles
{
public interface IAlternativeTitleRepository : IBasicRepository<AlternativeTitle>
{
AlternativeTitle FindBySourceId(int sourceId);
List<AlternativeTitle> FindBySourceIds(List<int> sourceIds);
}
public class AlternativeTitleRepository : BasicRepository<AlternativeTitle>, IAlternativeTitleRepository
@ -17,5 +21,15 @@ namespace NzbDrone.Core.Movies.AlternativeTitles
{
_database = database;
}
public AlternativeTitle FindBySourceId(int sourceId)
{
return Query.Where(t => t.SourceId == sourceId).FirstOrDefault();
}
public List<AlternativeTitle> FindBySourceIds(List<int> sourceIds)
{
return Query.Where(t => t.SourceId.In(sourceIds)).ToList();
}
}
}

@ -23,6 +23,7 @@ namespace NzbDrone.Core.Movies.AlternativeTitles
AlternativeTitle AddAltTitle(AlternativeTitle title, Movie movie);
List<AlternativeTitle> AddAltTitles(List<AlternativeTitle> titles, Movie movie);
AlternativeTitle GetById(int id);
void DeleteNotEnoughVotes(List<AlternativeTitle> mappingsTitles);
}
public class AlternativeTitleService : IAlternativeTitleService
@ -66,5 +67,17 @@ namespace NzbDrone.Core.Movies.AlternativeTitles
{
return _titleRepo.Get(id);
}
public void RemoveTitle(AlternativeTitle title)
{
_titleRepo.Delete(title);
}
public void DeleteNotEnoughVotes(List<AlternativeTitle> mappingsTitles)
{
var toRemove = mappingsTitles.Where(t => t.SourceType == SourceType.Mappings && t.Votes < 4);
var realT = _titleRepo.FindBySourceIds(toRemove.Select(t => t.SourceId).ToList());
_titleRepo.DeleteMany(realT);
}
}
}

@ -126,6 +126,7 @@
<Compile Include="Authentication\UserService.cs" />
<Compile Include="Datastore\Migration\123_create_netimport_table.cs" />
<Compile Include="Datastore\Migration\140_add_alternative_titles_table.cs" />
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedAlternativeTitles.cs" />
<Compile Include="MediaFiles\Events\MovieFileUpdatedEvent.cs" />
<Compile Include="Datastore\Migration\134_add_remux_qualities_for_the_wankers.cs" />
<Compile Include="Datastore\Migration\129_add_parsed_movie_info_to_pending_release.cs" />

@ -121,9 +121,14 @@ namespace NzbDrone.Core.Tv
var mappingsTitles = mappings.Item1;
movie.AlternativeTitles.AddRange(_titleService.AddAltTitles(movieInfo.AlternativeTitles, movie));
_titleService.DeleteNotEnoughVotes(mappingsTitles);
mappingsTitles = mappingsTitles.ExceptBy(t => t.CleanTitle, movie.AlternativeTitles,
t => t.CleanTitle, EqualityComparer<string>.Default).ToList();
mappingsTitles = mappingsTitles.Where(t => t.Votes > 3).ToList();
movie.AlternativeTitles.AddRange(_titleService.AddAltTitles(mappingsTitles, movie));
@ -132,11 +137,20 @@ namespace NzbDrone.Core.Tv
movie.SecondaryYear = mappings.Item2.Year;
movie.SecondaryYearSourceId = mappings.Item2.SourceId;
}
else
{
movie.SecondaryYear = null;
movie.SecondaryYearSourceId = 0;
}
}
catch (RadarrAPIException ex)
{
//Not that wild, could just be a 404.
}
catch (Exception ex)
{
_logger.Info(ex, "Unable to communicate with Mappings Server.");
}
_movieService.UpdateMovie(movie);

Loading…
Cancel
Save