2012-07-13 03:50:50 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using MediaBrowser.Controller;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Api
|
|
|
|
|
{
|
|
|
|
|
public static class ApiService
|
|
|
|
|
{
|
|
|
|
|
public static BaseItem GetItemById(string id)
|
|
|
|
|
{
|
2012-07-16 16:50:44 +00:00
|
|
|
|
Guid guid = string.IsNullOrEmpty(id) ? Guid.Empty : new Guid(id);
|
2012-07-13 03:50:50 +00:00
|
|
|
|
|
2012-07-16 16:50:44 +00:00
|
|
|
|
return Kernel.Instance.GetItemById(guid);
|
2012-07-13 03:50:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-16 16:50:44 +00:00
|
|
|
|
public static IEnumerable<CategoryInfo> GetAllStudios(Folder parent, Guid userId)
|
2012-07-13 03:50:50 +00:00
|
|
|
|
{
|
2012-07-16 16:50:44 +00:00
|
|
|
|
Dictionary<string, int> data = new Dictionary<string, int>();
|
|
|
|
|
|
|
|
|
|
IEnumerable<BaseItem> allItems = Kernel.Instance.GetParentalAllowedRecursiveChildren(parent, userId);
|
|
|
|
|
|
|
|
|
|
foreach (var item in allItems)
|
2012-07-13 03:50:50 +00:00
|
|
|
|
{
|
2012-07-16 16:50:44 +00:00
|
|
|
|
if (item.Studios == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (string val in item.Studios)
|
|
|
|
|
{
|
|
|
|
|
if (!data.ContainsKey(val))
|
|
|
|
|
{
|
|
|
|
|
data.Add(val, 1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
data[val]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-07-13 03:50:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-16 16:50:44 +00:00
|
|
|
|
List<CategoryInfo> list = new List<CategoryInfo>();
|
2012-07-13 03:50:50 +00:00
|
|
|
|
|
2012-07-16 16:50:44 +00:00
|
|
|
|
foreach (string key in data.Keys)
|
|
|
|
|
{
|
|
|
|
|
list.Add(new CategoryInfo()
|
|
|
|
|
{
|
|
|
|
|
Name = key,
|
|
|
|
|
ItemCount = data[key]
|
2012-07-13 03:50:50 +00:00
|
|
|
|
|
2012-07-16 16:50:44 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
2012-07-13 03:50:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-16 16:50:44 +00:00
|
|
|
|
public static IEnumerable<CategoryInfo> GetAllGenres(Folder parent, Guid userId)
|
2012-07-13 03:50:50 +00:00
|
|
|
|
{
|
2012-07-16 16:50:44 +00:00
|
|
|
|
Dictionary<string, int> data = new Dictionary<string, int>();
|
2012-07-13 03:50:50 +00:00
|
|
|
|
|
2012-07-16 16:50:44 +00:00
|
|
|
|
IEnumerable<BaseItem> allItems = Kernel.Instance.GetParentalAllowedRecursiveChildren(parent, userId);
|
2012-07-13 03:50:50 +00:00
|
|
|
|
|
2012-07-16 16:50:44 +00:00
|
|
|
|
foreach (var item in allItems)
|
|
|
|
|
{
|
|
|
|
|
if (item.Genres == null)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2012-07-13 03:50:50 +00:00
|
|
|
|
|
2012-07-16 16:50:44 +00:00
|
|
|
|
foreach (string val in item.Genres)
|
|
|
|
|
{
|
|
|
|
|
if (!data.ContainsKey(val))
|
|
|
|
|
{
|
|
|
|
|
data.Add(val, 1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
data[val]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<CategoryInfo> list = new List<CategoryInfo>();
|
|
|
|
|
|
|
|
|
|
foreach (string key in data.Keys)
|
|
|
|
|
{
|
|
|
|
|
list.Add(new CategoryInfo()
|
|
|
|
|
{
|
|
|
|
|
Name = key,
|
|
|
|
|
ItemCount = data[key]
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
2012-07-13 03:50:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|