Added new theme song/video endpoints
This commit is contained in:
parent
d97a1af263
commit
9821faf566
|
@ -52,7 +52,7 @@ namespace MediaBrowser.Api
|
|||
/// </summary>
|
||||
[Route("/Items/{Id}/ThemeSongs", "GET")]
|
||||
[Api(Description = "Gets theme songs for an item")]
|
||||
public class GetThemeSongs : IReturn<ThemeSongsResult>
|
||||
public class GetThemeSongs : IReturn<ThemeMediaResult>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user id.
|
||||
|
@ -67,14 +67,17 @@ namespace MediaBrowser.Api
|
|||
/// <value>The id.</value>
|
||||
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
||||
public string Id { get; set; }
|
||||
|
||||
[ApiMember(Name = "InheritFromParent", Description = "Determines whether or not parent items should be searched for theme media.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
||||
public bool InheritFromParent { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class GetThemeVideos
|
||||
/// </summary>
|
||||
[Route("/Items/{Id}/ThemeVideos", "GET")]
|
||||
[Api(Description = "Gets video backdrops for an item")]
|
||||
public class GetThemeVideos : IReturn<ThemeVideosResult>
|
||||
[Api(Description = "Gets theme videos for an item")]
|
||||
public class GetThemeVideos : IReturn<ThemeMediaResult>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user id.
|
||||
|
@ -89,6 +92,34 @@ namespace MediaBrowser.Api
|
|||
/// <value>The id.</value>
|
||||
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
||||
public string Id { get; set; }
|
||||
|
||||
[ApiMember(Name = "InheritFromParent", Description = "Determines whether or not parent items should be searched for theme media.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
||||
public bool InheritFromParent { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class GetThemeVideos
|
||||
/// </summary>
|
||||
[Route("/Items/{Id}/ThemeMedia", "GET")]
|
||||
[Api(Description = "Gets theme videos and songs for an item")]
|
||||
public class GetThemeMedia : IReturn<ThemeMediaResult>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user id.
|
||||
/// </summary>
|
||||
/// <value>The user id.</value>
|
||||
[ApiMember(Name = "UserId", Description = "Optional. Filter by user id, and attach user data", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
||||
public Guid? UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the id.
|
||||
/// </summary>
|
||||
/// <value>The id.</value>
|
||||
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
||||
public string Id { get; set; }
|
||||
|
||||
[ApiMember(Name = "InheritFromParent", Description = "Determines whether or not parent items should be searched for theme media.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
||||
public bool InheritFromParent { get; set; }
|
||||
}
|
||||
|
||||
[Route("/Library/Refresh", "POST")]
|
||||
|
@ -112,7 +143,7 @@ namespace MediaBrowser.Api
|
|||
[ApiMember(Name = "UserId", Description = "Optional. Get counts from a specific user's library.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
||||
public Guid? UserId { get; set; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Class LibraryService
|
||||
/// </summary>
|
||||
|
@ -230,7 +261,7 @@ namespace MediaBrowser.Api
|
|||
{
|
||||
throw new InvalidOperationException(string.Format("{0} is currently offline.", item.Name));
|
||||
}
|
||||
|
||||
|
||||
if (item.LocationType == LocationType.FileSystem)
|
||||
{
|
||||
if (Directory.Exists(item.Path))
|
||||
|
@ -303,12 +334,44 @@ namespace MediaBrowser.Api
|
|||
return result;
|
||||
}
|
||||
|
||||
public object Get(GetThemeMedia request)
|
||||
{
|
||||
var themeSongs = GetThemeSongs(new GetThemeSongs
|
||||
{
|
||||
InheritFromParent = request.InheritFromParent,
|
||||
Id = request.Id,
|
||||
UserId = request.UserId
|
||||
|
||||
}).Result;
|
||||
|
||||
var themeVideos = GetThemeVideos(new GetThemeVideos
|
||||
{
|
||||
InheritFromParent = request.InheritFromParent,
|
||||
Id = request.Id,
|
||||
UserId = request.UserId
|
||||
|
||||
}).Result;
|
||||
|
||||
return ToOptimizedResult(new AllThemeMediaResult
|
||||
{
|
||||
ThemeSongsResult = themeSongs,
|
||||
ThemeVideosResult = themeVideos
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
public object Get(GetThemeSongs request)
|
||||
{
|
||||
var result = GetThemeSongs(request).Result;
|
||||
|
||||
return ToOptimizedResult(result);
|
||||
}
|
||||
|
||||
private async Task<ThemeMediaResult> GetThemeSongs(GetThemeSongs request)
|
||||
{
|
||||
var user = request.UserId.HasValue ? _userManager.GetUserById(request.UserId.Value) : null;
|
||||
|
||||
|
@ -318,6 +381,11 @@ namespace MediaBrowser.Api
|
|||
: (Folder)_libraryManager.RootFolder)
|
||||
: DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, request.UserId);
|
||||
|
||||
while (item.ThemeSongIds.Count == 0 && request.InheritFromParent && item.Parent != null)
|
||||
{
|
||||
item = item.Parent;
|
||||
}
|
||||
|
||||
// Get everything
|
||||
var fields = Enum.GetNames(typeof(ItemFields))
|
||||
.Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true))
|
||||
|
@ -325,20 +393,18 @@ namespace MediaBrowser.Api
|
|||
|
||||
var dtoBuilder = new DtoBuilder(Logger, _libraryManager, _userDataRepository, _itemRepo);
|
||||
|
||||
var items = item.ThemeSongIds.Select(_itemRepo.RetrieveItem)
|
||||
.OrderBy(i => i.SortName)
|
||||
.Select(i => dtoBuilder.GetBaseItemDto(i, fields, user))
|
||||
.Select(t => t.Result)
|
||||
.ToArray();
|
||||
var tasks = item.ThemeSongIds.Select(_itemRepo.RetrieveItem)
|
||||
.OrderBy(i => i.SortName)
|
||||
.Select(i => dtoBuilder.GetBaseItemDto(i, fields, user));
|
||||
|
||||
var result = new ThemeSongsResult
|
||||
var items = await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
|
||||
return new ThemeMediaResult
|
||||
{
|
||||
Items = items,
|
||||
TotalRecordCount = items.Length,
|
||||
OwnerId = DtoBuilder.GetClientItemId(item)
|
||||
};
|
||||
|
||||
return ToOptimizedResult(result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -347,6 +413,13 @@ namespace MediaBrowser.Api
|
|||
/// <param name="request">The request.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
public object Get(GetThemeVideos request)
|
||||
{
|
||||
var result = GetThemeVideos(request).Result;
|
||||
|
||||
return ToOptimizedResult(result);
|
||||
}
|
||||
|
||||
public async Task<ThemeMediaResult> GetThemeVideos(GetThemeVideos request)
|
||||
{
|
||||
var user = request.UserId.HasValue ? _userManager.GetUserById(request.UserId.Value) : null;
|
||||
|
||||
|
@ -356,6 +429,11 @@ namespace MediaBrowser.Api
|
|||
: (Folder)_libraryManager.RootFolder)
|
||||
: DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, request.UserId);
|
||||
|
||||
while (item.ThemeVideoIds.Count == 0 && request.InheritFromParent && item.Parent != null)
|
||||
{
|
||||
item = item.Parent;
|
||||
}
|
||||
|
||||
// Get everything
|
||||
var fields =
|
||||
Enum.GetNames(typeof(ItemFields))
|
||||
|
@ -364,22 +442,18 @@ namespace MediaBrowser.Api
|
|||
|
||||
var dtoBuilder = new DtoBuilder(Logger, _libraryManager, _userDataRepository, _itemRepo);
|
||||
|
||||
var items =
|
||||
item.ThemeVideoIds.Select(_itemRepo.RetrieveItem)
|
||||
.OrderBy(i => i.SortName)
|
||||
.Select(i => dtoBuilder.GetBaseItemDto(i, fields, user))
|
||||
.Select(t => t.Result)
|
||||
.ToArray();
|
||||
var tasks = item.ThemeVideoIds.Select(_itemRepo.RetrieveItem)
|
||||
.OrderBy(i => i.SortName)
|
||||
.Select(i => dtoBuilder.GetBaseItemDto(i, fields, user));
|
||||
|
||||
var result = new ThemeVideosResult
|
||||
{
|
||||
Items = items,
|
||||
TotalRecordCount = items.Length,
|
||||
OwnerId = DtoBuilder.GetClientItemId(item)
|
||||
};
|
||||
var items = await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
|
||||
return ToOptimizedResult(result);
|
||||
return new ThemeMediaResult
|
||||
{
|
||||
Items = items,
|
||||
TotalRecordCount = items.Length,
|
||||
OwnerId = DtoBuilder.GetClientItemId(item)
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -425,6 +425,13 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
return artists.Any(album.HasArtist);
|
||||
}
|
||||
|
||||
var musicVideo = i as MusicVideo;
|
||||
|
||||
if (musicVideo != null)
|
||||
{
|
||||
return artists.Any(musicVideo.HasArtist);
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,10 +1,23 @@
|
|||
using MediaBrowser.Model.Entities;
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
public class MusicVideo : Video
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the artist.
|
||||
/// </summary>
|
||||
/// <value>The artist.</value>
|
||||
public string Artist { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the album.
|
||||
/// </summary>
|
||||
/// <value>The album.</value>
|
||||
public string Album { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Should be overridden to return the proper folder where metadata lives
|
||||
/// </summary>
|
||||
|
@ -18,6 +31,16 @@ namespace MediaBrowser.Controller.Entities
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified name has artist.
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <returns><c>true</c> if the specified name has artist; otherwise, <c>false</c>.</returns>
|
||||
public bool HasArtist(string name)
|
||||
{
|
||||
return string.Equals(Artist, name, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the user data key.
|
||||
/// </summary>
|
||||
|
|
|
@ -23,6 +23,33 @@ namespace MediaBrowser.Model.ApiClient
|
|||
/// </summary>
|
||||
event EventHandler<HttpResponseEventArgs> HttpResponseReceived;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the theme songs async.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="itemId">The item id.</param>
|
||||
/// <param name="inheritFromParents">if set to <c>true</c> [inherit from parents].</param>
|
||||
/// <returns>Task{ThemeMediaResult}.</returns>
|
||||
Task<ThemeMediaResult> GetThemeSongsAsync(string userId, string itemId, bool inheritFromParents);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the theme videos async.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="itemId">The item id.</param>
|
||||
/// <param name="inheritFromParents">if set to <c>true</c> [inherit from parents].</param>
|
||||
/// <returns>Task{ThemeMediaResult}.</returns>
|
||||
Task<ThemeMediaResult> GetThemeVideosAsync(string userId, string itemId, bool inheritFromParents);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all theme media async.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user id.</param>
|
||||
/// <param name="itemId">The item id.</param>
|
||||
/// <param name="inheritFromParents">if set to <c>true</c> [inherit from parents].</param>
|
||||
/// <returns>Task{AllThemeMediaResult}.</returns>
|
||||
Task<AllThemeMediaResult> GetAllThemeMediaAsync(string userId, string itemId, bool inheritFromParents);
|
||||
|
||||
/// <summary>
|
||||
/// Marks the notifications read.
|
||||
/// </summary>
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
using System;
|
||||
|
||||
|
||||
namespace MediaBrowser.Model.Querying
|
||||
{
|
||||
/// <summary>
|
||||
/// Class ThemeSongsResult
|
||||
/// Class ThemeMediaResult
|
||||
/// </summary>
|
||||
public class ThemeSongsResult : ItemsResult
|
||||
public class ThemeMediaResult : ItemsResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the owner id.
|
||||
|
@ -14,12 +13,10 @@ namespace MediaBrowser.Model.Querying
|
|||
public string OwnerId { get; set; }
|
||||
}
|
||||
|
||||
public class ThemeVideosResult : ItemsResult
|
||||
public class AllThemeMediaResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the owner id.
|
||||
/// </summary>
|
||||
/// <value>The owner id.</value>
|
||||
public string OwnerId { get; set; }
|
||||
public ThemeMediaResult ThemeVideosResult { get; set; }
|
||||
|
||||
public ThemeMediaResult ThemeSongsResult { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>MediaBrowser.Common.Internal</id>
|
||||
<version>3.0.144</version>
|
||||
<version>3.0.145</version>
|
||||
<title>MediaBrowser.Common.Internal</title>
|
||||
<authors>Luke</authors>
|
||||
<owners>ebr,Luke,scottisafool</owners>
|
||||
|
@ -12,7 +12,7 @@
|
|||
<description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description>
|
||||
<copyright>Copyright © Media Browser 2013</copyright>
|
||||
<dependencies>
|
||||
<dependency id="MediaBrowser.Common" version="3.0.144" />
|
||||
<dependency id="MediaBrowser.Common" version="3.0.145" />
|
||||
<dependency id="NLog" version="2.0.1.2" />
|
||||
<dependency id="ServiceStack.Text" version="3.9.45" />
|
||||
<dependency id="SimpleInjector" version="2.2.3" />
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>MediaBrowser.Common</id>
|
||||
<version>3.0.144</version>
|
||||
<version>3.0.145</version>
|
||||
<title>MediaBrowser.Common</title>
|
||||
<authors>Media Browser Team</authors>
|
||||
<owners>ebr,Luke,scottisafool</owners>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>MediaBrowser.Server.Core</id>
|
||||
<version>3.0.144</version>
|
||||
<version>3.0.145</version>
|
||||
<title>Media Browser.Server.Core</title>
|
||||
<authors>Media Browser Team</authors>
|
||||
<owners>ebr,Luke,scottisafool</owners>
|
||||
|
@ -12,7 +12,7 @@
|
|||
<description>Contains core components required to build plugins for Media Browser Server.</description>
|
||||
<copyright>Copyright © Media Browser 2013</copyright>
|
||||
<dependencies>
|
||||
<dependency id="MediaBrowser.Common" version="3.0.144" />
|
||||
<dependency id="MediaBrowser.Common" version="3.0.145" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
|
|
Loading…
Reference in New Issue
Block a user