This commit is contained in:
Eric Reed 2013-04-24 14:54:34 -04:00
commit 3636215710
8 changed files with 238 additions and 17 deletions

View File

@ -161,7 +161,7 @@ namespace MediaBrowser.Api.UserLibrary
public string Id { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this <see cref="UpdateUserItemRating"/> is likes.
/// Gets or sets a value indicating whether this <see cref="UpdateUserItemRating" /> is likes.
/// </summary>
/// <value><c>true</c> if likes; otherwise, <c>false</c>.</value>
[ApiMember(Name = "Likes", Description = "Whether the user likes the item or not. true/false", IsRequired = true, DataType = "boolean", ParameterType = "query", Verb = "POST")]
@ -212,6 +212,9 @@ namespace MediaBrowser.Api.UserLibrary
public string Id { get; set; }
}
/// <summary>
/// Class OnPlaybackStart
/// </summary>
[Route("/Users/{UserId}/PlayingItems/{Id}", "POST")]
[Api(Description = "Reports that a user has begun playing an item")]
public class OnPlaybackStart : IReturnVoid
@ -231,6 +234,9 @@ namespace MediaBrowser.Api.UserLibrary
public string Id { get; set; }
}
/// <summary>
/// Class OnPlaybackProgress
/// </summary>
[Route("/Users/{UserId}/PlayingItems/{Id}/Progress", "POST")]
[Api(Description = "Reports a user's playback progress")]
public class OnPlaybackProgress : IReturnVoid
@ -257,6 +263,9 @@ namespace MediaBrowser.Api.UserLibrary
public long? PositionTicks { get; set; }
}
/// <summary>
/// Class OnPlaybackStopped
/// </summary>
[Route("/Users/{UserId}/PlayingItems/{Id}", "DELETE")]
[Api(Description = "Reports that a user has stopped playing an item")]
public class OnPlaybackStopped : IReturnVoid
@ -305,6 +314,28 @@ namespace MediaBrowser.Api.UserLibrary
public string Id { get; set; }
}
/// <summary>
/// Class GetThemeSongs
/// </summary>
[Route("/Users/{UserId}/Items/{Id}/ThemeSongs", "GET")]
[Api(Description = "Gets theme songs for an item")]
public class GetThemeSongs : IReturn<ThemeSongsResult>
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", 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; }
}
/// <summary>
/// Class GetSpecialFeatures
/// </summary>
@ -337,12 +368,21 @@ namespace MediaBrowser.Api.UserLibrary
/// The _user manager
/// </summary>
private readonly IUserManager _userManager;
/// <summary>
/// The _user data repository
/// </summary>
private readonly IUserDataRepository _userDataRepository;
/// <summary>
/// The _library manager
/// </summary>
private readonly ILibraryManager _libraryManager;
/// <summary>
/// Initializes a new instance of the <see cref="UserLibraryService" /> class.
/// </summary>
/// <param name="userManager">The user manager.</param>
/// <param name="libraryManager">The library manager.</param>
/// <param name="userDataRepository">The user data repository.</param>
/// <exception cref="System.ArgumentNullException">jsonSerializer</exception>
public UserLibraryService(IUserManager userManager, ILibraryManager libraryManager, IUserDataRepository userDataRepository)
: base()
@ -396,6 +436,34 @@ namespace MediaBrowser.Api.UserLibrary
return ToOptimizedResult(items);
}
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get(GetThemeSongs request)
{
var user = _userManager.GetUserById(request.UserId);
var item = string.IsNullOrEmpty(request.Id) ? user.RootFolder : DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager, user.Id);
// Get everything
var fields = Enum.GetNames(typeof(ItemFields)).Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)).ToList();
var dtoBuilder = new DtoBuilder(Logger, _libraryManager, _userDataRepository);
var items = item.ThemeSongs.Select(i => dtoBuilder.GetBaseItemDto(i, user, fields)).AsParallel().Select(t => t.Result).ToArray();
var result = new ThemeSongsResult
{
Items = items,
TotalRecordCount = items.Length,
OwnerId = DtoBuilder.GetClientItemId(item)
};
return ToOptimizedResult(result);
}
/// <summary>
/// Gets the specified request.
/// </summary>
@ -417,6 +485,11 @@ namespace MediaBrowser.Api.UserLibrary
return ToOptimizedResult(result);
}
/// <summary>
/// Gets the specified request.
/// </summary>
/// <param name="request">The request.</param>
/// <returns>System.Object.</returns>
public object Get(GetRootFolder request)
{
var user = _userManager.GetUserById(request.UserId);

View File

@ -35,6 +35,7 @@ namespace MediaBrowser.Controller.Entities
/// The trailer folder name
/// </summary>
public const string TrailerFolderName = "trailers";
public const string ThemeSongsFolderName = "theme-music";
/// <summary>
/// Gets or sets the name.
@ -656,6 +657,28 @@ namespace MediaBrowser.Controller.Entities
}
}
private List<Audio.Audio> _themeSongs;
private bool _themeSongsInitialized;
private object _themeSongsSyncLock = new object();
[IgnoreDataMember]
public List<Audio.Audio> ThemeSongs
{
get
{
LazyInitializer.EnsureInitialized(ref _themeSongs, ref _themeSongsInitialized, ref _themeSongsSyncLock, LoadThemeSongs);
return _themeSongs;
}
private set
{
_themeSongs = value;
if (value == null)
{
_themeSongsInitialized = false;
}
}
}
/// <summary>
/// Loads local trailers from the file system
/// </summary>
@ -714,6 +737,64 @@ namespace MediaBrowser.Controller.Entities
}).ToList();
}
/// <summary>
/// Loads the theme songs.
/// </summary>
/// <returns>List{Audio.Audio}.</returns>
private List<Audio.Audio> LoadThemeSongs()
{
ItemResolveArgs resolveArgs;
try
{
resolveArgs = ResolveArgs;
}
catch (IOException ex)
{
Logger.ErrorException("Error getting ResolveArgs for {0}", ex, Path);
return new List<Audio.Audio>();
}
if (!resolveArgs.IsDirectory)
{
return new List<Audio.Audio>();
}
var folder = resolveArgs.GetFileSystemEntryByName(ThemeSongsFolderName);
// Path doesn't exist. No biggie
if (folder == null)
{
return new List<Audio.Audio>();
}
IEnumerable<WIN32_FIND_DATA> files;
try
{
files = FileSystem.GetFiles(folder.Value.Path);
}
catch (IOException ex)
{
Logger.ErrorException("Error loading theme songs for {0}", ex, Name);
return new List<Audio.Audio>();
}
return LibraryManager.ResolvePaths<Audio.Audio>(files, null).Select(audio =>
{
// Try to retrieve it from the db. If we don't find it, use the resolved version
var dbItem = LibraryManager.RetrieveItem(audio.Id) as Audio.Audio;
if (dbItem != null)
{
dbItem.ResolveArgs = audio.ResolveArgs;
audio = dbItem;
}
return audio;
}).ToList();
}
/// <summary>
/// Overrides the base implementation to refresh metadata for local trailers
/// </summary>
@ -732,6 +813,7 @@ namespace MediaBrowser.Controller.Entities
// Lazy load these again
LocalTrailers = null;
ThemeSongs = null;
// Refresh for the item
var itemRefreshTask = ProviderManager.ExecuteMetadataProviders(this, cancellationToken, forceRefresh, allowSlowProviders);
@ -741,10 +823,13 @@ namespace MediaBrowser.Controller.Entities
// Refresh metadata for local trailers
var trailerTasks = LocalTrailers.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
var themeSongTasks = ThemeSongs.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
cancellationToken.ThrowIfCancellationRequested();
// Await the trailer tasks
await Task.WhenAll(trailerTasks).ConfigureAwait(false);
await Task.WhenAll(themeSongTasks).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();

View File

@ -84,6 +84,7 @@
<Compile Include="Net\NetworkShare.cs" />
<Compile Include="Net\NetworkShareType.cs" />
<Compile Include="Querying\PersonsQuery.cs" />
<Compile Include="Querying\ThemeSongsResult.cs" />
<Compile Include="Serialization\IJsonSerializer.cs" />
<Compile Include="Serialization\IXmlSerializer.cs" />
<Compile Include="Updates\CheckForUpdateResult.cs" />

View File

@ -0,0 +1,16 @@
using System;
namespace MediaBrowser.Model.Querying
{
/// <summary>
/// Class ThemeSongsResult
/// </summary>
public class ThemeSongsResult : ItemsResult
{
/// <summary>
/// Gets or sets the owner id.
/// </summary>
/// <value>The owner id.</value>
public string OwnerId { get; set; }
}
}

View File

@ -1,4 +1,6 @@
using MediaBrowser.Controller.Library;
using System.IO;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using System;
using System.Collections.Generic;
using System.Linq;
@ -16,7 +18,6 @@ namespace MediaBrowser.Server.Implementations.Library
/// </summary>
private static readonly List<string> IgnoreFolders = new List<string>
{
"trailers",
"metadata",
"certificate",
"backup",
@ -36,7 +37,12 @@ namespace MediaBrowser.Server.Implementations.Library
// Ignore hidden files and folders
if (args.IsHidden)
{
return true;
var parentFolderName = Path.GetFileName(Path.GetDirectoryName(args.Path));
if (!string.Equals(parentFolderName, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
if (args.IsDirectory)
@ -48,6 +54,16 @@ namespace MediaBrowser.Server.Implementations.Library
{
return true;
}
if (string.Equals(filename, BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase))
{
return true;
}
if (string.Equals(filename, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
return false;

View File

@ -274,9 +274,11 @@ namespace MediaBrowser.Server.Implementations.Library
var specialFeatures = items.OfType<Movie>().SelectMany(i => i.SpecialFeatures).ToList();
var localTrailers = items.SelectMany(i => i.LocalTrailers).ToList();
var themeSongs = items.SelectMany(i => i.ThemeSongs).ToList();
items.AddRange(specialFeatures);
items.AddRange(localTrailers);
items.AddRange(themeSongs);
// Need to use DistinctBy Id because there could be multiple instances with the same id
// due to sharing the default library
@ -325,22 +327,29 @@ namespace MediaBrowser.Server.Implementations.Library
{
LibraryItemsCache.AddOrUpdate(item.Id, item, delegate { return item; });
foreach (var trailer in item.LocalTrailers)
foreach (var subItem in item.LocalTrailers)
{
// Prevent access to foreach variable in closure
var trailer1 = trailer;
LibraryItemsCache.AddOrUpdate(trailer.Id, trailer, delegate { return trailer1; });
var trailer1 = subItem;
LibraryItemsCache.AddOrUpdate(subItem.Id, subItem, delegate { return trailer1; });
}
foreach (var subItem in item.ThemeSongs)
{
// Prevent access to foreach variable in closure
var trailer1 = subItem;
LibraryItemsCache.AddOrUpdate(subItem.Id, subItem, delegate { return trailer1; });
}
var movie = item as Movie;
if (movie != null)
{
foreach (var special in movie.SpecialFeatures)
foreach (var subItem in movie.SpecialFeatures)
{
// Prevent access to foreach variable in closure
var special1 = special;
LibraryItemsCache.AddOrUpdate(special.Id, special, delegate { return special1; });
var special1 = subItem;
LibraryItemsCache.AddOrUpdate(subItem.Id, subItem, delegate { return special1; });
}
}
}

View File

@ -1712,6 +1712,27 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
});
};
/**
* Gets theme songs for an item
*/
self.getThemeSongs = function (userId, itemId) {
if (!userId) {
throw new Error("null userId");
}
if (!itemId) {
throw new Error("null itemId");
}
var url = self.getUrl("Users/" + userId + "/Items/" + itemId + "/ThemeSongs");
return self.ajax({
type: "GET",
url: url,
dataType: "json"
});
};
/**
* Gets special features for an item
*/

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.85" targetFramework="net45" />
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.86" targetFramework="net45" />
<package id="ServiceStack.Common" version="3.9.43" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.43" targetFramework="net45" />
</packages>