From 9026af7550a3b01956f12f03794b92cb3af03430 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 25 May 2013 19:52:41 -0400 Subject: [PATCH] unwrapped similar items api into separate endpoints for each type --- MediaBrowser.Api/AlbumsService.cs | 87 ++++++++ MediaBrowser.Api/GamesService.cs | 66 ++++++ MediaBrowser.Api/LibraryService.cs | 209 +----------------- MediaBrowser.Api/MediaBrowser.Api.csproj | 5 + MediaBrowser.Api/MoviesService.cs | 67 ++++++ MediaBrowser.Api/SimilarItemsHelper.cs | 184 +++++++++++++++ MediaBrowser.Api/TrailersService.cs | 67 ++++++ MediaBrowser.Api/TvShowsService.cs | 23 ++ .../SQLiteDisplayPreferencesRepository.cs | 62 ++++-- .../Sqlite/SQLiteItemRepository.cs | 2 +- .../Sqlite/SQLiteUserDataRepository.cs | 66 ++++-- MediaBrowser.WebDashboard/ApiClient.js | 48 +++- MediaBrowser.WebDashboard/packages.config | 2 +- 13 files changed, 637 insertions(+), 251 deletions(-) create mode 100644 MediaBrowser.Api/AlbumsService.cs create mode 100644 MediaBrowser.Api/GamesService.cs create mode 100644 MediaBrowser.Api/MoviesService.cs create mode 100644 MediaBrowser.Api/SimilarItemsHelper.cs create mode 100644 MediaBrowser.Api/TrailersService.cs diff --git a/MediaBrowser.Api/AlbumsService.cs b/MediaBrowser.Api/AlbumsService.cs new file mode 100644 index 000000000..7ffe8b600 --- /dev/null +++ b/MediaBrowser.Api/AlbumsService.cs @@ -0,0 +1,87 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Persistence; +using ServiceStack.ServiceHost; +using System; +using System.Linq; + +namespace MediaBrowser.Api +{ + [Route("/Albums/{Id}/Similar", "GET")] + [Api(Description = "Finds albums similar to a given album.")] + public class GetSimilarAlbums : BaseGetSimilarItems + { + } + + public class AlbumsService : BaseApiService + { + /// + /// The _user manager + /// + private readonly IUserManager _userManager; + + /// + /// The _user data repository + /// + private readonly IUserDataRepository _userDataRepository; + /// + /// The _library manager + /// + private readonly ILibraryManager _libraryManager; + + public AlbumsService(IUserManager userManager, IUserDataRepository userDataRepository, ILibraryManager libraryManager) + { + _userManager = userManager; + _userDataRepository = userDataRepository; + _libraryManager = libraryManager; + } + + /// + /// Gets the specified request. + /// + /// The request. + /// System.Object. + public object Get(GetSimilarAlbums request) + { + var result = SimilarItemsHelper.GetSimilarItems(_userManager, + _libraryManager, + _userDataRepository, + Logger, + request, item => item is MusicAlbum, + GetAlbumSimilarityScore); + + return ToOptimizedResult(result); + } + + /// + /// Gets the album similarity score. + /// + /// The item1. + /// The item2. + /// System.Int32. + private int GetAlbumSimilarityScore(BaseItem item1, BaseItem item2) + { + var points = SimilarItemsHelper.GetSimiliarityScore(item1, item2); + + var album1 = (MusicAlbum)item1; + var album2 = (MusicAlbum)item2; + + var artists1 = album1.RecursiveChildren + .OfType