Fixes an issue with movies not being added with same title slug as existing movies.

pull/74/head^2
Leonardo Galli 8 years ago
parent 893e20c27b
commit 994e881ba6

@ -24,13 +24,15 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
private readonly IHttpRequestBuilderFactory _requestBuilder; private readonly IHttpRequestBuilderFactory _requestBuilder;
private readonly IHttpRequestBuilderFactory _movieBuilder; private readonly IHttpRequestBuilderFactory _movieBuilder;
private readonly ITmdbConfigService _configService; private readonly ITmdbConfigService _configService;
private readonly IMovieService _movieService;
public SkyHookProxy(IHttpClient httpClient, ISonarrCloudRequestBuilder requestBuilder, ITmdbConfigService configService, Logger logger) public SkyHookProxy(IHttpClient httpClient, ISonarrCloudRequestBuilder requestBuilder, ITmdbConfigService configService, IMovieService movieService, Logger logger)
{ {
_httpClient = httpClient; _httpClient = httpClient;
_requestBuilder = requestBuilder.SkyHookTvdb; _requestBuilder = requestBuilder.SkyHookTvdb;
_movieBuilder = requestBuilder.TMDB; _movieBuilder = requestBuilder.TMDB;
_configService = configService; _configService = configService;
_movieService = movieService;
_logger = logger; _logger = logger;
} }
@ -93,6 +95,13 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
movie.InCinemas = DateTime.Parse(resource.release_date); movie.InCinemas = DateTime.Parse(resource.release_date);
movie.Year = movie.InCinemas.Value.Year; movie.Year = movie.InCinemas.Value.Year;
var slugResult = _movieService.FindByTitleSlug(movie.TitleSlug);
if (slugResult != null)
{
_logger.Debug("Movie with this title slug already exists. Adding year...");
}
movie.TitleSlug += "-" + movie.Year.ToString();
movie.Images.Add(_configService.GetCoverForURL(resource.poster_path, MediaCoverTypes.Poster));//TODO: Update to load image specs from tmdb page! movie.Images.Add(_configService.GetCoverForURL(resource.poster_path, MediaCoverTypes.Poster));//TODO: Update to load image specs from tmdb page!
movie.Images.Add(_configService.GetCoverForURL(resource.backdrop_path, MediaCoverTypes.Banner)); movie.Images.Add(_configService.GetCoverForURL(resource.backdrop_path, MediaCoverTypes.Banner));
movie.Runtime = resource.runtime; movie.Runtime = resource.runtime;
@ -320,6 +329,14 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
string titleSlug = result.title; string titleSlug = result.title;
imdbMovie.TitleSlug = titleSlug.ToLower().Replace(" ", "-"); imdbMovie.TitleSlug = titleSlug.ToLower().Replace(" ", "-");
imdbMovie.Year = DateTime.Parse(result.release_date).Year; imdbMovie.Year = DateTime.Parse(result.release_date).Year;
var slugResult = _movieService.FindByTitleSlug(imdbMovie.TitleSlug);
if (slugResult != null)
{
_logger.Debug("Movie with this title slug already exists. Adding year...");
}
imdbMovie.TitleSlug += "-" + imdbMovie.Year.ToString();
imdbMovie.Images = new List<MediaCover.MediaCover>(); imdbMovie.Images = new List<MediaCover.MediaCover>();
imdbMovie.Overview = result.overview; imdbMovie.Overview = result.overview;
try try

@ -13,6 +13,7 @@ namespace NzbDrone.Core.Tv
Movie FindByTitle(string cleanTitle); Movie FindByTitle(string cleanTitle);
Movie FindByTitle(string cleanTitle, int year); Movie FindByTitle(string cleanTitle, int year);
Movie FindByImdbId(string imdbid); Movie FindByImdbId(string imdbid);
Movie FindByTitleSlug(string slug);
List<Movie> GetMoviesByFileId(int fileId); List<Movie> GetMoviesByFileId(int fileId);
void SetFileId(int fileId, int movieId); void SetFileId(int fileId, int movieId);
} }
@ -114,5 +115,9 @@ namespace NzbDrone.Core.Tv
SetFields(new Movie { Id = episodeId, MovieFileId = fileId }, movie => movie.MovieFileId); SetFields(new Movie { Id = episodeId, MovieFileId = fileId }, movie => movie.MovieFileId);
} }
public Movie FindByTitleSlug(string slug)
{
return Query.Where(m => m.TitleSlug == slug).FirstOrDefault();
}
} }
} }

@ -24,6 +24,7 @@ namespace NzbDrone.Core.Tv
Movie FindByTitle(string title); Movie FindByTitle(string title);
Movie FindByTitle(string title, int year); Movie FindByTitle(string title, int year);
Movie FindByTitleInexact(string title); Movie FindByTitleInexact(string title);
Movie FindByTitleSlug(string slug);
Movie GetMovieByFileId(int fileId); Movie GetMovieByFileId(int fileId);
void DeleteMovie(int movieId, bool deleteFiles); void DeleteMovie(int movieId, bool deleteFiles);
List<Movie> GetAllMovies(); List<Movie> GetAllMovies();
@ -218,5 +219,10 @@ namespace NzbDrone.Core.Tv
{ {
return _movieRepository.GetMoviesByFileId(fileId).First(); return _movieRepository.GetMoviesByFileId(fileId).First();
} }
public Movie FindByTitleSlug(string slug)
{
return _movieRepository.FindByTitleSlug(slug);
}
} }
} }

Loading…
Cancel
Save