rework image extraction settings

This commit is contained in:
Luke Pulverenti 2014-02-19 13:50:37 -05:00
parent 411ce21751
commit 4a39df98cd
20 changed files with 219 additions and 72 deletions

View File

@ -55,6 +55,13 @@ namespace MediaBrowser.Api
public bool Enabled { get; set; }
}
[Route("/System/Configuration/VideoImageExtraction", "POST")]
[Api(("Updates image extraction for all types"))]
public class UpdateVideoImageExtraction : IReturnVoid
{
public bool Enabled { get; set; }
}
public class ConfigurationService : BaseApiService
{
/// <summary>
@ -123,6 +130,20 @@ namespace MediaBrowser.Api
/// This is a temporary method used until image settings get broken out.
/// </summary>
/// <param name="request"></param>
public void Post(UpdateVideoImageExtraction request)
{
var config = _configurationManager.Configuration;
EnableImageExtractionForType(typeof(Movie), config, request.Enabled);
EnableImageExtractionForType(typeof(Episode), config, request.Enabled);
EnableImageExtractionForType(typeof(AdultVideo), config, request.Enabled);
EnableImageExtractionForType(typeof(MusicVideo), config, request.Enabled);
EnableImageExtractionForType(typeof(Video), config, request.Enabled);
EnableImageExtractionForType(typeof(Trailer), config, request.Enabled);
_configurationManager.SaveConfiguration();
}
public void Post(UpdateSaveLocalMetadata request)
{
var config = _configurationManager.Configuration;
@ -174,6 +195,32 @@ namespace MediaBrowser.Api
}
}
private void EnableImageExtractionForType(Type type, ServerConfiguration config, bool enabled)
{
var options = GetMetadataOptions(type, config);
const string imageProviderName = "Screen Grabber";
var contains = options.DisabledImageFetchers.Contains(imageProviderName, StringComparer.OrdinalIgnoreCase);
if (!enabled && !contains)
{
var list = options.DisabledImageFetchers.ToList();
list.Add(imageProviderName);
options.DisabledImageFetchers = list.ToArray();
}
else if (enabled && contains)
{
var list = options.DisabledImageFetchers.ToList();
list.Remove(imageProviderName);
options.DisabledImageFetchers = list.ToArray();
}
}
private MetadataOptions GetMetadataOptions(Type type, ServerConfiguration config)
{
var options = config.MetadataOptions

View File

@ -435,56 +435,11 @@ namespace MediaBrowser.Api
Task.WaitAll(task);
}
private async Task DeleteItem(DeleteItem request)
private Task DeleteItem(DeleteItem request)
{
var item = _dtoService.GetItemByDtoId(request.Id);
var parent = item.Parent;
var locationType = item.LocationType;
if (locationType == LocationType.FileSystem || locationType == LocationType.Offline)
{
foreach (var path in item.GetDeletePaths().ToList())
{
if (Directory.Exists(path))
{
Directory.Delete(path, true);
}
else if (File.Exists(path))
{
File.Delete(path);
}
}
if (parent != null)
{
try
{
await parent.ValidateChildren(new Progress<double>(), CancellationToken.None)
.ConfigureAwait(false);
}
catch (Exception ex)
{
Logger.ErrorException("Error refreshing item", ex);
}
}
}
else if (parent != null)
{
try
{
await parent.RemoveChild(item, CancellationToken.None).ConfigureAwait(false);
}
catch (Exception ex)
{
Logger.ErrorException("Error removing item", ex);
}
}
else
{
throw new InvalidOperationException("Don't know how to delete " + item.Name);
}
return _libraryManager.DeleteItem(item);
}
/// <summary>

View File

@ -330,5 +330,12 @@ namespace MediaBrowser.Controller.Library
/// </summary>
/// <param name="item">The item.</param>
void RegisterItem(BaseItem item);
/// <summary>
/// Deletes the item.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>Task.</returns>
Task DeleteItem(BaseItem item);
}
}

View File

@ -26,6 +26,14 @@ namespace MediaBrowser.Controller.Persistence
/// <returns>Task.</returns>
Task SaveItem(BaseItem item, CancellationToken cancellationToken);
/// <summary>
/// Deletes the item.
/// </summary>
/// <param name="id">The identifier.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task.</returns>
Task DeleteItem(Guid id, CancellationToken cancellationToken);
/// <summary>
/// Gets the critic reviews.
/// </summary>

View File

@ -166,8 +166,6 @@ namespace MediaBrowser.Model.Configuration
public bool EnableTmdbUpdates { get; set; }
public bool EnableFanArtUpdates { get; set; }
public bool EnableVideoImageExtraction { get; set; }
/// <summary>
/// Gets or sets the image saving convention.
/// </summary>
@ -218,7 +216,6 @@ namespace MediaBrowser.Model.Configuration
EnableHttpLevelLogging = true;
EnableDashboardResponseCaching = true;
EnableVideoImageExtraction = true;
EnableMovieChapterImageExtraction = true;
EnableEpisodeChapterImageExtraction = false;
EnableOtherVideoChapterImageExtraction = false;

View File

@ -1,5 +1,4 @@
using System.Linq;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
@ -14,6 +13,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

View File

@ -37,7 +37,7 @@ namespace MediaBrowser.Providers.GameGenres
public static string ProviderName
{
get { return "Media Browser Images"; }
get { return "Media Browser Designs"; }
}
public bool Supports(IHasImages item)

View File

@ -38,7 +38,7 @@ namespace MediaBrowser.Providers.Genres
public static string ProviderName
{
get { return "Media Browser Images"; }
get { return "Media Browser Designs"; }
}
public bool Supports(IHasImages item)

View File

@ -151,7 +151,7 @@ namespace MediaBrowser.Providers.MediaInfo
public string Name
{
get { return "Embedded Image"; }
get { return "Image Extractor"; }
}
public bool Supports(IHasImages item)

View File

@ -113,16 +113,11 @@ namespace MediaBrowser.Providers.MediaInfo
public string Name
{
get { return "Embedded Image"; }
get { return "Screen Grabber"; }
}
public bool Supports(IHasImages item)
{
if (!_config.Configuration.EnableVideoImageExtraction)
{
return false;
}
return item.LocationType == LocationType.FileSystem && item is Video;
}

View File

@ -431,7 +431,7 @@ namespace MediaBrowser.Providers.Movies
if (fileInfo.Exists)
{
if (_config.Configuration.EnableFanArtUpdates || (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 7)
if ((DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 7)
{
return _cachedTask;
}

View File

@ -187,7 +187,7 @@ namespace MediaBrowser.Providers.Movies
if (fileInfo.Exists)
{
// If it's recent or automatic updates are enabled, don't re-download
if ((_configurationManager.Configuration.EnableTmdbUpdates) || (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 7)
if ((DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 7)
{
return _cachedTask;
}

View File

@ -33,7 +33,7 @@ namespace MediaBrowser.Providers.Music
public string Name
{
get { return "Embedded Image"; }
get { return "Image Extractor"; }
}
public bool Supports(IHasImages item)

View File

@ -398,7 +398,7 @@ namespace MediaBrowser.Providers.Music
if (fileInfo.Exists)
{
if (_config.Configuration.EnableFanArtUpdates || (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 7)
if ((DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 7)
{
return _cachedTask;
}

View File

@ -38,7 +38,7 @@ namespace MediaBrowser.Providers.MusicGenres
public static string ProviderName
{
get { return "Media Browser Images"; }
get { return "Media Browser Designs"; }
}
public bool Supports(IHasImages item)

View File

@ -37,7 +37,7 @@ namespace MediaBrowser.Providers.Studios
public static string ProviderName
{
get { return "Media Browser Images"; }
get { return "Media Browser Designs"; }
}
public bool Supports(IHasImages item)

View File

@ -376,7 +376,7 @@ namespace MediaBrowser.Providers.TV
if (fileInfo.Exists)
{
if (_config.Configuration.EnableFanArtUpdates || (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 7)
if ((DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 7)
{
return _cachedTask;
}

View File

@ -272,7 +272,7 @@ namespace MediaBrowser.Providers.TV
if (fileInfo.Exists)
{
// If it's recent or automatic updates are enabled, don't re-download
if ((_configurationManager.Configuration.EnableTmdbUpdates) || (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 7)
if ((DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 7)
{
return _cachedTask;
}

View File

@ -408,6 +408,83 @@ namespace MediaBrowser.Server.Implementations.Library
LibraryItemsCache.AddOrUpdate(item.Id, item, delegate { return item; });
}
public async Task DeleteItem(BaseItem item)
{
var parent = item.Parent;
var locationType = item.LocationType;
var children = item.IsFolder
? ((Folder)item).RecursiveChildren.ToList()
: new List<BaseItem>();
foreach (var metadataPath in GetMetadataPaths(item, children))
{
_logger.Debug("Deleting path {0}", metadataPath);
try
{
Directory.Delete(metadataPath, true);
}
catch (DirectoryNotFoundException)
{
}
catch (Exception ex)
{
_logger.ErrorException("Error deleting {0}", ex, metadataPath);
}
}
if (locationType == LocationType.FileSystem || locationType == LocationType.Offline)
{
foreach (var path in item.GetDeletePaths().ToList())
{
if (Directory.Exists(path))
{
_logger.Debug("Deleting path {0}", path);
Directory.Delete(path, true);
}
else if (File.Exists(path))
{
_logger.Debug("Deleting path {0}", path);
File.Delete(path);
}
}
if (parent != null)
{
await parent.ValidateChildren(new Progress<double>(), CancellationToken.None)
.ConfigureAwait(false);
}
}
else if (parent != null)
{
await parent.RemoveChild(item, CancellationToken.None).ConfigureAwait(false);
}
else
{
throw new InvalidOperationException("Don't know how to delete " + item.Name);
}
foreach (var child in children)
{
await ItemRepository.DeleteItem(child.Id, CancellationToken.None).ConfigureAwait(false);
}
}
private IEnumerable<string> GetMetadataPaths(BaseItem item, IEnumerable<BaseItem> children)
{
var list = new List<string>
{
ConfigurationManager.ApplicationPaths.GetInternalMetadataPath(item.Id)
};
list.AddRange(children.Select(i => ConfigurationManager.ApplicationPaths.GetInternalMetadataPath(i.Id)));
return list;
}
/// <summary>
/// Resolves the item.
/// </summary>

View File

@ -61,6 +61,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
private IDbCommand _deleteChildrenCommand;
private IDbCommand _saveChildrenCommand;
private IDbCommand _deleteItemCommand;
/// <summary>
/// Initializes a new instance of the <see cref="SqliteItemRepository"/> class.
@ -156,6 +157,10 @@ namespace MediaBrowser.Server.Implementations.Persistence
_deleteChildrenCommand.CommandText = "delete from ChildrenIds where ParentId=@ParentId";
_deleteChildrenCommand.Parameters.Add(_deleteChildrenCommand, "@ParentId");
_deleteItemCommand = _connection.CreateCommand();
_deleteItemCommand.CommandText = "delete from TypedBaseItems where guid=@Id";
_deleteItemCommand.Parameters.Add(_deleteItemCommand, "@Id");
_saveChildrenCommand = _connection.CreateCommand();
_saveChildrenCommand.CommandText = "replace into ChildrenIds (ParentId, ItemId) values (@ParentId, @ItemId)";
_saveChildrenCommand.Parameters.Add(_saveChildrenCommand, "@ParentId");
@ -463,6 +468,64 @@ namespace MediaBrowser.Server.Implementations.Persistence
}
}
public async Task DeleteItem(Guid id, CancellationToken cancellationToken)
{
if (id == Guid.Empty)
{
throw new ArgumentNullException("id");
}
await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false);
IDbTransaction transaction = null;
try
{
transaction = _connection.BeginTransaction();
// First delete children
_deleteChildrenCommand.GetParameter(0).Value = id;
_deleteChildrenCommand.Transaction = transaction;
_deleteChildrenCommand.ExecuteNonQuery();
// Delete the item
_deleteItemCommand.GetParameter(0).Value = id;
_deleteItemCommand.Transaction = transaction;
_deleteItemCommand.ExecuteNonQuery();
transaction.Commit();
}
catch (OperationCanceledException)
{
if (transaction != null)
{
transaction.Rollback();
}
throw;
}
catch (Exception e)
{
_logger.ErrorException("Failed to save children:", e);
if (transaction != null)
{
transaction.Rollback();
}
throw;
}
finally
{
if (transaction != null)
{
transaction.Dispose();
}
_writeLock.Release();
}
}
public async Task SaveChildren(Guid parentId, IEnumerable<Guid> children, CancellationToken cancellationToken)
{
if (parentId == Guid.Empty)
@ -475,8 +538,6 @@ namespace MediaBrowser.Server.Implementations.Persistence
throw new ArgumentNullException("children");
}
cancellationToken.ThrowIfCancellationRequested();
await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false);
IDbTransaction transaction = null;