diff --git a/MediaBrowser.Api/BaseApiService.cs b/MediaBrowser.Api/BaseApiService.cs index e969d79ff..b3f5027e0 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 eb4ddc9cd..c80627340 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 ae328f70f..7f0521b53 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 83e35cd41..264846568 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 000000000..39e95b91d --- /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 ad8b49954..f49bd8cf0 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 867eb300a..e0ff0fbc6 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 606aee1f9..59b3af342 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 44a7673ed..03ea79b3b 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 000000000..79f4e73d5 --- /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 6d8d454d9..8fb471c2d 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 daa03d1cd..fc0650d5e 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 500f5c84f..64342cef9 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 44f8acd09..40919486c 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 - +