Manual join of Series for EpisodesBetweenDates

This commit is contained in:
Mark McDowall 2013-04-16 23:55:39 -07:00
parent df38aa2307
commit a4d69cc5ce
9 changed files with 33 additions and 12 deletions

View File

@ -54,7 +54,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene
public string GetSceneName(int seriesId, int seasonNumber = -1)
{
var tvDbId = _seriesService.FindByTvdbId(seriesId).TvDbId;
var tvDbId = _seriesService.FindByTvdbId(seriesId).TvdbId;
var mapping = _repository.FindByTvdbId(tvDbId);

View File

@ -55,7 +55,7 @@ namespace NzbDrone.Core.MediaCover
}
catch (Exception e)
{
_logger.ErrorException("Couldn't download media cover for " + series.TvDbId, e);
_logger.ErrorException("Couldn't download media cover for " + series.TvdbId, e);
}
}

View File

@ -47,7 +47,7 @@ namespace NzbDrone.Core.MetadataSource
private static Series MapSeries(Show show)
{
var series = new Series();
series.TvDbId = show.tvdb_id;
series.TvdbId = show.tvdb_id;
series.TvRageId = show.tvrage_id;
series.ImdbId = show.imdb_id;
series.Title = show.title;

View File

@ -47,15 +47,19 @@ namespace NzbDrone.Core.Tv
private readonly IEpisodeRepository _episodeRepository;
private readonly IEventAggregator _eventAggregator;
private readonly IConfigService _configService;
private readonly ISeriesService _seriesService;
private readonly Logger _logger;
public EpisodeService(IProvideEpisodeInfo episodeInfoProxy, ISeasonRepository seasonRepository, IEpisodeRepository episodeRepository, IEventAggregator eventAggregator, IConfigService configService, Logger logger)
public EpisodeService(IProvideEpisodeInfo episodeInfoProxy, ISeasonRepository seasonRepository,
IEpisodeRepository episodeRepository, IEventAggregator eventAggregator,
IConfigService configService, ISeriesService seriesService, Logger logger)
{
_episodeInfoProxy = episodeInfoProxy;
_seasonRepository = seasonRepository;
_episodeRepository = episodeRepository;
_eventAggregator = eventAggregator;
_configService = configService;
_seriesService = seriesService;
_logger = logger;
}
@ -89,7 +93,6 @@ namespace NzbDrone.Core.Tv
return _episodeRepository.GetEpisodes(seriesId, seasonNumber);
}
public List<Episode> EpisodesWithoutFiles(bool includeSpecials)
{
return _episodeRepository.EpisodesWithoutFiles(includeSpecials);
@ -111,7 +114,7 @@ namespace NzbDrone.Core.Tv
var successCount = 0;
var failCount = 0;
var tvdbEpisodes = _episodeInfoProxy.GetEpisodeInfo(series.TvDbId);
var tvdbEpisodes = _episodeInfoProxy.GetEpisodeInfo(series.TvdbId);
var seriesEpisodes = GetEpisodeBySeries(series.Id);
var updateList = new List<Episode>();
@ -281,7 +284,15 @@ namespace NzbDrone.Core.Tv
public List<Episode> EpisodesBetweenDates(DateTime start, DateTime end)
{
return _episodeRepository.EpisodesBetweenDates(start.ToUniversalTime(), end.ToUniversalTime());
var episodes = _episodeRepository.EpisodesBetweenDates(start.ToUniversalTime(), end.ToUniversalTime());
var series = _seriesService.GetSeriesInList(episodes.Select(e => e.SeriesId).Distinct());
episodes.ForEach(e =>
{
e.Series = series.SingleOrDefault(s => s.Id == e.SeriesId);
});
return episodes;
}
public void Handle(EpisodeGrabbedEvent message)

View File

@ -24,7 +24,7 @@ namespace NzbDrone.Core.Tv
Images = new List<MediaCover.MediaCover>();
}
public int TvDbId { get; set; }
public int TvdbId { get; set; }
public int TvRageId { get; set; }
public string ImdbId { get; set; }
public string Title { get; set; }

View File

@ -13,6 +13,7 @@ namespace NzbDrone.Core.Tv
Series FindByTvdbId(int tvdbId);
void SetSeriesType(int seriesId, SeriesTypes seriesTypes);
void SetTvRageId(int seriesId, int tvRageId);
List<Series> SeriesIsInList(IEnumerable<int> ids);
}
public class SeriesRepository : BasicRepository<Series>, ISeriesRepository
@ -39,7 +40,7 @@ namespace NzbDrone.Core.Tv
public Series FindByTvdbId(int tvdbId)
{
return Query.SingleOrDefault(s => s.TvDbId.Equals(tvdbId));
return Query.SingleOrDefault(s => s.TvdbId.Equals(tvdbId));
}
public void SetSeriesType(int seriesId, SeriesTypes seriesType)
@ -51,5 +52,10 @@ namespace NzbDrone.Core.Tv
{
SetFields(new Series { Id = seriesId, TvRageId = tvRageId }, s => s.TvRageId);
}
public List<Series> SeriesIsInList(IEnumerable<int> ids)
{
return Query.Where(String.Format("Id IN ({0})", String.Join(",", ids)));
}
}
}

View File

@ -32,6 +32,7 @@ namespace NzbDrone.Core.Tv
List<Series> GetAllSeries();
void UpdateSeries(Series series);
bool SeriesPathExists(string folder);
List<Series> GetSeriesInList(IEnumerable<int> seriesIds);
}
public class SeriesService : ISeriesService, IHandleAsync<SeriesAddedEvent>
@ -63,11 +64,10 @@ namespace NzbDrone.Core.Tv
return _seriesRepository.Get(id).Monitored;
}
public Series UpdateSeriesInfo(int seriesId)
{
var series = _seriesRepository.Get(seriesId);
var seriesInfo = _seriesInfoProxy.GetSeriesInfo(series.TvDbId);
var seriesInfo = _seriesInfoProxy.GetSeriesInfo(series.TvdbId);
series.Title = seriesInfo.Title;
series.AirTime = seriesInfo.AirTime;
@ -179,6 +179,11 @@ namespace NzbDrone.Core.Tv
return _seriesRepository.SeriesPathExists(folder);
}
public List<Series> GetSeriesInList(IEnumerable<int> seriesIds)
{
return _seriesRepository.SeriesIsInList(seriesIds);
}
public void HandleAsync(SeriesAddedEvent message)
{
UpdateSeriesInfo(message.Series.Id);

View File

@ -2,7 +2,6 @@
<FileVersion>1</FileVersion>
<AutoEnableOnStartup>True</AutoEnableOnStartup>
<AllowParallelTestExecution>true</AllowParallelTestExecution>
<AllowTestsToRunInParallelWithThemselves>true</AllowTestsToRunInParallelWithThemselves>
<FrameworkUtilisationTypeForNUnit>UseDynamicAnalysis</FrameworkUtilisationTypeForNUnit>
<FrameworkUtilisationTypeForGallio>Disabled</FrameworkUtilisationTypeForGallio>
<FrameworkUtilisationTypeForMSpec>Disabled</FrameworkUtilisationTypeForMSpec>