fixed an issue with the video image provider requiring two-pass refreshing

This commit is contained in:
Luke Pulverenti 2013-04-05 21:03:38 -04:00
parent 9794c8fb1a
commit 9c7f492e2c
9 changed files with 149 additions and 99 deletions

View file

@ -93,7 +93,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
cancellationToken.ThrowIfCancellationRequested();
await Fetch(myItem, cancellationToken, result, isoMount).ConfigureAwait(false);
Fetch(myItem, cancellationToken, result, isoMount);
cancellationToken.ThrowIfCancellationRequested();
@ -180,7 +180,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
/// <param name="result">The result.</param>
/// <param name="isoMount">The iso mount.</param>
/// <returns>Task.</returns>
protected abstract Task Fetch(T item, CancellationToken cancellationToken, FFProbeResult result, IIsoMount isoMount);
protected abstract void Fetch(T item, CancellationToken cancellationToken, FFProbeResult result, IIsoMount isoMount);
/// <summary>
/// Converts ffprobe stream info to our MediaStream class

View file

@ -57,12 +57,6 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
if (video != null)
{
// Can't extract images if there are no video streams
if (video.MediaStreams == null || video.MediaStreams.All(m => m.Type != MediaStreamType.Video))
{
return false;
}
if (video.VideoType == VideoType.Iso && video.IsoType.HasValue && _isoManager.CanMount(item.Path))
{
return true;
@ -93,6 +87,9 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
{
var video = (Video)item;
// We can only extract images from videos if we know there's an embedded video stream
if (video.MediaStreams != null && video.MediaStreams.Any(m => m.Type == MediaStreamType.Video))
{
var filename = item.Id + "_" + item.DateModified.Ticks + "_primary";
var path = Kernel.Instance.FFMpegManager.VideoImageCache.GetResourcePath(filename, ".jpg");
@ -105,6 +102,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
// Image is already in the cache
item.PrimaryImagePath = path;
}
}
SetLastRefreshed(item, DateTime.UtcNow);
return TrueTaskResult;

View file

@ -42,9 +42,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
/// <param name="data">The data.</param>
/// <param name="isoMount">The iso mount.</param>
/// <returns>Task.</returns>
protected override Task Fetch(Audio audio, CancellationToken cancellationToken, FFProbeResult data, IIsoMount isoMount)
{
return Task.Run(() =>
protected override void Fetch(Audio audio, CancellationToken cancellationToken, FFProbeResult data, IIsoMount isoMount)
{
if (data.streams == null)
{
@ -76,7 +74,6 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
{
FetchDataFromTags(audio, data.format.tags);
}
});
}
/// <summary>

View file

@ -187,9 +187,7 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
/// <param name="data">The data.</param>
/// <param name="isoMount">The iso mount.</param>
/// <returns>Task.</returns>
protected override Task Fetch(Video video, CancellationToken cancellationToken, FFProbeResult data, IIsoMount isoMount)
{
return Task.Run(() =>
protected override void Fetch(Video video, CancellationToken cancellationToken, FFProbeResult data, IIsoMount isoMount)
{
if (data.format != null)
{
@ -224,7 +222,6 @@ namespace MediaBrowser.Controller.Providers.MediaInfo
}
AddExternalSubtitles(video);
});
}
/// <summary>

View file

@ -104,7 +104,7 @@ namespace MediaBrowser.Server.Implementations.Providers
/// <param name="providers">The providers.</param>
public void AddMetadataProviders(IEnumerable<BaseMetadataProvider> providers)
{
MetadataProviders = providers.ToArray();
MetadataProviders = providers.OrderBy(e => e.Priority).ToArray();
}
/// <summary>

View file

@ -30,7 +30,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite
/// <summary>
/// The flush interval
/// </summary>
private const int FlushInterval = 5000;
private const int FlushInterval = 2000;
/// <summary>
/// The flush timer

View file

@ -34,6 +34,18 @@ namespace MediaBrowser.Server.Implementations.Sqlite
}
}
/// <summary>
/// Gets a value indicating whether [enable delayed commands].
/// </summary>
/// <value><c>true</c> if [enable delayed commands]; otherwise, <c>false</c>.</value>
protected override bool EnableDelayedCommands
{
get
{
return false;
}
}
/// <summary>
/// The _protobuf serializer
/// </summary>
@ -106,7 +118,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite
/// or
/// userDataId
/// </exception>
public Task SaveUserData(Guid userId, Guid userDataId, UserItemData userData, CancellationToken cancellationToken)
public async Task SaveUserData(Guid userId, Guid userDataId, UserItemData userData, CancellationToken cancellationToken)
{
if (userData == null)
{
@ -127,8 +139,6 @@ namespace MediaBrowser.Server.Implementations.Sqlite
cancellationToken.ThrowIfCancellationRequested();
return Task.Run(() =>
{
var serialized = _protobufSerializer.SerializeToBytes(userData);
cancellationToken.ThrowIfCancellationRequested();
@ -138,8 +148,27 @@ namespace MediaBrowser.Server.Implementations.Sqlite
cmd.AddParam("@1", userDataId);
cmd.AddParam("@2", userId);
cmd.AddParam("@3", serialized);
QueueCommand(cmd);
});
using (var tran = connection.BeginTransaction())
{
try
{
cmd.Transaction = tran;
await cmd.ExecuteNonQueryAsync(cancellationToken);
tran.Commit();
}
catch (OperationCanceledException)
{
tran.Rollback();
}
catch (Exception e)
{
Logger.ErrorException("Failed to commit transaction.", e);
tran.Rollback();
}
}
}
/// <summary>

View file

@ -45,6 +45,18 @@ namespace MediaBrowser.Server.Implementations.Sqlite
/// </summary>
private readonly IApplicationPaths _appPaths;
/// <summary>
/// Gets a value indicating whether [enable delayed commands].
/// </summary>
/// <value><c>true</c> if [enable delayed commands]; otherwise, <c>false</c>.</value>
protected override bool EnableDelayedCommands
{
get
{
return false;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="SQLiteUserDataRepository" /> class.
/// </summary>
@ -97,7 +109,7 @@ namespace MediaBrowser.Server.Implementations.Sqlite
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
/// <exception cref="System.ArgumentNullException">user</exception>
public Task SaveUser(User user, CancellationToken cancellationToken)
public async Task SaveUser(User user, CancellationToken cancellationToken)
{
if (user == null)
{
@ -109,8 +121,6 @@ namespace MediaBrowser.Server.Implementations.Sqlite
throw new ArgumentNullException("cancellationToken");
}
return Task.Run(() =>
{
cancellationToken.ThrowIfCancellationRequested();
var serialized = _jsonSerializer.SerializeToBytes(user);
@ -121,8 +131,27 @@ namespace MediaBrowser.Server.Implementations.Sqlite
cmd.CommandText = "replace into users (guid, data) values (@1, @2)";
cmd.AddParam("@1", user.Id);
cmd.AddParam("@2", serialized);
QueueCommand(cmd);
});
using (var tran = connection.BeginTransaction())
{
try
{
cmd.Transaction = tran;
await cmd.ExecuteNonQueryAsync(cancellationToken);
tran.Commit();
}
catch (OperationCanceledException)
{
tran.Rollback();
}
catch (Exception e)
{
Logger.ErrorException("Failed to commit transaction.", e);
tran.Rollback();
}
}
}
/// <summary>

View file

@ -298,7 +298,7 @@ namespace MediaBrowser.ServerApplication
() => LibraryManager.AddParts(GetExports<IResolverIgnoreRule>(), GetExports<IVirtualFolderCreator>(), GetExports<IItemResolver>(), GetExports<IIntroProvider>(), GetExports<IBaseItemComparer>()),
() => ProviderManager.AddMetadataProviders(GetExports<BaseMetadataProvider>().OrderBy(e => e.Priority).ToArray())
() => ProviderManager.AddMetadataProviders(GetExports<BaseMetadataProvider>().ToArray())
);
UdpServer = new UdpServer(Logger, NetworkManager, ServerConfigurationManager);