added new properties and endpoints for series special features

This commit is contained in:
Luke Pulverenti 2013-08-30 21:08:32 -04:00
parent e031694a99
commit b538dc31b1
8 changed files with 124 additions and 11 deletions

View File

@ -172,6 +172,9 @@ namespace MediaBrowser.Api.UserLibrary
[ApiMember(Name = "AdjacentTo", Description = "Optional. Return items that are siblings of a supplied item.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
public string AdjacentTo { get; set; }
[ApiMember(Name = "MinIndexNumber", Description = "Optional filter index number.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? MinIndexNumber { get; set; }
/// <summary>
/// Gets the order by.
/// </summary>
@ -511,6 +514,12 @@ namespace MediaBrowser.Api.UserLibrary
items = items.Where(i => i.Id == previousId || i.Id == nextId);
}
// Min index number
if (request.MinIndexNumber.HasValue)
{
items = items.Where(i => i.IndexNumber.HasValue && i.IndexNumber.Value >= request.MinIndexNumber.Value);
}
// Min official rating
if (!string.IsNullOrEmpty(request.MinOfficialRating))
{

View File

@ -1,6 +1,7 @@
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Session;
@ -325,7 +326,7 @@ namespace MediaBrowser.Api.UserLibrary
/// Class GetSpecialFeatures
/// </summary>
[Route("/Users/{UserId}/Items/{Id}/SpecialFeatures", "GET")]
[Api(Description = "Gets special features for a movie")]
[Api(Description = "Gets special features for an item")]
public class GetSpecialFeatures : IReturn<List<BaseItemDto>>
{
/// <summary>
@ -404,16 +405,40 @@ namespace MediaBrowser.Api.UserLibrary
// Get everything
var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)).ToList();
var movie = (Movie)item;
var dtoBuilder = new DtoBuilder(Logger, _libraryManager, _userDataRepository, _itemRepo);
var tasks = movie.SpecialFeatureIds
.Select(_itemRepo.RetrieveItem)
.OrderBy(i => i.SortName)
.Select(i => dtoBuilder.GetBaseItemDto(i, fields, user, movie));
var movie = item as Movie;
return Task.WhenAll(tasks);
// Get them from the db
if (movie != null)
{
// Avoid implicitly captured closure
var movie1 = movie;
var tasks = movie.SpecialFeatureIds
.Select(_itemRepo.RetrieveItem)
.OrderBy(i => i.SortName)
.Select(i => dtoBuilder.GetBaseItemDto(i, fields, user, movie1));
return Task.WhenAll(tasks);
}
var series = item as Series;
// Get them from the child tree
if (series != null)
{
var tasks = series
.RecursiveChildren
.OfType<Episode>()
.Where(i => i.ParentIndexNumber.HasValue && i.ParentIndexNumber.Value == 0)
.OrderBy(i => i.SortName)
.Select(i => dtoBuilder.GetBaseItemDto(i, fields, user));
return Task.WhenAll(tasks);
}
throw new ArgumentException("The item does not support special features");
}
/// <summary>
@ -589,7 +614,7 @@ namespace MediaBrowser.Api.UserLibrary
return DtoBuilder.GetUserItemDataDto(data);
}
/// <summary>
/// Posts the specified request.
/// </summary>

View File

@ -108,7 +108,7 @@ namespace MediaBrowser.Controller.Dto
.Select(i => i.ToString("N"))
.ToArray();
}
// Make sure all the tasks we kicked off have completed.
if (tasks.Count > 0)
{
@ -532,6 +532,10 @@ namespace MediaBrowser.Controller.Dto
dto.AirDays = series.AirDays;
dto.AirTime = series.AirTime;
dto.Status = series.Status;
dto.SpecialFeatureCount = series.SpecialFeatureIds.Count;
dto.SeasonCount = series.SeasonCount;
}
if (episode != null)
@ -579,7 +583,7 @@ namespace MediaBrowser.Controller.Dto
{
dto.SeriesName = item.SeriesName;
}
private void SetMusicVideoProperties(BaseItemDto dto, MusicVideo item)
{
if (!string.IsNullOrEmpty(item.Album))

View File

@ -13,9 +13,15 @@ namespace MediaBrowser.Controller.Entities.TV
/// </summary>
public class Series : Folder
{
public List<Guid> SpecialFeatureIds { get; set; }
public int SeasonCount { get; set; }
public Series()
{
AirDays = new List<DayOfWeek>();
SpecialFeatureIds = new List<Guid>();
}
/// <summary>

View File

@ -138,6 +138,8 @@ namespace MediaBrowser.Model.Dto
/// <value>The production year.</value>
public int? ProductionYear { get; set; }
public int? SeasonCount { get; set; }
/// <summary>
/// Gets or sets the players supported by a game.
/// </summary>

View File

@ -176,6 +176,8 @@ namespace MediaBrowser.Model.Querying
/// <value>The max official rating.</value>
public string MaxOfficialRating { get; set; }
public int? MinIndexNumber { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="ItemQuery"/> class.
/// </summary>

View File

@ -107,6 +107,7 @@
<Compile Include="TV\SeasonProviderFromXml.cs" />
<Compile Include="TV\SeriesProviderFromXml.cs" />
<Compile Include="TV\SeriesXmlParser.cs" />
<Compile Include="TV\SeriesPostScanTask.cs" />
<Compile Include="TV\TvdbPersonImageProvider.cs" />
<Compile Include="TV\TvdbPrescanTask.cs" />
<Compile Include="TV\TvdbSeriesImageProvider.cs" />

View File

@ -0,0 +1,64 @@
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Providers.TV
{
class SeriesPostScanTask : ILibraryPostScanTask
{
/// <summary>
/// The _library manager
/// </summary>
private readonly ILibraryManager _libraryManager;
public SeriesPostScanTask(ILibraryManager libraryManager)
{
_libraryManager = libraryManager;
}
public Task Run(IProgress<double> progress, CancellationToken cancellationToken)
{
return Task.Run(() => RunInternal(progress, cancellationToken));
}
private void RunInternal(IProgress<double> progress, CancellationToken cancellationToken)
{
var seriesList = _libraryManager.RootFolder
.RecursiveChildren
.OfType<Series>()
.ToList();
var numComplete = 0;
foreach (var series in seriesList)
{
cancellationToken.ThrowIfCancellationRequested();
var episodes = series.RecursiveChildren
.OfType<Episode>()
.ToList();
series.SpecialFeatureIds = episodes
.Where(i => i.ParentIndexNumber.HasValue && i.ParentIndexNumber.Value == 0)
.Select(i => i.Id)
.ToList();
series.SeasonCount = episodes
.Select(i => i.ParentIndexNumber ?? 0)
.Where(i => i != 0)
.Distinct()
.Count();
numComplete++;
double percent = numComplete;
percent /= seriesList.Count;
percent *= 100;
progress.Report(percent);
}
}
}
}