From 4064b8badad46ac30afd7009bdc793c1f49c9103 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 21 Sep 2013 17:00:04 -0400 Subject: [PATCH] added GameSystem entity --- MediaBrowser.Api/BaseApiService.cs | 13 +++- .../DefaultTheme/DefaultThemeService.cs | 2 +- MediaBrowser.Api/GamesService.cs | 73 +++++++++++++++++++ MediaBrowser.Api/LibraryService.cs | 14 +--- .../Entities/GameSystem.cs | 23 ++++++ .../MediaBrowser.Controller.csproj | 1 + .../MediaBrowser.Model.Portable.csproj | 3 + .../MediaBrowser.Model.net35.csproj | 3 + MediaBrowser.Model/ApiClient/IApiClient.cs | 15 +++- MediaBrowser.Model/Dto/GameSystemSummary.cs | 36 +++++++++ MediaBrowser.Model/MediaBrowser.Model.csproj | 1 + Nuget/MediaBrowser.Common.Internal.nuspec | 4 +- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 +- 14 files changed, 173 insertions(+), 21 deletions(-) create mode 100644 MediaBrowser.Controller/Entities/GameSystem.cs create mode 100644 MediaBrowser.Model/Dto/GameSystemSummary.cs diff --git a/MediaBrowser.Api/BaseApiService.cs b/MediaBrowser.Api/BaseApiService.cs index e969d79ff8..b3f5027e0a 100644 --- a/MediaBrowser.Api/BaseApiService.cs +++ b/MediaBrowser.Api/BaseApiService.cs @@ -9,7 +9,6 @@ using ServiceStack.ServiceHost; using System; using System.Collections.Generic; using System.Linq; -using System.Threading.Tasks; namespace MediaBrowser.Api { @@ -125,6 +124,18 @@ namespace MediaBrowser.Api return libraryManager.GetPerson(DeSlugPersonName(name, libraryManager)); } + protected IEnumerable GetAllLibraryItems(Guid? userId, IUserManager userManager, ILibraryManager libraryManager) + { + if (userId.HasValue) + { + var user = userManager.GetUserById(userId.Value); + + return userManager.GetUserById(userId.Value).RootFolder.GetRecursiveChildren(user); + } + + return libraryManager.RootFolder.RecursiveChildren; + } + /// /// Deslugs an artist name by finding the correct entry in the library /// diff --git a/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs b/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs index eb4ddc9cda..c806273408 100644 --- a/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs +++ b/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs @@ -124,7 +124,7 @@ namespace MediaBrowser.Api.DefaultTheme var user = _userManager.GetUserById(request.UserId); var items = user.RootFolder.GetRecursiveChildren(user) - .Where(i => i is Game || string.Equals(i.GetType().Name, "GamePlatform", StringComparison.OrdinalIgnoreCase)) + .Where(i => i is Game || i is GameSystem) .ToList(); var itemsWithBackdrops = FilterItemsForBackdropDisplay(items.Where(i => i.BackdropImagePaths.Count > 0)).ToList(); diff --git a/MediaBrowser.Api/GamesService.cs b/MediaBrowser.Api/GamesService.cs index ae328f70f3..7f0521b535 100644 --- a/MediaBrowser.Api/GamesService.cs +++ b/MediaBrowser.Api/GamesService.cs @@ -2,7 +2,12 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Persistence; +using MediaBrowser.Model.Dto; using ServiceStack.ServiceHost; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; namespace MediaBrowser.Api { @@ -15,6 +20,21 @@ namespace MediaBrowser.Api { } + /// + /// Class GetGameSystemSummaries + /// + [Route("/Games/SystemSummaries", "GET")] + [Api(Description = "Finds games similar to a given game.")] + public class GetGameSystemSummaries : IReturn> + { + /// + /// Gets or sets the user id. + /// + /// The user id. + [ApiMember(Name = "UserId", Description = "Optional. Filter by user id", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public Guid? UserId { get; set; } + } + /// /// Class GamesService /// @@ -34,7 +54,13 @@ namespace MediaBrowser.Api /// private readonly ILibraryManager _libraryManager; + /// + /// The _item repo + /// private readonly IItemRepository _itemRepo; + /// + /// The _dto service + /// private readonly IDtoService _dtoService; /// @@ -44,6 +70,7 @@ namespace MediaBrowser.Api /// The user data repository. /// The library manager. /// The item repo. + /// The dto service. public GamesService(IUserManager userManager, IUserDataRepository userDataRepository, ILibraryManager libraryManager, IItemRepository itemRepo, IDtoService dtoService) { _userManager = userManager; @@ -53,6 +80,52 @@ namespace MediaBrowser.Api _dtoService = dtoService; } + /// + /// Gets the specified request. + /// + /// The request. + /// System.Object. + public object Get(GetGameSystemSummaries request) + { + var gameSystems = GetAllLibraryItems(request.UserId, _userManager, _libraryManager) + .OfType() + .ToList(); + + var user = request.UserId == null ? null : _userManager.GetUserById(request.UserId.Value); + + var result = gameSystems + .Select(i => GetSummary(i, user)) + .ToList(); + + return ToOptimizedResult(result); + } + + /// + /// Gets the summary. + /// + /// The system. + /// The user. + /// GameSystemSummary. + private GameSystemSummary GetSummary(GameSystem system, User user) + { + var summary = new GameSystemSummary + { + Name = system.Name + }; + + var items = user == null ? system.RecursiveChildren : system.GetRecursiveChildren(user); + + var games = items.OfType().ToList(); + + summary.GameCount = games.Count; + + summary.GameFileExtensions = games.Select(i => Path.GetExtension(i.Path)) + .Distinct(StringComparer.OrdinalIgnoreCase) + .ToList(); + + return summary; + } + /// /// Gets the specified request. /// diff --git a/MediaBrowser.Api/LibraryService.cs b/MediaBrowser.Api/LibraryService.cs index 83e35cd413..264846568f 100644 --- a/MediaBrowser.Api/LibraryService.cs +++ b/MediaBrowser.Api/LibraryService.cs @@ -313,7 +313,7 @@ namespace MediaBrowser.Api /// System.Object. public object Get(GetItemCounts request) { - var items = GetItems(request.UserId).ToList(); + var items = GetAllLibraryItems(request.UserId, _userManager, _libraryManager).ToList(); var counts = new ItemCounts { @@ -332,18 +332,6 @@ namespace MediaBrowser.Api return ToOptimizedResult(counts); } - protected IEnumerable GetItems(Guid? userId) - { - if (userId.HasValue) - { - var user = _userManager.GetUserById(userId.Value); - - return _userManager.GetUserById(userId.Value).RootFolder.GetRecursiveChildren(user); - } - - return _libraryManager.RootFolder.RecursiveChildren; - } - /// /// Posts the specified request. /// diff --git a/MediaBrowser.Controller/Entities/GameSystem.cs b/MediaBrowser.Controller/Entities/GameSystem.cs new file mode 100644 index 0000000000..39e95b91de --- /dev/null +++ b/MediaBrowser.Controller/Entities/GameSystem.cs @@ -0,0 +1,23 @@ +using System; + +namespace MediaBrowser.Controller.Entities +{ + /// + /// Class GameSystem + /// + public class GameSystem : Folder + { + /// + /// Return the id that should be used to key display prefs for this item. + /// Default is based on the type for everything except actual generic folders. + /// + /// The display prefs id. + public override Guid DisplayPreferencesId + { + get + { + return Id; + } + } + } +} diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index ad8b499543..f49bd8cf00 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -83,6 +83,7 @@ + diff --git a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj index 867eb300a7..e0ff0fbc63 100644 --- a/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj +++ b/MediaBrowser.Model.Portable/MediaBrowser.Model.Portable.csproj @@ -98,6 +98,9 @@ Dto\ChapterInfoDto.cs + + Dto\GameSystemSummary.cs + Dto\IItemDto.cs diff --git a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj index 606aee1f9e..59b3af342c 100644 --- a/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj +++ b/MediaBrowser.Model.net35/MediaBrowser.Model.net35.csproj @@ -82,6 +82,9 @@ Dto\ChapterInfoDto.cs + + Dto\GameSystemSummary.cs + Dto\IItemDto.cs diff --git a/MediaBrowser.Model/ApiClient/IApiClient.cs b/MediaBrowser.Model/ApiClient/IApiClient.cs index 44a7673ed9..03ea79b3b0 100644 --- a/MediaBrowser.Model/ApiClient/IApiClient.cs +++ b/MediaBrowser.Model/ApiClient/IApiClient.cs @@ -34,8 +34,20 @@ namespace MediaBrowser.Model.ApiClient /// event EventHandler HttpResponseReceived; + /// + /// Gets the API URL. + /// + /// The handler. + /// System.String. string GetApiUrl(string handler); + /// + /// Gets the game system summaries async. + /// + /// The cancellation token. + /// Task{List{GameSystemSummary}}. + Task> GetGameSystemSummariesAsync(CancellationToken cancellationToken); + /// /// Gets the async. /// @@ -186,6 +198,7 @@ namespace MediaBrowser.Model.ApiClient /// /// Gets active client sessions. /// + /// The query. /// Task{SessionInfoDto[]}. Task GetClientSessionsAsync(SessionQuery query); @@ -468,7 +481,7 @@ namespace MediaBrowser.Model.ApiClient /// The user id. /// Task{UserItemDataDto}. Task MarkUnplayedAsync(string itemId, string userId); - + /// /// Updates the favorite status async. /// diff --git a/MediaBrowser.Model/Dto/GameSystemSummary.cs b/MediaBrowser.Model/Dto/GameSystemSummary.cs new file mode 100644 index 0000000000..79f4e73d52 --- /dev/null +++ b/MediaBrowser.Model/Dto/GameSystemSummary.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; + +namespace MediaBrowser.Model.Dto +{ + /// + /// Class GameSystemSummary + /// + public class GameSystemSummary + { + /// + /// Gets or sets the name. + /// + /// The name. + public string Name { get; set; } + + /// + /// Gets or sets the game count. + /// + /// The game count. + public int GameCount { get; set; } + + /// + /// Gets or sets the game extensions. + /// + /// The game extensions. + public List GameFileExtensions { get; set; } + + /// + /// Initializes a new instance of the class. + /// + public GameSystemSummary() + { + GameFileExtensions = new List(); + } + } +} diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index 6d8d454d93..8fb471c2d1 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -50,6 +50,7 @@ + diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index daa03d1cd1..fc0650d5ef 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.204 + 3.0.205 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index 500f5c84f2..64342cef9a 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.204 + 3.0.205 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index 44f8acd09b..40919486ce 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.204 + 3.0.205 Media Browser.Server.Core Media Browser Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Media Browser Server. Copyright © Media Browser 2013 - +