render channels page

pull/702/head
Luke Pulverenti 11 years ago
parent c3530e5e32
commit 71514af96b

@ -1012,21 +1012,7 @@ namespace MediaBrowser.Api.UserLibrary
if (request.AiredDuringSeason.HasValue)
{
var val = request.AiredDuringSeason.Value;
items = items.Where(i =>
{
var episode = i as Episode;
if (episode != null)
{
var seasonNumber = episode.AirsAfterSeasonNumber ?? episode.AirsBeforeSeasonNumber ?? episode.ParentIndexNumber;
return episode.PremiereDate.HasValue && seasonNumber.HasValue && seasonNumber.Value == val;
}
return false;
});
items = FilterByAiredDuringSeason(items, request.AiredDuringSeason.Value);
}
if (!string.IsNullOrEmpty(request.MinPremiereDate))
@ -1046,6 +1032,43 @@ namespace MediaBrowser.Api.UserLibrary
return items;
}
private IEnumerable<BaseItem> FilterByAiredDuringSeason(IEnumerable<BaseItem> items, int seasonNumber)
{
var episodes = items.OfType<Episode>().ToList();
// We can only enforce the air date requirement if the episodes have air dates
var enforceAirDate = episodes.Any(i => i.PremiereDate.HasValue);
return episodes.Where(i =>
{
var episode = i;
if (episode != null)
{
var currentSeasonNumber = episode.AirsAfterSeasonNumber ?? episode.AirsBeforeSeasonNumber ?? episode.ParentIndexNumber;
// If this produced nothing, try and get it from the parent folder
if (!currentSeasonNumber.HasValue)
{
var season = episode.Parent as Season;
if (season != null)
{
currentSeasonNumber = season.IndexNumber;
}
}
if (enforceAirDate && !episode.PremiereDate.HasValue)
{
return false;
}
return currentSeasonNumber.HasValue && currentSeasonNumber.Value == seasonNumber;
}
return false;
});
}
/// <summary>
/// Determines whether the specified item has image.
/// </summary>

@ -1,8 +1,8 @@
using System;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Sorting;
using MediaBrowser.Model.Querying;
using System;
namespace MediaBrowser.Server.Implementations.Sorting
{
@ -16,12 +16,15 @@ namespace MediaBrowser.Server.Implementations.Sorting
/// <returns>System.Int32.</returns>
public int Compare(BaseItem x, BaseItem y)
{
var val = DateTime.Compare(x.PremiereDate ?? DateTime.MinValue, y.PremiereDate ?? DateTime.MinValue);
if (x.PremiereDate.HasValue && y.PremiereDate.HasValue)
{
var val = DateTime.Compare(x.PremiereDate.Value, y.PremiereDate.Value);
if (val != 0)
{
return val;
}
}
var episode1 = x as Episode;
var episode2 = y as Episode;

Loading…
Cancel
Save