update providers
This commit is contained in:
parent
6c0743a70d
commit
00bcbfa958
|
@ -50,12 +50,6 @@ namespace MediaBrowser.Providers.Manager
|
|||
protected Task SaveProviderResult(TItemType item, MetadataStatus result, IDirectoryService directoryService)
|
||||
{
|
||||
result.ItemId = item.Id;
|
||||
result.ItemName = item.Name;
|
||||
result.ItemType = item.GetType().Name;
|
||||
|
||||
var series = item as IHasSeries;
|
||||
|
||||
result.SeriesName = series == null ? null : series.SeriesName;
|
||||
|
||||
//var locationType = item.LocationType;
|
||||
|
||||
|
@ -99,7 +93,6 @@ namespace MediaBrowser.Providers.Manager
|
|||
|
||||
var updateType = ItemUpdateType.None;
|
||||
var refreshResult = GetLastResult(item);
|
||||
refreshResult.LastErrorMessage = string.Empty;
|
||||
|
||||
var itemImageProvider = new ItemImageProvider(Logger, ProviderManager, ServerConfigurationManager, FileSystem);
|
||||
var localImagesFailed = false;
|
||||
|
@ -119,7 +112,6 @@ namespace MediaBrowser.Providers.Manager
|
|||
{
|
||||
localImagesFailed = true;
|
||||
Logger.ErrorException("Error validating images for {0}", ex, item.Path ?? item.Name ?? "Unknown name");
|
||||
refreshResult.AddStatus(ex.Message);
|
||||
}
|
||||
|
||||
var metadataResult = new MetadataResult<TItemType>
|
||||
|
@ -150,7 +142,6 @@ namespace MediaBrowser.Providers.Manager
|
|||
var result = await RefreshWithProviders(metadataResult, id, refreshOptions, providers, itemImageProvider, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
updateType = updateType | result.UpdateType;
|
||||
refreshResult.AddStatus(result.ErrorMessage);
|
||||
if (result.Failures == 0)
|
||||
{
|
||||
refreshResult.SetDateLastMetadataRefresh(DateTime.UtcNow);
|
||||
|
@ -172,7 +163,6 @@ namespace MediaBrowser.Providers.Manager
|
|||
var result = await itemImageProvider.RefreshImages(itemOfType, providers, refreshOptions, config, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
updateType = updateType | result.UpdateType;
|
||||
refreshResult.AddStatus(result.ErrorMessage);
|
||||
if (result.Failures == 0)
|
||||
{
|
||||
refreshResult.SetDateLastImagesRefresh(DateTime.UtcNow);
|
||||
|
@ -231,17 +221,7 @@ namespace MediaBrowser.Providers.Manager
|
|||
|
||||
private DateTime GetLastRefreshDate(IHasMetadata item)
|
||||
{
|
||||
if (item.DateLastRefreshed != default(DateTime))
|
||||
{
|
||||
return item.DateLastRefreshed;
|
||||
}
|
||||
|
||||
if (ServerConfigurationManager.Configuration.EnableDateLastRefresh)
|
||||
{
|
||||
return item.DateLastRefreshed;
|
||||
}
|
||||
|
||||
if (item is BoxSet || (item is IItemByName && !(item is MusicArtist)))
|
||||
if (EnableDateLastRefreshed(item))
|
||||
{
|
||||
return item.DateLastRefreshed;
|
||||
}
|
||||
|
@ -249,6 +229,26 @@ namespace MediaBrowser.Providers.Manager
|
|||
return item.DateLastSaved;
|
||||
}
|
||||
|
||||
private bool EnableDateLastRefreshed(IHasMetadata item)
|
||||
{
|
||||
if (ServerConfigurationManager.Configuration.EnableDateLastRefresh)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (item.DateLastRefreshed != default(DateTime))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (item is BoxSet || (item is IItemByName && !(item is MusicArtist)))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected async Task SaveItem(MetadataResult<TItemType> result, ItemUpdateType reason, CancellationToken cancellationToken)
|
||||
{
|
||||
if (result.Item.SupportsPeople && result.People != null)
|
||||
|
@ -668,7 +668,14 @@ namespace MediaBrowser.Providers.Manager
|
|||
{
|
||||
try
|
||||
{
|
||||
return changeMonitor.HasChanged(item, status, directoryService);
|
||||
var hasChanged = changeMonitor.HasChanged(item, status, directoryService);
|
||||
|
||||
//if (hasChanged)
|
||||
//{
|
||||
// Logger.Debug("{0} reports change to {1}", changeMonitor.GetType().Name, item.Path ?? item.Name);
|
||||
//}
|
||||
|
||||
return hasChanged;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -681,7 +688,15 @@ namespace MediaBrowser.Providers.Manager
|
|||
{
|
||||
try
|
||||
{
|
||||
return changeMonitor.HasChanged(item, directoryService, date);
|
||||
var hasChanged = changeMonitor.HasChanged(item, directoryService, date);
|
||||
|
||||
//if (hasChanged)
|
||||
//{
|
||||
// Logger.Debug("{0} reports change to {1} since {2}", changeMonitor.GetType().Name,
|
||||
// item.Path ?? item.Name, date);
|
||||
//}
|
||||
|
||||
return hasChanged;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
@ -1765,14 +1765,6 @@ namespace MediaBrowser.Server.Implementations.Dto
|
|||
return;
|
||||
}
|
||||
|
||||
if (fields.Contains(ItemFields.OriginalPrimaryImageAspectRatio))
|
||||
{
|
||||
if (size.Width > 0 && size.Height > 0)
|
||||
{
|
||||
dto.OriginalPrimaryImageAspectRatio = size.Width / size.Height;
|
||||
}
|
||||
}
|
||||
|
||||
var supportedEnhancers = _imageProcessor.GetSupportedEnhancers(item, ImageType.Primary).ToList();
|
||||
|
||||
foreach (var enhancer in supportedEnhancers)
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
|
||||
string[] queries = {
|
||||
|
||||
"create table if not exists MetadataStatus (ItemId GUID PRIMARY KEY, ItemName TEXT, ItemType TEXT, SeriesName TEXT, DateLastMetadataRefresh datetime, DateLastImagesRefresh datetime, LastErrorMessage TEXT, ItemDateModified DateTimeNull)",
|
||||
"create table if not exists MetadataStatus (ItemId GUID PRIMARY KEY, DateLastMetadataRefresh datetime, DateLastImagesRefresh datetime, ItemDateModified DateTimeNull)",
|
||||
"create index if not exists idx_MetadataStatus on MetadataStatus(ItemId)",
|
||||
|
||||
//pragmas
|
||||
|
@ -66,12 +66,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
private static readonly string[] StatusColumns =
|
||||
{
|
||||
"ItemId",
|
||||
"ItemName",
|
||||
"ItemType",
|
||||
"SeriesName",
|
||||
"DateLastMetadataRefresh",
|
||||
"DateLastImagesRefresh",
|
||||
"LastErrorMessage",
|
||||
"ItemDateModified"
|
||||
};
|
||||
|
||||
|
@ -160,37 +156,17 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
|
||||
if (!reader.IsDBNull(1))
|
||||
{
|
||||
result.ItemName = reader.GetString(1);
|
||||
result.DateLastMetadataRefresh = reader.GetDateTime(1).ToUniversalTime();
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(2))
|
||||
{
|
||||
result.ItemName = reader.GetString(2);
|
||||
result.DateLastImagesRefresh = reader.GetDateTime(2).ToUniversalTime();
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(3))
|
||||
{
|
||||
result.SeriesName = reader.GetString(3);
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(4))
|
||||
{
|
||||
result.DateLastMetadataRefresh = reader.GetDateTime(4).ToUniversalTime();
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(5))
|
||||
{
|
||||
result.DateLastImagesRefresh = reader.GetDateTime(5).ToUniversalTime();
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(6))
|
||||
{
|
||||
result.LastErrorMessage = reader.GetString(6);
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(7))
|
||||
{
|
||||
result.ItemDateModified = reader.GetDateTime(7).ToUniversalTime();
|
||||
result.ItemDateModified = reader.GetDateTime(3).ToUniversalTime();
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -214,13 +190,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
transaction = _connection.BeginTransaction();
|
||||
|
||||
_saveStatusCommand.GetParameter(0).Value = status.ItemId;
|
||||
_saveStatusCommand.GetParameter(1).Value = status.ItemName;
|
||||
_saveStatusCommand.GetParameter(2).Value = status.ItemType;
|
||||
_saveStatusCommand.GetParameter(3).Value = status.SeriesName;
|
||||
_saveStatusCommand.GetParameter(4).Value = status.DateLastMetadataRefresh;
|
||||
_saveStatusCommand.GetParameter(5).Value = status.DateLastImagesRefresh;
|
||||
_saveStatusCommand.GetParameter(6).Value = status.LastErrorMessage;
|
||||
_saveStatusCommand.GetParameter(7).Value = status.ItemDateModified;
|
||||
_saveStatusCommand.GetParameter(1).Value = status.DateLastMetadataRefresh;
|
||||
_saveStatusCommand.GetParameter(2).Value = status.DateLastImagesRefresh;
|
||||
_saveStatusCommand.GetParameter(3).Value = status.ItemDateModified;
|
||||
|
||||
_saveStatusCommand.Transaction = transaction;
|
||||
|
||||
|
|
|
@ -144,15 +144,18 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "select data from users";
|
||||
cmd.CommandText = "select guid,data from users";
|
||||
|
||||
using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
using (var stream = reader.GetMemoryStream(0))
|
||||
var id = reader.GetGuid(0);
|
||||
|
||||
using (var stream = reader.GetMemoryStream(1))
|
||||
{
|
||||
var user = _jsonSerializer.DeserializeFromStream<User>(stream);
|
||||
user.Id = id;
|
||||
yield return user;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -285,5 +285,25 @@ namespace MediaBrowser.Server.Implementations.Photos
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task<string> CreateSingleImage(List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType)
|
||||
{
|
||||
var image = itemsWithImages
|
||||
.Where(i => i.HasImage(imageType) && i.GetImageInfo(imageType, 0).IsLocalFile && Path.HasExtension(i.GetImagePath(imageType)))
|
||||
.Select(i => i.GetImagePath(imageType))
|
||||
.FirstOrDefault();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(image))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var ext = Path.GetExtension(image);
|
||||
|
||||
var outputPath = Path.ChangeExtension(outputPathWithoutExtension, ext);
|
||||
File.Copy(image, outputPath);
|
||||
|
||||
return outputPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,24 +26,9 @@ namespace MediaBrowser.Server.Implementations.Photos
|
|||
return Task.FromResult(items);
|
||||
}
|
||||
|
||||
protected override async Task<string> CreateImage(IHasImages item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
|
||||
protected override Task<string> CreateImage(IHasImages item, List<BaseItem> itemsWithImages, string outputPathWithoutExtension, ImageType imageType, int imageIndex)
|
||||
{
|
||||
var image = itemsWithImages
|
||||
.Where(i => i.HasImage(ImageType.Primary) && i.GetImageInfo(ImageType.Primary, 0).IsLocalFile && Path.HasExtension(i.GetImagePath(ImageType.Primary)))
|
||||
.Select(i => i.GetImagePath(ImageType.Primary))
|
||||
.FirstOrDefault();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(image))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var ext = Path.GetExtension(image);
|
||||
|
||||
var outputPath = Path.ChangeExtension(outputPathWithoutExtension, ext);
|
||||
File.Copy(image, outputPath);
|
||||
|
||||
return outputPath;
|
||||
return CreateSingleImage(itemsWithImages, outputPathWithoutExtension, ImageType.Primary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
|
||||
// Do the data sync twice so the server knows what was removed from the device
|
||||
await SyncData(provider, dataProvider, serverId, target, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
|
||||
progress.Report(100);
|
||||
}
|
||||
|
||||
|
|
|
@ -640,7 +640,6 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
dtoOptions.Fields.Remove(ItemFields.MediaStreams);
|
||||
dtoOptions.Fields.Remove(ItemFields.IndexOptions);
|
||||
dtoOptions.Fields.Remove(ItemFields.MediaSourceCount);
|
||||
dtoOptions.Fields.Remove(ItemFields.OriginalPrimaryImageAspectRatio);
|
||||
dtoOptions.Fields.Remove(ItemFields.Path);
|
||||
dtoOptions.Fields.Remove(ItemFields.SeriesGenres);
|
||||
dtoOptions.Fields.Remove(ItemFields.Settings);
|
||||
|
|
|
@ -17,12 +17,9 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace MediaBrowser.Server.Implementations.Sync
|
||||
{
|
||||
public class SyncRepository : ISyncRepository, IDisposable
|
||||
public class SyncRepository : BaseSqliteRepository, ISyncRepository
|
||||
{
|
||||
private IDbConnection _connection;
|
||||
private readonly ILogger _logger;
|
||||
private readonly SemaphoreSlim _writeLock = new SemaphoreSlim(1, 1);
|
||||
private readonly IServerApplicationPaths _appPaths;
|
||||
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
||||
|
||||
private IDbCommand _insertJobCommand;
|
||||
|
@ -34,19 +31,20 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
private IDbCommand _updateJobItemCommand;
|
||||
|
||||
private readonly IJsonSerializer _json;
|
||||
private readonly IServerApplicationPaths _appPaths;
|
||||
|
||||
public SyncRepository(ILogger logger, IServerApplicationPaths appPaths, IJsonSerializer json)
|
||||
public SyncRepository(ILogManager logManager, IJsonSerializer json, IServerApplicationPaths appPaths)
|
||||
: base(logManager)
|
||||
{
|
||||
_logger = logger;
|
||||
_appPaths = appPaths;
|
||||
_json = json;
|
||||
_appPaths = appPaths;
|
||||
}
|
||||
|
||||
public async Task Initialize()
|
||||
{
|
||||
var dbFile = Path.Combine(_appPaths.DataPath, "sync14.db");
|
||||
|
||||
_connection = await SqliteExtensions.ConnectToDb(dbFile, _logger).ConfigureAwait(false);
|
||||
_connection = await SqliteExtensions.ConnectToDb(dbFile, Logger).ConfigureAwait(false);
|
||||
|
||||
string[] queries = {
|
||||
|
||||
|
@ -62,10 +60,10 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
"pragma shrink_memory"
|
||||
};
|
||||
|
||||
_connection.RunQueries(queries, _logger);
|
||||
_connection.RunQueries(queries, Logger);
|
||||
|
||||
_connection.AddColumn(_logger, "SyncJobs", "Profile", "TEXT");
|
||||
_connection.AddColumn(_logger, "SyncJobs", "Bitrate", "INT");
|
||||
_connection.AddColumn(Logger, "SyncJobs", "Profile", "TEXT");
|
||||
_connection.AddColumn(Logger, "SyncJobs", "Bitrate", "INT");
|
||||
|
||||
PrepareStatements();
|
||||
}
|
||||
|
@ -298,7 +296,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
|
||||
CheckDisposed();
|
||||
|
||||
await _writeLock.WaitAsync().ConfigureAwait(false);
|
||||
await WriteLock.WaitAsync().ConfigureAwait(false);
|
||||
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
|
@ -344,7 +342,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.ErrorException("Failed to save record:", e);
|
||||
Logger.ErrorException("Failed to save record:", e);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
|
@ -360,7 +358,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
transaction.Dispose();
|
||||
}
|
||||
|
||||
_writeLock.Release();
|
||||
WriteLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -373,7 +371,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
|
||||
CheckDisposed();
|
||||
|
||||
await _writeLock.WaitAsync().ConfigureAwait(false);
|
||||
await WriteLock.WaitAsync().ConfigureAwait(false);
|
||||
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
|
@ -405,7 +403,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.ErrorException("Failed to save record:", e);
|
||||
Logger.ErrorException("Failed to save record:", e);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
|
@ -421,7 +419,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
transaction.Dispose();
|
||||
}
|
||||
|
||||
_writeLock.Release();
|
||||
WriteLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -656,7 +654,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
|
||||
CheckDisposed();
|
||||
|
||||
await _writeLock.WaitAsync().ConfigureAwait(false);
|
||||
await WriteLock.WaitAsync().ConfigureAwait(false);
|
||||
|
||||
IDbTransaction transaction = null;
|
||||
|
||||
|
@ -699,7 +697,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.ErrorException("Failed to save record:", e);
|
||||
Logger.ErrorException("Failed to save record:", e);
|
||||
|
||||
if (transaction != null)
|
||||
{
|
||||
|
@ -715,7 +713,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
transaction.Dispose();
|
||||
}
|
||||
|
||||
_writeLock.Release();
|
||||
WriteLock.Release();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -802,15 +800,6 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
return item;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private bool _disposed;
|
||||
private void CheckDisposed()
|
||||
{
|
||||
|
@ -820,38 +809,26 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
}
|
||||
}
|
||||
|
||||
private readonly object _disposeLock = new object();
|
||||
|
||||
/// <summary>
|
||||
/// Releases unmanaged and - optionally - managed resources.
|
||||
/// </summary>
|
||||
/// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
|
||||
protected virtual void Dispose(bool dispose)
|
||||
protected override void Dispose(bool dispose)
|
||||
{
|
||||
if (dispose)
|
||||
{
|
||||
_disposed = true;
|
||||
}
|
||||
base.Dispose(dispose);
|
||||
}
|
||||
|
||||
try
|
||||
protected override void CloseConnection()
|
||||
{
|
||||
if (_connection != null)
|
||||
{
|
||||
if (_connection.IsOpen())
|
||||
{
|
||||
lock (_disposeLock)
|
||||
{
|
||||
if (_connection != null)
|
||||
{
|
||||
if (_connection.IsOpen())
|
||||
{
|
||||
_connection.Close();
|
||||
}
|
||||
_connection.Close();
|
||||
}
|
||||
|
||||
_connection.Dispose();
|
||||
_connection = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.ErrorException("Error disposing database", ex);
|
||||
}
|
||||
_connection.Dispose();
|
||||
_connection = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,9 +54,7 @@ namespace MediaBrowser.Server.Implementations.UserViews
|
|||
return new List<BaseItem>();
|
||||
}
|
||||
|
||||
if (string.Equals(view.ViewType, SpecialFolder.GameGenre, StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(view.ViewType, SpecialFolder.MusicGenre, StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(view.ViewType, SpecialFolder.MovieGenre, StringComparison.OrdinalIgnoreCase) ||
|
||||
if (string.Equals(view.ViewType, SpecialFolder.MovieGenre, StringComparison.OrdinalIgnoreCase) ||
|
||||
string.Equals(view.ViewType, SpecialFolder.TvGenre, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var userItemsResult = await view.GetItems(new InternalItemsQuery
|
||||
|
|
|
@ -680,7 +680,7 @@ namespace MediaBrowser.Server.Startup.Common
|
|||
|
||||
private async Task<ISyncRepository> GetSyncRepository()
|
||||
{
|
||||
var repo = new SyncRepository(LogManager.GetLogger("SyncRepository"), ServerConfigurationManager.ApplicationPaths, JsonSerializer);
|
||||
var repo = new SyncRepository(LogManager, JsonSerializer, ServerConfigurationManager.ApplicationPaths);
|
||||
|
||||
await repo.Initialize().ConfigureAwait(false);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user