Manual join of Series for EpisodesBetweenDates

pull/4/head
Mark McDowall 12 years ago
parent df38aa2307
commit a4d69cc5ce

@ -54,7 +54,7 @@ namespace NzbDrone.Core.DataAugmentation.Scene
public string GetSceneName(int seriesId, int seasonNumber = -1) 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); var mapping = _repository.FindByTvdbId(tvDbId);

@ -55,7 +55,7 @@ namespace NzbDrone.Core.MediaCover
} }
catch (Exception e) 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);
} }
} }

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

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

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

@ -13,6 +13,7 @@ namespace NzbDrone.Core.Tv
Series FindByTvdbId(int tvdbId); Series FindByTvdbId(int tvdbId);
void SetSeriesType(int seriesId, SeriesTypes seriesTypes); void SetSeriesType(int seriesId, SeriesTypes seriesTypes);
void SetTvRageId(int seriesId, int tvRageId); void SetTvRageId(int seriesId, int tvRageId);
List<Series> SeriesIsInList(IEnumerable<int> ids);
} }
public class SeriesRepository : BasicRepository<Series>, ISeriesRepository public class SeriesRepository : BasicRepository<Series>, ISeriesRepository
@ -39,7 +40,7 @@ namespace NzbDrone.Core.Tv
public Series FindByTvdbId(int tvdbId) 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) 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); 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)));
}
} }
} }

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

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

Loading…
Cancel
Save