fixed special episode sorting

pull/702/head
Luke Pulverenti 11 years ago
parent a0e6c0422b
commit 4b4c5635af

@ -80,25 +80,36 @@ namespace MediaBrowser.Server.Implementations.Sorting
return xSeason.CompareTo(ySeason);
}
// Now we know they have the same season
// Special comes after episode
if (y.AirsAfterSeasonNumber.HasValue)
{
return -1;
}
// Compare episode number
var yEpisode = y.AirsBeforeEpisodeNumber;
// Add 1 to to non-specials to account for AirsBeforeEpisodeNumber
var xEpisode = x.IndexNumber ?? -1;
xEpisode++;
// Special comes before the season
if (!yEpisode.HasValue)
{
return 1;
}
var yEpisode = y.AirsBeforeEpisodeNumber ?? 10000;
// Compare episode number
var xEpisode = x.IndexNumber;
if (!xEpisode.HasValue)
{
// Can't really compare if this happens
return 0;
}
// Sometimes they'll both have a value.
// For example AirsAfterSeasonNumber=1, AirsBeforeSeasonNumber=2, AirsBeforeEpisodeNumber=1
// The episode should be displayed at the end of season 1
if (y.AirsAfterSeasonNumber.HasValue && y.AirsBeforeSeasonNumber.HasValue && y.AirsBeforeSeasonNumber.Value > y.AirsAfterSeasonNumber.Value)
// Special comes before episode
if (xEpisode.Value == yEpisode.Value)
{
yEpisode = 10000;
return 1;
}
return xEpisode.CompareTo(yEpisode);
return xEpisode.Value.CompareTo(yEpisode.Value);
}
private int CompareSpecials(Episode x, Episode y)

Loading…
Cancel
Save