1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

Fixed: Missing won't show episodes that are on air

This commit is contained in:
Mark McDowall 2014-10-24 19:44:29 -07:00
parent b538b450f5
commit 71416eea29
2 changed files with 30 additions and 6 deletions

View File

@ -1,4 +1,5 @@
using System;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
@ -143,5 +144,24 @@ public void should_not_return_unaired()
episodes.TotalRecords.Should().Be(4);
}
[Test]
public void should_not_return_episodes_on_air()
{
var onAirEpisode = Builder<Episode>.CreateNew()
.With(e => e.Id = 0)
.With(e => e.SeriesId = _monitoredSeries.Id)
.With(e => e.EpisodeFileId = 0)
.With(e => e.AirDateUtc = DateTime.Now.AddMinutes(-15))
.With(e => e.Monitored = true)
.Build();
Db.Insert(onAirEpisode);
var episodes = Subject.EpisodesWithoutFiles(_pagingSpec, false);
episodes.TotalRecords.Should().Be(4);
episodes.Records.Where(e => e.Id == onAirEpisode.Id).Should().BeEmpty();
}
}
}

View File

@ -118,7 +118,6 @@ public PagingSpec<Episode> EpisodesWithoutFiles(PagingSpec<Episode> pagingSpec,
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 @@ public PagingSpec<Episode> EpisodesWhereCutoffUnmet(PagingSpec<Episode> pagingSp
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 @@ private SortBuilder<Episode> GetMissingEpisodesQuery(PagingSpec<Episode> pagingS
.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>();