|
|
|
@ -118,7 +118,6 @@ namespace NzbDrone.Core.Tv
|
|
|
|
|
|
|
|
|
|
public PagingSpec<Episode> EpisodesWhereCutoffUnmet(PagingSpec<Episode> pagingSpec, List<QualitiesBelowCutoff> qualitiesBelowCutoff, bool includeSpecials)
|
|
|
|
|
{
|
|
|
|
|
var currentTime = DateTime.UtcNow;
|
|
|
|
|
var startingSeasonNumber = 1;
|
|
|
|
|
|
|
|
|
|
if (includeSpecials)
|
|
|
|
@ -126,8 +125,8 @@ namespace NzbDrone.Core.Tv
|
|
|
|
|
startingSeasonNumber = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pagingSpec.TotalRecords = EpisodesWhereCutoffUnmetQuery(pagingSpec, currentTime, qualitiesBelowCutoff, startingSeasonNumber).GetRowCount();
|
|
|
|
|
pagingSpec.Records = EpisodesWhereCutoffUnmetQuery(pagingSpec, currentTime, qualitiesBelowCutoff, startingSeasonNumber).ToList();
|
|
|
|
|
pagingSpec.TotalRecords = EpisodesWhereCutoffUnmetQuery(pagingSpec, qualitiesBelowCutoff, startingSeasonNumber).GetRowCount();
|
|
|
|
|
pagingSpec.Records = EpisodesWhereCutoffUnmetQuery(pagingSpec, qualitiesBelowCutoff, startingSeasonNumber).ToList();
|
|
|
|
|
|
|
|
|
|
return pagingSpec;
|
|
|
|
|
}
|
|
|
|
@ -196,26 +195,31 @@ namespace NzbDrone.Core.Tv
|
|
|
|
|
.Where(pagingSpec.FilterExpression)
|
|
|
|
|
.AndWhere(e => e.EpisodeFileId == 0)
|
|
|
|
|
.AndWhere(e => e.SeasonNumber >= startingSeasonNumber)
|
|
|
|
|
.AndWhere(e => e.AirDateUtc <= currentTime)
|
|
|
|
|
.AndWhere(BuildAirDateUtcCutoffWhereClause(currentTime))
|
|
|
|
|
.OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection())
|
|
|
|
|
.Skip(pagingSpec.PagingOffset())
|
|
|
|
|
.Take(pagingSpec.PageSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SortBuilder<Episode> EpisodesWhereCutoffUnmetQuery(PagingSpec<Episode> pagingSpec, DateTime currentTime, List<QualitiesBelowCutoff> qualitiesBelowCutoff, int startingSeasonNumber)
|
|
|
|
|
private SortBuilder<Episode> EpisodesWhereCutoffUnmetQuery(PagingSpec<Episode> pagingSpec, List<QualitiesBelowCutoff> qualitiesBelowCutoff, int startingSeasonNumber)
|
|
|
|
|
{
|
|
|
|
|
return Query.Join<Episode, Series>(JoinType.Inner, e => e.Series, (e, s) => e.SeriesId == s.Id)
|
|
|
|
|
.Join<Episode, EpisodeFile>(JoinType.Left, e => e.EpisodeFile, (e, s) => e.EpisodeFileId == s.Id)
|
|
|
|
|
.Where(pagingSpec.FilterExpression)
|
|
|
|
|
.AndWhere(e => e.EpisodeFileId != 0)
|
|
|
|
|
.AndWhere(e => e.SeasonNumber >= startingSeasonNumber)
|
|
|
|
|
.AndWhere(e => e.AirDateUtc <= currentTime)
|
|
|
|
|
.AndWhere(BuildQualityCutoffWhereClause(qualitiesBelowCutoff))
|
|
|
|
|
.OrderBy(pagingSpec.OrderByClause(), pagingSpec.ToSortDirection())
|
|
|
|
|
.Skip(pagingSpec.PagingOffset())
|
|
|
|
|
.Take(pagingSpec.PageSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string BuildAirDateUtcCutoffWhereClause(DateTime currentTime)
|
|
|
|
|
{
|
|
|
|
|
return String.Format("WHERE datetime(strftime('%s', [t0].[AirDateUtc]) + [t1].[RunTime] * 60, 'unixepoch') <= '{0}'",
|
|
|
|
|
currentTime.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string BuildQualityCutoffWhereClause(List<QualitiesBelowCutoff> qualitiesBelowCutoff)
|
|
|
|
|
{
|
|
|
|
|
var clauses = new List<String>();
|
|
|
|
|