|
|
@ -1,7 +1,9 @@
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using Marr.Data.QGen;
|
|
|
|
using Marr.Data.QGen;
|
|
|
|
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
using NzbDrone.Core.Datastore.Extentions;
|
|
|
|
using NzbDrone.Core.Datastore.Extentions;
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
|
using NzbDrone.Core.Messaging.Events;
|
|
|
@ -14,8 +16,8 @@ namespace NzbDrone.Core.Tv
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Episode Find(int seriesId, int season, int episodeNumber);
|
|
|
|
Episode Find(int seriesId, int season, int episodeNumber);
|
|
|
|
Episode Find(int seriesId, int absoluteEpisodeNumber);
|
|
|
|
Episode Find(int seriesId, int absoluteEpisodeNumber);
|
|
|
|
Episode Get(int seriesId, String date);
|
|
|
|
Episode Get(int seriesId, string date);
|
|
|
|
Episode Find(int seriesId, String date);
|
|
|
|
Episode Find(int seriesId, string date);
|
|
|
|
List<Episode> GetEpisodes(int seriesId);
|
|
|
|
List<Episode> GetEpisodes(int seriesId);
|
|
|
|
List<Episode> GetEpisodes(int seriesId, int seasonNumber);
|
|
|
|
List<Episode> GetEpisodes(int seriesId, int seasonNumber);
|
|
|
|
List<Episode> GetEpisodeByFileId(int fileId);
|
|
|
|
List<Episode> GetEpisodeByFileId(int fileId);
|
|
|
@ -32,11 +34,13 @@ namespace NzbDrone.Core.Tv
|
|
|
|
public class EpisodeRepository : BasicRepository<Episode>, IEpisodeRepository
|
|
|
|
public class EpisodeRepository : BasicRepository<Episode>, IEpisodeRepository
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private readonly IDatabase _database;
|
|
|
|
private readonly IDatabase _database;
|
|
|
|
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
|
|
|
|
public EpisodeRepository(IDatabase database, IEventAggregator eventAggregator)
|
|
|
|
public EpisodeRepository(IDatabase database, IEventAggregator eventAggregator, Logger logger)
|
|
|
|
: base(database, eventAggregator)
|
|
|
|
: base(database, eventAggregator)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_database = database;
|
|
|
|
_database = database;
|
|
|
|
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Episode Find(int seriesId, int season, int episodeNumber)
|
|
|
|
public Episode Find(int seriesId, int season, int episodeNumber)
|
|
|
@ -54,18 +58,21 @@ namespace NzbDrone.Core.Tv
|
|
|
|
.SingleOrDefault();
|
|
|
|
.SingleOrDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Episode Get(int seriesId, String date)
|
|
|
|
public Episode Get(int seriesId, string date)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Query.Where(s => s.SeriesId == seriesId)
|
|
|
|
var episode = FindOneByAirDate(seriesId, date);
|
|
|
|
.AndWhere(s => s.AirDate == date)
|
|
|
|
|
|
|
|
.Single();
|
|
|
|
if (episode == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw new InvalidOperationException("Expected at one episode");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return episode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Episode Find(int seriesId, String date)
|
|
|
|
public Episode Find(int seriesId, string date)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Query.Where(s => s.SeriesId == seriesId)
|
|
|
|
return FindOneByAirDate(seriesId, date);
|
|
|
|
.AndWhere(s => s.AirDate == date)
|
|
|
|
|
|
|
|
.SingleOrDefault();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<Episode> GetEpisodes(int seriesId)
|
|
|
|
public List<Episode> GetEpisodes(int seriesId)
|
|
|
@ -207,5 +214,28 @@ namespace NzbDrone.Core.Tv
|
|
|
|
|
|
|
|
|
|
|
|
return String.Format("({0})", String.Join(" OR ", clauses));
|
|
|
|
return String.Format("({0})", String.Join(" OR ", clauses));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Episode FindOneByAirDate(int seriesId, string date)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var episodes = Query.Where(s => s.SeriesId == seriesId)
|
|
|
|
|
|
|
|
.AndWhere(s => s.AirDate == date)
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!episodes.Any()) return null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (episodes.Count == 1) return episodes.First();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_logger.Debug("Multiple episodes with the same air date were found, will exclude specials");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var regularEpisodes = episodes.Where(e => e.SeasonNumber > 0).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (regularEpisodes.Count == 1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.Debug("Left with one episode after excluding specials");
|
|
|
|
|
|
|
|
return regularEpisodes.First();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
throw new InvalidOperationException("Multiple episodes with the same air date found");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|