Daily episodes that are added via RSS feed will have proper season and episode numbers.

pull/7/merge
Mark McDowall 13 years ago
parent 8b841c633a
commit 290e5d5897

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using FluentAssertions;
using NUnit.Framework;
@ -164,5 +165,31 @@ namespace NzbDrone.Core.Test
//Resolve
result.Should().Be("http://www.nzbdrone.com");
}
[Test]
public void MaxOrDefault_should_return_zero_when_collection_is_empty()
{
//Setup
//Act
var result = (new List<int>()).MaxOrDefault();
//Resolve
result.Should().Be(0);
}
[Test]
public void MaxOrDefault_should_return_max_when_collection_is_not_empty()
{
//Setup
var list = new List<int> {6, 4, 5, 3, 8, 10};
//Act
var result = list.MaxOrDefault();
//Resolve
result.Should().Be(10);
}
}
}

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
@ -51,5 +52,15 @@ namespace NzbDrone.Core
{
return uri.AbsoluteUri.Remove(uri.AbsoluteUri.Length - String.Join("", uri.Segments).Length - uri.Query.Length);
}
public static int MaxOrDefault(this IEnumerable<int> ints)
{
var intList = ints.ToList();
if (intList.Count() == 0)
return 0;
return intList.Max();
}
}
}

@ -138,9 +138,25 @@ namespace NzbDrone.Core.Providers
SeriesId = parseResult.Series.SeriesId,
AirDate = parseResult.AirDate.Value,
Title = "TBD",
Overview = String.Empty,
Overview = String.Empty
};
var episodesInSeries = GetEpisodeBySeries(parseResult.Series.SeriesId);
//Find the current season number
var maxSeasonNumber = episodesInSeries.Select(s => s.SeasonNumber).MaxOrDefault();
//Set the season number
episodeInfo.SeasonNumber = (maxSeasonNumber == 0) ? 1 : maxSeasonNumber;
//Find the latest episode number
var maxEpisodeNumber = episodesInSeries
.Where(w => w.SeasonNumber == episodeInfo.SeasonNumber)
.Select(s => s.EpisodeNumber).MaxOrDefault();
//Set the episode number to max + 1
episodeInfo.EpisodeNumber = maxEpisodeNumber + 1;
AddEpisode(episodeInfo);
}

Loading…
Cancel
Save