aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/LibraryService.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-10-05 23:03:08 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-10-05 23:03:08 -0400
commit863f123f3c8d26dc9fee050a9132857281caba84 (patch)
tree7e3f3ea0b6d420c33bf79ba9c2b2e0ef480f408f /MediaBrowser.Api/LibraryService.cs
parent3fbf08b8825d7476e7cd87fb922e3aa9245253cc (diff)
updated nuget + subtitle changes
Diffstat (limited to 'MediaBrowser.Api/LibraryService.cs')
-rw-r--r--MediaBrowser.Api/LibraryService.cs42
1 files changed, 42 insertions, 0 deletions
diff --git a/MediaBrowser.Api/LibraryService.cs b/MediaBrowser.Api/LibraryService.cs
index 0f15124a5..16952dabd 100644
--- a/MediaBrowser.Api/LibraryService.cs
+++ b/MediaBrowser.Api/LibraryService.cs
@@ -10,7 +10,9 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying;
using ServiceStack.ServiceHost;
using System;
+using System.Collections;
using System.Collections.Generic;
+using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
@@ -175,6 +177,21 @@ namespace MediaBrowser.Api
public string Id { get; set; }
}
+ [Route("/Items/YearIndex", "GET")]
+ [Api(Description = "Gets a year index based on an item query.")]
+ public class GetYearIndex : IReturn<List<ItemIndex>>
+ {
+ /// <summary>
+ /// Gets or sets the user id.
+ /// </summary>
+ /// <value>The user id.</value>
+ [ApiMember(Name = "UserId", Description = "Optional. Filter by user id, and attach user data", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
+ public Guid? UserId { get; set; }
+
+ [ApiMember(Name = "IncludeItemTypes", Description = "Optional. If specified, results will be filtered based on item type. This allows multiple, comma delimeted.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET", AllowMultiple = true)]
+ public string IncludeItemTypes { get; set; }
+ }
+
/// <summary>
/// Class LibraryService
/// </summary>
@@ -564,5 +581,30 @@ namespace MediaBrowser.Api
OwnerId = _dtoService.GetDtoId(item)
};
}
+
+ private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
+
+ public object Get(GetYearIndex request)
+ {
+ IEnumerable<BaseItem> items = GetAllLibraryItems(request.UserId, _userManager, _libraryManager);
+
+ if (!string.IsNullOrEmpty(request.IncludeItemTypes))
+ {
+ var vals = request.IncludeItemTypes.Split(',');
+ items = items.Where(f => vals.Contains(f.GetType().Name, StringComparer.OrdinalIgnoreCase));
+ }
+
+ var lookup = items
+ .ToLookup(i => i.ProductionYear ?? -1)
+ .OrderBy(i => i.Key)
+ .Select(i => new ItemIndex
+ {
+ ItemCount = i.Count(),
+ Name = i.Key == -1 ? string.Empty : i.Key.ToString(UsCulture)
+ })
+ .ToList();
+
+ return ToOptimizedResult(lookup);
+ }
}
}