AirDate now stored as a string

pull/4/head
Mark McDowall 11 years ago
parent ea278c39b6
commit 5bfcc511e8

@ -11,7 +11,7 @@ namespace NzbDrone.Api.Episodes
public Int32 SeasonNumber { get; set; }
public Int32 EpisodeNumber { get; set; }
public String Title { get; set; }
public DateTime? AirDate { get; set; }
public String AirDate { get; set; }
public DateTime? AirDateUtc { get; set; }
public String Overview { get; set; }
public EpisodeFile EpisodeFile { get; set; }

@ -37,7 +37,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetProviderTests
_remoteEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.AirDate = DateTime.Today)
.With(e => e.AirDate = DateTime.Today.ToString(Episode.AIR_DATE_FORMAT))
.Build()
.ToList();
}

@ -42,7 +42,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabProviderTests
_remoteEpisode.Episodes = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.AirDate = DateTime.Today)
.With(e => e.AirDate = DateTime.Today.ToString(Episode.AIR_DATE_FORMAT))
.Build()
.ToList();
}

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using NUnit.Framework;
@ -27,7 +28,6 @@ namespace NzbDrone.Core.Test.MetadataSourceTests
result[0].Title.Should().Be(expected);
}
[Test]
public void no_search_result()
{
@ -35,16 +35,35 @@ namespace NzbDrone.Core.Test.MetadataSourceTests
result.Should().BeEmpty();
}
[Test]
public void should_be_able_to_get_series_detail()
[TestCase(75978)]
[TestCase(79349)]
public void should_be_able_to_get_series_detail(int tvdbId)
{
var details = Subject.GetSeriesInfo(75978);
var details = Subject.GetSeriesInfo(tvdbId);
ValidateSeries(details.Item1);
ValidateEpisodes(details.Item2);
}
var episodes = details.Item2;
private void ValidateSeries(Series series)
{
series.Should().NotBeNull();
series.Title.Should().NotBeBlank();
series.Overview.Should().NotBeBlank();
series.AirTime.Should().NotBeBlank();
series.FirstAired.Should().HaveValue();
series.FirstAired.Value.Kind.Should().Be(DateTimeKind.Utc);
series.Images.Should().NotBeEmpty();
series.ImdbId.Should().NotBeBlank();
series.Network.Should().NotBeBlank();
series.Runtime.Should().BeGreaterThan(0);
series.TitleSlug.Should().NotBeBlank();
series.TvRageId.Should().BeGreaterThan(0);
series.TvdbId.Should().BeGreaterThan(0);
}
private void ValidateEpisodes(List<Episode> episodes)
{
episodes.Should().NotBeEmpty();
episodes.GroupBy(e => e.SeasonNumber.ToString("000") + e.EpisodeNumber.ToString("000"))
@ -57,33 +76,23 @@ namespace NzbDrone.Core.Test.MetadataSourceTests
foreach (var episode in episodes)
{
episode.AirDate.Should().HaveValue();
episode.AirDate.Value.Kind.Should().Be(DateTimeKind.Utc);
episode.EpisodeNumber.Should().NotBe(0);
episode.Title.Should().NotBeBlank();
episode.TvDbEpisodeId.Should().NotBe(0);
ValidateEpisode(episode);
}
}
private void ValidateEpisode(Episode episode)
{
episode.Should().NotBeNull();
episode.Title.Should().NotBeBlank();
episode.EpisodeNumber.Should().NotBe(0);
episode.TvDbEpisodeId.Should().BeGreaterThan(0);
episode.Should().NotBeNull();
private void ValidateSeries(Series series)
{
series.Should().NotBeNull();
series.Title.Should().NotBeBlank();
series.Overview.Should().NotBeBlank();
series.AirTime.Should().NotBeBlank();
series.FirstAired.Should().HaveValue();
series.FirstAired.Value.Kind.Should().Be(DateTimeKind.Utc);
series.Images.Should().NotBeEmpty();
series.ImdbId.Should().NotBeBlank();
series.Network.Should().NotBeBlank();
series.Runtime.Should().BeGreaterThan(0);
series.TitleSlug.Should().NotBeBlank();
series.TvRageId.Should().BeGreaterThan(0);
series.TvdbId.Should().BeGreaterThan(0);
if (episode.AirDateUtc.HasValue)
{
episode.AirDateUtc.Value.Kind.Should().Be(DateTimeKind.Utc);
}
}
}
}

@ -157,7 +157,7 @@
<Compile Include="MediaFileTests\MediaFileTableCleanupServiceFixture.cs" />
<Compile Include="MediaFileTests\MediaFileRepositoryFixture.cs" />
<Compile Include="MediaFileTests\EpisodeFileMoverFixture.cs" />
<Compile Include="MetadataSourceTests\TracktProxyFixture.cs" />
<Compile Include="MetadataSourceTests\TraktProxyFixture.cs" />
<Compile Include="NotificationTests\NotificationServiceFixture.cs" />
<Compile Include="NotificationTests\Xbmc\GetJsonVersionFixture.cs" />
<Compile Include="NotificationTests\Xbmc\Http\ActivePlayersFixture.cs" />

@ -700,7 +700,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
var episodes = Builder<Episode>
.CreateListOfSize(1)
.All()
.With(e => e.AirDate = new DateTime(2012, 12, 13))
.With(e => e.AirDate = "2012-12-13")
.With(e => e.Title = "Kristen Stewart")
.Build();
@ -729,7 +729,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
var episodes = Builder<Episode>
.CreateListOfSize(1)
.All()
.With(e => e.AirDate = new DateTime(2012, 12, 13))
.With(e => e.AirDate = "2012-12-13")
.With(e => e.Title = "Kristen Stewart")
.Build();

@ -27,7 +27,7 @@ namespace NzbDrone.Core.Test.SeriesStatsTests
_episode = Builder<Episode>.CreateNew()
.With(e => e.Id = 0)
.With(e => e.SeriesId = series.Id)
.With(e => e.AirDate = DateTime.Today.AddDays(5))
.With(e => e.AirDateUtc = DateTime.Today.AddDays(5))
.Build();
Db.Insert(_episode);
@ -39,7 +39,7 @@ namespace NzbDrone.Core.Test.SeriesStatsTests
var stats = Subject.SeriesStatistics();
stats.Should().HaveCount(1);
stats.First().NextAiring.Should().Be(_episode.AirDate);
stats.First().NextAiring.Should().Be(_episode.AirDateUtc);
}
}
}

@ -0,0 +1,15 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Tags("")]
[Migration(14)]
public class drop_air_date : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
SQLiteAlter.DropColumns("Episodes", new []{ "AirDate" });
}
}
}

@ -0,0 +1,15 @@
using FluentMigrator;
using NzbDrone.Core.Datastore.Migration.Framework;
namespace NzbDrone.Core.Datastore.Migration
{
[Tags("")]
[Migration(15)]
public class add_air_date_as_string : NzbDroneMigrationBase
{
protected override void MainDbUpgrade()
{
Alter.Table("Episodes").AddColumn("AirDate").AsString().Nullable();
}
}
}

@ -31,7 +31,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications.Search
var episode = _episodeService.GetEpisode(dailySearchSpec.SeriesId, dailySearchSpec.Airtime);
if (!remoteEpisode.ParsedEpisodeInfo.AirDate.HasValue || remoteEpisode.ParsedEpisodeInfo.AirDate.Value.Date != episode.AirDate.Value.Date)
if (!remoteEpisode.ParsedEpisodeInfo.AirDate.HasValue || remoteEpisode.ParsedEpisodeInfo.AirDate.Value.ToString(Episode.AIR_DATE_FORMAT) != episode.AirDate)
{
_logger.Trace("Episode AirDate does not match searched episode number, skipping.");
return false;

@ -7,11 +7,6 @@ namespace NzbDrone.Core
{
public static class Fluent
{
private const Decimal ONE_KILOBYTE = 1024M;
private const Decimal ONE_MEGABYTE = ONE_KILOBYTE * 1024M;
private const Decimal ONE_GIGABYTE = ONE_MEGABYTE * 1024M;
private const Decimal ONE_TERABYTE = ONE_GIGABYTE * 1024M;
public static string WithDefault(this string actual, object defaultValue)
{
if (defaultValue == null)
@ -93,70 +88,6 @@ namespace NzbDrone.Core
return s.Substring(0, i);
}
public static string AddSpacesToEnum(this Enum enumValue)
{
var text = enumValue.ToString();
if (string.IsNullOrWhiteSpace(text))
return "";
var newText = new StringBuilder(text.Length * 2);
newText.Append(text[0]);
for (int i = 1; i < text.Length; i++)
{
if (char.IsUpper(text[i]) && text[i - 1] != ' ')
newText.Append(' ');
newText.Append(text[i]);
}
return newText.ToString();
}
public static string ToBestFileSize(this long bytes, int precision = 0)
{
var ulongBytes = (ulong)bytes;
return ulongBytes.ToBestFileSize(precision);
}
public static string ToBestFileSize(this ulong bytes, int precision = 0)
{
if (bytes == 0)
return "0B";
decimal size = Convert.ToDecimal(bytes);
string suffix;
if (size > ONE_TERABYTE)
{
size /= ONE_TERABYTE;
suffix = "TB";
}
else if (size > ONE_GIGABYTE)
{
size /= ONE_GIGABYTE;
suffix = "GB";
}
else if (size > ONE_MEGABYTE)
{
size /= ONE_MEGABYTE;
suffix = "MB";
}
else if (size > ONE_KILOBYTE)
{
size /= ONE_KILOBYTE;
suffix = "KB";
}
else
{
suffix = " B";
}
return String.Format("{0:N" + precision + "} {1}", size, suffix);
}
public static int MinOrDefault(this IEnumerable<int> ints)
{
if (ints == null)

@ -13,7 +13,7 @@ namespace NzbDrone.Core.IndexerSearch.Definitions
public override string ToString()
{
return string.Format("[{0} : S{1:00}E{1:0}*]", SceneTitle, SeasonNumber, Prefix);
return string.Format("[{0} : S{1:00}E{2:0}*]", SceneTitle, SeasonNumber, Prefix);
}
}
}

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading.Tasks;
using NLog;
using NzbDrone.Core.DataAugmentation.Scene;
@ -53,7 +54,7 @@ namespace NzbDrone.Core.IndexerSearch
if (series.SeriesType == SeriesTypes.Daily)
{
return SearchDaily(episode.SeriesId, episode.AirDate.Value.Date);
return SearchDaily(episode.SeriesId, DateTime.ParseExact(episode.AirDate, Episode.AIR_DATE_FORMAT, CultureInfo.InvariantCulture));
}
return SearchSingle(series, episode);

@ -69,7 +69,7 @@ namespace NzbDrone.Core.MetadataSource
episode.EpisodeNumber = traktEpisode.number;
episode.TvDbEpisodeId = traktEpisode.tvdb_id;
episode.Title = traktEpisode.title;
episode.AirDate = FromEpoch(traktEpisode.first_aired);
episode.AirDate = FromIsoToString(traktEpisode.first_aired_iso);
episode.AirDateUtc = FromIso(traktEpisode.first_aired_iso);
return episode;
@ -95,7 +95,7 @@ namespace NzbDrone.Core.MetadataSource
{
if (ticks == 0) return null;
return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(ticks);
return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Unspecified).AddSeconds(ticks);
}
private static DateTime? FromIso(string iso)
@ -107,5 +107,15 @@ namespace NzbDrone.Core.MetadataSource
return result.ToUniversalTime();
}
private static string FromIsoToString(string iso)
{
DateTime result;
if (!DateTime.TryParse(iso, out result))
return null;
return result.ToString(Episode.AIR_DATE_FORMAT);
}
}
}

@ -215,6 +215,8 @@
<Compile Include="Datastore\Migration\011_remove_ignored.cs" />
<Compile Include="Datastore\Migration\012_remove_custom_start_date.cs" />
<Compile Include="Datastore\Migration\013_add_air_date_utc.cs" />
<Compile Include="Datastore\Migration\014_drop_air_date.cs" />
<Compile Include="Datastore\Migration\015_add_air_date_as_string.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationContext.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationController.cs" />
<Compile Include="Datastore\Migration\Framework\MigrationExtension.cs" />

@ -128,8 +128,8 @@ namespace NzbDrone.Core.Organizer
else
{
if (episodes.First().AirDate.HasValue)
result += episodes.First().AirDate.Value.ToString("yyyy-MM-dd");
if (!String.IsNullOrEmpty(episodes.First().AirDate))
result += episodes.First().AirDate;
else
result += "Unknown";

@ -54,10 +54,10 @@ namespace NzbDrone.Core.SeriesStats
{
return @"SELECT
SeriesId,
SUM(CASE WHEN Monitored = 1 AND Airdate <= @currentDate THEN 1 ELSE 0 END) AS EpisodeCount,
SUM(CASE WHEN Monitored = 1 AND Episodes.EpisodeFileId > 0 AND AirDate <= @currentDate THEN 1 ELSE 0 END) AS EpisodeFileCount,
SUM(CASE WHEN Monitored = 1 AND AirdateUtc <= @currentDate THEN 1 ELSE 0 END) AS EpisodeCount,
SUM(CASE WHEN Monitored = 1 AND Episodes.EpisodeFileId > 0 AND AirDateUtc <= @currentDate THEN 1 ELSE 0 END) AS EpisodeFileCount,
MAX(Episodes.SeasonNumber) as SeasonCount,
MIN(CASE WHEN AirDate < @currentDate THEN NULL ELSE AirDate END) AS NextAiringString
MIN(CASE WHEN AirDateUtc < @currentDate THEN NULL ELSE AirDate END) AS NextAiringString
FROM Episodes";
}

@ -9,13 +9,15 @@ namespace NzbDrone.Core.Tv
{
public class Episode : ModelBase
{
public const string AIR_DATE_FORMAT = "yyyy-MM-dd";
public int TvDbEpisodeId { get; set; }
public int SeriesId { get; set; }
public int EpisodeFileId { get; set; }
public int SeasonNumber { get; set; }
public int EpisodeNumber { get; set; }
public string Title { get; set; }
public DateTime? AirDate { get; set; }
public string AirDate { get; set; }
public DateTime? AirDateUtc { get; set; }
public string Overview { get; set; }
@ -37,7 +39,7 @@ namespace NzbDrone.Core.Tv
public override string ToString()
{
return string.Format("[0]{1}", TvDbEpisodeId, Title.NullSafe());
return string.Format("[{0}]{1}", TvDbEpisodeId, Title.NullSafe());
}
}
}

@ -49,12 +49,12 @@ namespace NzbDrone.Core.Tv
public Episode Get(int seriesId, DateTime date)
{
return Query.Single(s => s.SeriesId == seriesId && s.AirDate.HasValue && s.AirDate.Value.Date == date.Date);
return Query.Single(s => s.SeriesId == seriesId && s.AirDate == date.ToString(Episode.AIR_DATE_FORMAT));
}
public Episode Find(int seriesId, DateTime date)
{
return Query.SingleOrDefault(s => s.SeriesId == seriesId && s.AirDate.HasValue && s.AirDate.Value.Date == date.Date);
return Query.SingleOrDefault(s => s.SeriesId == seriesId && s.AirDate == date.ToString(Episode.AIR_DATE_FORMAT));
}
public List<Episode> GetEpisodes(int seriesId)

@ -163,14 +163,14 @@ namespace NzbDrone.Core.Tv
allEpisodes.AddRange(newList);
allEpisodes.AddRange(updateList);
var groups = allEpisodes.Where(c=>c.AirDate.HasValue).GroupBy(e => new { e.SeriesId, e.AirDate }).Where(g => g.Count() > 1).ToList();
var groups = allEpisodes.Where(c=>c.AirDateUtc.HasValue).GroupBy(e => new { e.SeriesId, e.AirDate }).Where(g => g.Count() > 1).ToList();
foreach (var group in groups)
{
int episodeCount = 0;
foreach (var episode in group.OrderBy(e => e.SeasonNumber).ThenBy(e => e.EpisodeNumber))
{
episode.AirDate = episode.AirDate.Value.AddMinutes(series.Runtime * episodeCount);
episode.AirDateUtc = episode.AirDateUtc.Value.AddMinutes(series.Runtime * episodeCount);
episodeCount++;
}
}

Loading…
Cancel
Save