mirror of
https://github.com/lidarr/Lidarr
synced 2025-03-03 10:06:06 +00:00
Daily episodes that are added via RSS feed will have proper season and episode numbers.
This commit is contained in:
parent
8b841c633a
commit
290e5d5897
3 changed files with 55 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
|
@ -164,5 +165,31 @@ public void ParentUriString_should_return_parent_url_when_url_with_query_strings
|
|||
//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 @@ public static string ParentUriString(this Uri uri)
|
|||
{
|
||||
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 @@ public virtual IList<Episode> GetEpisodesByParseResult(EpisodeParseResult parseR
|
|||
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…
Reference in a new issue