fixes #573 - Support media info for intros
This commit is contained in:
parent
cbbb984160
commit
fe2eb6cb01
|
@ -58,7 +58,7 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Route("/Users/{UserId}/Items/{Id}/Intros", "GET")]
|
[Route("/Users/{UserId}/Items/{Id}/Intros", "GET")]
|
||||||
[Api(("Gets intros to play before the main media item plays"))]
|
[Api(("Gets intros to play before the main media item plays"))]
|
||||||
public class GetIntros : IReturn<List<string>>
|
public class GetIntros : IReturn<ItemsResult>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the user id.
|
/// Gets or sets the user id.
|
||||||
|
@ -552,7 +552,21 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
|
|
||||||
var item = string.IsNullOrEmpty(request.Id) ? user.RootFolder : _dtoService.GetItemByDtoId(request.Id, user.Id);
|
var item = string.IsNullOrEmpty(request.Id) ? user.RootFolder : _dtoService.GetItemByDtoId(request.Id, user.Id);
|
||||||
|
|
||||||
var result = _libraryManager.GetIntros(item, user);
|
var items = _libraryManager.GetIntros(item, user);
|
||||||
|
|
||||||
|
// Get everything
|
||||||
|
var fields = Enum.GetNames(typeof(ItemFields))
|
||||||
|
.Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var dtos = items.Select(i => _dtoService.GetBaseItemDto(i, fields, user))
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
var result = new ItemsResult
|
||||||
|
{
|
||||||
|
Items = dtos,
|
||||||
|
TotalRecordCount = dtos.Length
|
||||||
|
};
|
||||||
|
|
||||||
return ToOptimizedResult(result);
|
return ToOptimizedResult(result);
|
||||||
}
|
}
|
||||||
|
@ -579,6 +593,13 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
return ToOptimizedResult(dto);
|
return ToOptimizedResult(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Marks the favorite.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId">The user id.</param>
|
||||||
|
/// <param name="itemId">The item id.</param>
|
||||||
|
/// <param name="isFavorite">if set to <c>true</c> [is favorite].</param>
|
||||||
|
/// <returns>Task{UserItemDataDto}.</returns>
|
||||||
private async Task<UserItemDataDto> MarkFavorite(Guid userId, string itemId, bool isFavorite)
|
private async Task<UserItemDataDto> MarkFavorite(Guid userId, string itemId, bool isFavorite)
|
||||||
{
|
{
|
||||||
var user = _userManager.GetUserById(userId);
|
var user = _userManager.GetUserById(userId);
|
||||||
|
@ -622,6 +643,13 @@ namespace MediaBrowser.Api.UserLibrary
|
||||||
return ToOptimizedResult(dto);
|
return ToOptimizedResult(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the user item rating.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userId">The user id.</param>
|
||||||
|
/// <param name="itemId">The item id.</param>
|
||||||
|
/// <param name="likes">if set to <c>true</c> [likes].</param>
|
||||||
|
/// <returns>Task{UserItemDataDto}.</returns>
|
||||||
private async Task<UserItemDataDto> UpdateUserItemRating(Guid userId, string itemId, bool? likes)
|
private async Task<UserItemDataDto> UpdateUserItemRating(Guid userId, string itemId, bool? likes)
|
||||||
{
|
{
|
||||||
var user = _userManager.GetUserById(userId);
|
var user = _userManager.GetUserById(userId);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.Library
|
namespace MediaBrowser.Controller.Library
|
||||||
|
@ -14,12 +15,27 @@ namespace MediaBrowser.Controller.Library
|
||||||
/// <param name="item">The item.</param>
|
/// <param name="item">The item.</param>
|
||||||
/// <param name="user">The user.</param>
|
/// <param name="user">The user.</param>
|
||||||
/// <returns>IEnumerable{System.String}.</returns>
|
/// <returns>IEnumerable{System.String}.</returns>
|
||||||
IEnumerable<string> GetIntros(BaseItem item, User user);
|
IEnumerable<IntroInfo> GetIntros(BaseItem item, User user);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets all intros.
|
/// Gets all intro files.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>IEnumerable{System.String}.</returns>
|
/// <returns>IEnumerable{System.String}.</returns>
|
||||||
IEnumerable<string> GetAllIntros();
|
IEnumerable<string> GetAllIntroFiles();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class IntroInfo
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the path.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The path.</value>
|
||||||
|
public string Path { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the item id.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The item id.</value>
|
||||||
|
public Guid? ItemId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,11 @@ namespace MediaBrowser.Controller.Library
|
||||||
/// <value>The root folder.</value>
|
/// <value>The root folder.</value>
|
||||||
AggregateFolder RootFolder { get; }
|
AggregateFolder RootFolder { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the person sync.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name.</param>
|
||||||
|
/// <returns>Person.</returns>
|
||||||
Person GetPersonSync(string name);
|
Person GetPersonSync(string name);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -143,7 +148,13 @@ namespace MediaBrowser.Controller.Library
|
||||||
/// <param name="item">The item.</param>
|
/// <param name="item">The item.</param>
|
||||||
/// <param name="user">The user.</param>
|
/// <param name="user">The user.</param>
|
||||||
/// <returns>IEnumerable{System.String}.</returns>
|
/// <returns>IEnumerable{System.String}.</returns>
|
||||||
IEnumerable<string> GetIntros(BaseItem item, User user);
|
IEnumerable<Video> GetIntros(BaseItem item, User user);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all intro files.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>IEnumerable{System.String}.</returns>
|
||||||
|
IEnumerable<string> GetAllIntroFiles();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the parts.
|
/// Adds the parts.
|
||||||
|
|
|
@ -169,9 +169,8 @@ namespace MediaBrowser.Model.ApiClient
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="itemId">The item id.</param>
|
/// <param name="itemId">The item id.</param>
|
||||||
/// <param name="userId">The user id.</param>
|
/// <param name="userId">The user id.</param>
|
||||||
/// <returns>Task{System.String[]}.</returns>
|
/// <returns>Task{ItemsResult}.</returns>
|
||||||
/// <exception cref="ArgumentNullException">id</exception>
|
Task<ItemsResult> GetIntrosAsync(string itemId, string userId);
|
||||||
Task<string[]> GetIntrosAsync(string itemId, string userId);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a BaseItem
|
/// Gets a BaseItem
|
||||||
|
|
|
@ -87,6 +87,7 @@
|
||||||
<Compile Include="Music\MusicVideoXmlParser.cs" />
|
<Compile Include="Music\MusicVideoXmlParser.cs" />
|
||||||
<Compile Include="Music\SoundtrackPostScanTask.cs" />
|
<Compile Include="Music\SoundtrackPostScanTask.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="RefreshIntrosTask.cs" />
|
||||||
<Compile Include="Savers\AlbumXmlSaver.cs" />
|
<Compile Include="Savers\AlbumXmlSaver.cs" />
|
||||||
<Compile Include="Savers\ArtistXmlSaver.cs" />
|
<Compile Include="Savers\ArtistXmlSaver.cs" />
|
||||||
<Compile Include="Savers\BoxSetXmlSaver.cs" />
|
<Compile Include="Savers\BoxSetXmlSaver.cs" />
|
||||||
|
|
105
MediaBrowser.Providers/RefreshIntrosTask.cs
Normal file
105
MediaBrowser.Providers/RefreshIntrosTask.cs
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
using MediaBrowser.Controller.IO;
|
||||||
|
using MediaBrowser.Controller.Library;
|
||||||
|
using MediaBrowser.Model.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MediaBrowser.Providers
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Class RefreshIntrosTask
|
||||||
|
/// </summary>
|
||||||
|
public class RefreshIntrosTask : ILibraryPostScanTask
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The _library manager
|
||||||
|
/// </summary>
|
||||||
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
/// <summary>
|
||||||
|
/// The _logger
|
||||||
|
/// </summary>
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="RefreshIntrosTask"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="libraryManager">The library manager.</param>
|
||||||
|
/// <param name="logger">The logger.</param>
|
||||||
|
public RefreshIntrosTask(ILibraryManager libraryManager, ILogger logger)
|
||||||
|
{
|
||||||
|
_libraryManager = libraryManager;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Runs the specified progress.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="progress">The progress.</param>
|
||||||
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
|
/// <returns>Task.</returns>
|
||||||
|
public async Task Run(IProgress<double> progress, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var files = _libraryManager.GetAllIntroFiles().ToList();
|
||||||
|
|
||||||
|
var numComplete = 0;
|
||||||
|
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await RefreshIntro(file, cancellationToken).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.ErrorException("Error refreshing intro {0}", ex, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
numComplete++;
|
||||||
|
double percent = numComplete;
|
||||||
|
percent /= files.Count;
|
||||||
|
progress.Report(percent * 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Refreshes the intro.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">The path.</param>
|
||||||
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
|
/// <returns>Task.</returns>
|
||||||
|
private async Task RefreshIntro(string path, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var item = _libraryManager.ResolvePath(FileSystem.GetFileSystemInfo(path));
|
||||||
|
|
||||||
|
if (item == null)
|
||||||
|
{
|
||||||
|
_logger.Error("Intro resolver returned null for {0}", path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var dbItem = _libraryManager.RetrieveItem(item.Id);
|
||||||
|
var isNewItem = false;
|
||||||
|
|
||||||
|
if (dbItem != null)
|
||||||
|
{
|
||||||
|
dbItem.ResetResolveArgs(item.ResolveArgs);
|
||||||
|
item = dbItem;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isNewItem = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Force the save if it's a new item
|
||||||
|
await item.RefreshMetadata(cancellationToken, isNewItem).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1129,9 +1129,75 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||||
/// <param name="item">The item.</param>
|
/// <param name="item">The item.</param>
|
||||||
/// <param name="user">The user.</param>
|
/// <param name="user">The user.</param>
|
||||||
/// <returns>IEnumerable{System.String}.</returns>
|
/// <returns>IEnumerable{System.String}.</returns>
|
||||||
public IEnumerable<string> GetIntros(BaseItem item, User user)
|
public IEnumerable<Video> GetIntros(BaseItem item, User user)
|
||||||
{
|
{
|
||||||
return IntroProviders.SelectMany(i => i.GetIntros(item, user));
|
return IntroProviders.SelectMany(i => i.GetIntros(item, user))
|
||||||
|
.Select(ResolveIntro)
|
||||||
|
.Where(i => i != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all intro files.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>IEnumerable{System.String}.</returns>
|
||||||
|
public IEnumerable<string> GetAllIntroFiles()
|
||||||
|
{
|
||||||
|
return IntroProviders.SelectMany(i => i.GetAllIntroFiles());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Resolves the intro.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="info">The info.</param>
|
||||||
|
/// <returns>Video.</returns>
|
||||||
|
private Video ResolveIntro(IntroInfo info)
|
||||||
|
{
|
||||||
|
Video video = null;
|
||||||
|
|
||||||
|
if (info.ItemId.HasValue)
|
||||||
|
{
|
||||||
|
// Get an existing item by Id
|
||||||
|
video = GetItemById(info.ItemId.Value) as Video;
|
||||||
|
|
||||||
|
if (video == null)
|
||||||
|
{
|
||||||
|
_logger.Error("Unable to locate item with Id {0}.", info.ItemId.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!string.IsNullOrEmpty(info.Path))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Try to resolve the path into a video
|
||||||
|
video = ResolvePath(FileSystem.GetFileSystemInfo(info.Path)) as Video;
|
||||||
|
|
||||||
|
if (video == null)
|
||||||
|
{
|
||||||
|
_logger.Error("Intro resolver returned null for {0}.", info.Path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Pull the saved db item that will include metadata
|
||||||
|
var dbItem = GetItemById(video.Id) as Video;
|
||||||
|
|
||||||
|
if (dbItem != null)
|
||||||
|
{
|
||||||
|
dbItem.ResetResolveArgs(video.ResolveArgs);
|
||||||
|
video = dbItem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.ErrorException("Error resolving path {0}.", ex, info.Path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Error("IntroProvider returned an IntroInfo with null Path and ItemId.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return video;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>MediaBrowser.Common.Internal</id>
|
<id>MediaBrowser.Common.Internal</id>
|
||||||
<version>3.0.218</version>
|
<version>3.0.219</version>
|
||||||
<title>MediaBrowser.Common.Internal</title>
|
<title>MediaBrowser.Common.Internal</title>
|
||||||
<authors>Luke</authors>
|
<authors>Luke</authors>
|
||||||
<owners>ebr,Luke,scottisafool</owners>
|
<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>
|
<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>
|
<copyright>Copyright © Media Browser 2013</copyright>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency id="MediaBrowser.Common" version="3.0.218" />
|
<dependency id="MediaBrowser.Common" version="3.0.219" />
|
||||||
<dependency id="NLog" version="2.0.1.2" />
|
<dependency id="NLog" version="2.0.1.2" />
|
||||||
<dependency id="ServiceStack.Text" version="3.9.58" />
|
<dependency id="ServiceStack.Text" version="3.9.58" />
|
||||||
<dependency id="SimpleInjector" version="2.3.2" />
|
<dependency id="SimpleInjector" version="2.3.2" />
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>MediaBrowser.Common</id>
|
<id>MediaBrowser.Common</id>
|
||||||
<version>3.0.218</version>
|
<version>3.0.219</version>
|
||||||
<title>MediaBrowser.Common</title>
|
<title>MediaBrowser.Common</title>
|
||||||
<authors>Media Browser Team</authors>
|
<authors>Media Browser Team</authors>
|
||||||
<owners>ebr,Luke,scottisafool</owners>
|
<owners>ebr,Luke,scottisafool</owners>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>MediaBrowser.Server.Core</id>
|
<id>MediaBrowser.Server.Core</id>
|
||||||
<version>3.0.218</version>
|
<version>3.0.219</version>
|
||||||
<title>Media Browser.Server.Core</title>
|
<title>Media Browser.Server.Core</title>
|
||||||
<authors>Media Browser Team</authors>
|
<authors>Media Browser Team</authors>
|
||||||
<owners>ebr,Luke,scottisafool</owners>
|
<owners>ebr,Luke,scottisafool</owners>
|
||||||
|
@ -12,7 +12,7 @@
|
||||||
<description>Contains core components required to build plugins for Media Browser Server.</description>
|
<description>Contains core components required to build plugins for Media Browser Server.</description>
|
||||||
<copyright>Copyright © Media Browser 2013</copyright>
|
<copyright>Copyright © Media Browser 2013</copyright>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency id="MediaBrowser.Common" version="3.0.218" />
|
<dependency id="MediaBrowser.Common" version="3.0.219" />
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</metadata>
|
</metadata>
|
||||||
<files>
|
<files>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user