added theme song support
This commit is contained in:
parent
0d15e1d631
commit
d78c378452
|
@ -305,6 +305,25 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Route("/Users/{UserId}/Items/{Id}/ThemeSongs", "GET")]
|
||||||
|
[Api(Description = "Gets theme songs for an item")]
|
||||||
|
public class GetThemeSongs : IReturn<List<BaseItemDto>>
|
||||||
|
{
|
||||||
|
/// <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>
|
/// <summary>
|
||||||
/// Class GetSpecialFeatures
|
/// Class GetSpecialFeatures
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -396,6 +415,27 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
return ToOptimizedResult(items);
|
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).ToList();
|
||||||
|
|
||||||
|
return ToOptimizedResult(items);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the specified request.
|
/// Gets the specified request.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -35,6 +35,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
/// The trailer folder name
|
/// The trailer folder name
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string TrailerFolderName = "trailers";
|
public const string TrailerFolderName = "trailers";
|
||||||
|
public const string ThemeSongsFolderName = "theme-music";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the name.
|
/// 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>
|
/// <summary>
|
||||||
/// Loads local trailers from the file system
|
/// Loads local trailers from the file system
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -714,6 +737,64 @@ namespace MediaBrowser.Controller.Entities
|
||||||
}).ToList();
|
}).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>
|
/// <summary>
|
||||||
/// Overrides the base implementation to refresh metadata for local trailers
|
/// Overrides the base implementation to refresh metadata for local trailers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -732,6 +813,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
|
|
||||||
// Lazy load these again
|
// Lazy load these again
|
||||||
LocalTrailers = null;
|
LocalTrailers = null;
|
||||||
|
ThemeSongs = null;
|
||||||
|
|
||||||
// Refresh for the item
|
// Refresh for the item
|
||||||
var itemRefreshTask = ProviderManager.ExecuteMetadataProviders(this, cancellationToken, forceRefresh, allowSlowProviders);
|
var itemRefreshTask = ProviderManager.ExecuteMetadataProviders(this, cancellationToken, forceRefresh, allowSlowProviders);
|
||||||
|
@ -741,10 +823,13 @@ namespace MediaBrowser.Controller.Entities
|
||||||
// Refresh metadata for local trailers
|
// Refresh metadata for local trailers
|
||||||
var trailerTasks = LocalTrailers.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
|
var trailerTasks = LocalTrailers.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
|
||||||
|
|
||||||
|
var themeSongTasks = ThemeSongs.Select(i => i.RefreshMetadata(cancellationToken, forceSave, forceRefresh, allowSlowProviders));
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
// Await the trailer tasks
|
// Await the trailer tasks
|
||||||
await Task.WhenAll(trailerTasks).ConfigureAwait(false);
|
await Task.WhenAll(trailerTasks).ConfigureAwait(false);
|
||||||
|
await Task.WhenAll(themeSongTasks).ConfigureAwait(false);
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
using MediaBrowser.Controller.Library;
|
using System.IO;
|
||||||
|
using MediaBrowser.Controller.Entities;
|
||||||
|
using MediaBrowser.Controller.Library;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -35,9 +37,14 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||||
{
|
{
|
||||||
// Ignore hidden files and folders
|
// Ignore hidden files and folders
|
||||||
if (args.IsHidden)
|
if (args.IsHidden)
|
||||||
|
{
|
||||||
|
var parentFolderName = Path.GetFileName(Path.GetDirectoryName(args.Path));
|
||||||
|
|
||||||
|
if (!string.Equals(parentFolderName, BaseItem.ThemeSongsFolderName, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (args.IsDirectory)
|
if (args.IsDirectory)
|
||||||
{
|
{
|
||||||
|
|
|
@ -274,9 +274,11 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||||
|
|
||||||
var specialFeatures = items.OfType<Movie>().SelectMany(i => i.SpecialFeatures).ToList();
|
var specialFeatures = items.OfType<Movie>().SelectMany(i => i.SpecialFeatures).ToList();
|
||||||
var localTrailers = items.SelectMany(i => i.LocalTrailers).ToList();
|
var localTrailers = items.SelectMany(i => i.LocalTrailers).ToList();
|
||||||
|
var themeSongs = items.SelectMany(i => i.ThemeSongs).ToList();
|
||||||
|
|
||||||
items.AddRange(specialFeatures);
|
items.AddRange(specialFeatures);
|
||||||
items.AddRange(localTrailers);
|
items.AddRange(localTrailers);
|
||||||
|
items.AddRange(themeSongs);
|
||||||
|
|
||||||
// Need to use DistinctBy Id because there could be multiple instances with the same id
|
// Need to use DistinctBy Id because there could be multiple instances with the same id
|
||||||
// due to sharing the default library
|
// due to sharing the default library
|
||||||
|
@ -325,22 +327,29 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||||
{
|
{
|
||||||
LibraryItemsCache.AddOrUpdate(item.Id, item, delegate { return item; });
|
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
|
// Prevent access to foreach variable in closure
|
||||||
var trailer1 = trailer;
|
var trailer1 = subItem;
|
||||||
LibraryItemsCache.AddOrUpdate(trailer.Id, trailer, delegate { return trailer1; });
|
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;
|
var movie = item as Movie;
|
||||||
|
|
||||||
if (movie != null)
|
if (movie != null)
|
||||||
{
|
{
|
||||||
foreach (var special in movie.SpecialFeatures)
|
foreach (var subItem in movie.SpecialFeatures)
|
||||||
{
|
{
|
||||||
// Prevent access to foreach variable in closure
|
// Prevent access to foreach variable in closure
|
||||||
var special1 = special;
|
var special1 = subItem;
|
||||||
LibraryItemsCache.AddOrUpdate(special.Id, special, delegate { return special1; });
|
LibraryItemsCache.AddOrUpdate(subItem.Id, subItem, delegate { return special1; });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* Gets special features for an item
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<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.Common" version="3.9.43" targetFramework="net45" />
|
||||||
<package id="ServiceStack.Text" version="3.9.43" targetFramework="net45" />
|
<package id="ServiceStack.Text" version="3.9.43" targetFramework="net45" />
|
||||||
</packages>
|
</packages>
|
Loading…
Reference in New Issue
Block a user