using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Persistence;
using ServiceStack;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MediaBrowser.Api
{
[Route("/Albums/{Id}/Similar", "GET")]
[Api(Description = "Finds albums similar to a given album.")]
public class GetSimilarAlbums : BaseGetSimilarItemsFromItem
{
}
public class AlbumsService : BaseApiService
{
///
/// The _user manager
///
private readonly IUserManager _userManager;
///
/// The _user data repository
///
private readonly IUserDataManager _userDataRepository;
///
/// The _library manager
///
private readonly ILibraryManager _libraryManager;
private readonly IItemRepository _itemRepo;
private readonly IDtoService _dtoService;
public AlbumsService(IUserManager userManager, IUserDataManager userDataRepository, ILibraryManager libraryManager, IItemRepository itemRepo, IDtoService dtoService)
{
_userManager = userManager;
_userDataRepository = userDataRepository;
_libraryManager = libraryManager;
_itemRepo = itemRepo;
_dtoService = dtoService;
}
///
/// Gets the specified request.
///
/// The request.
/// System.Object.
public object Get(GetSimilarAlbums request)
{
var result = SimilarItemsHelper.GetSimilarItemsResult(_userManager,
_itemRepo,
_libraryManager,
_userDataRepository,
_dtoService,
Logger,
request, item => item is MusicAlbum,
GetAlbumSimilarityScore);
return ToOptimizedSerializedResultUsingCache(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.GetRecursiveChildren()
.OfType