resync media after changes

This commit is contained in:
Luke Pulverenti 2016-04-27 16:24:53 -04:00
parent d0aece61e7
commit f7128c7f8f
4 changed files with 31 additions and 2 deletions

View File

@ -102,6 +102,8 @@ namespace MediaBrowser.Model.Sync
/// <value>The index of the job item.</value> /// <value>The index of the job item.</value>
public int JobItemIndex { get; set; } public int JobItemIndex { get; set; }
public long ItemDateModifiedTicks { get; set; }
public SyncJobItem() public SyncJobItem()
{ {
AdditionalFiles = new List<ItemFileInfo>(); AdditionalFiles = new List<ItemFileInfo>();

View File

@ -632,6 +632,7 @@ namespace MediaBrowser.Server.Implementations.Sync
}, innerProgress, cancellationToken); }, innerProgress, cancellationToken);
jobItem.ItemDateModifiedTicks = item.DateModified.Ticks;
_syncManager.OnConversionComplete(jobItem); _syncManager.OnConversionComplete(jobItem);
} }
catch (OperationCanceledException) catch (OperationCanceledException)
@ -668,6 +669,7 @@ namespace MediaBrowser.Server.Implementations.Sync
throw new InvalidOperationException(string.Format("Cannot direct stream {0} protocol", mediaSource.Protocol)); throw new InvalidOperationException(string.Format("Cannot direct stream {0} protocol", mediaSource.Protocol));
} }
jobItem.ItemDateModifiedTicks = item.DateModified.Ticks;
jobItem.MediaSource = mediaSource; jobItem.MediaSource = mediaSource;
} }
@ -819,6 +821,7 @@ namespace MediaBrowser.Server.Implementations.Sync
}, innerProgress, cancellationToken); }, innerProgress, cancellationToken);
jobItem.ItemDateModifiedTicks = item.DateModified.Ticks;
_syncManager.OnConversionComplete(jobItem); _syncManager.OnConversionComplete(jobItem);
} }
catch (OperationCanceledException) catch (OperationCanceledException)
@ -855,6 +858,7 @@ namespace MediaBrowser.Server.Implementations.Sync
throw new InvalidOperationException(string.Format("Cannot direct stream {0} protocol", mediaSource.Protocol)); throw new InvalidOperationException(string.Format("Cannot direct stream {0} protocol", mediaSource.Protocol));
} }
jobItem.ItemDateModifiedTicks = item.DateModified.Ticks;
jobItem.MediaSource = mediaSource; jobItem.MediaSource = mediaSource;
} }
@ -871,6 +875,7 @@ namespace MediaBrowser.Server.Implementations.Sync
jobItem.Progress = 50; jobItem.Progress = 50;
jobItem.Status = SyncJobItemStatus.ReadyToTransfer; jobItem.Status = SyncJobItemStatus.ReadyToTransfer;
jobItem.ItemDateModifiedTicks = item.DateModified.Ticks;
await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false);
} }
@ -880,6 +885,7 @@ namespace MediaBrowser.Server.Implementations.Sync
jobItem.Progress = 50; jobItem.Progress = 50;
jobItem.Status = SyncJobItemStatus.ReadyToTransfer; jobItem.Status = SyncJobItemStatus.ReadyToTransfer;
jobItem.ItemDateModifiedTicks = item.DateModified.Ticks;
await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false); await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false);
} }

View File

@ -775,6 +775,13 @@ namespace MediaBrowser.Server.Implementations.Sync
removeFromDevice = true; removeFromDevice = true;
} }
} }
else if (libraryItem != null && libraryItem.DateModified.Ticks != jobItem.ItemDateModifiedTicks && jobItem.ItemDateModifiedTicks > 0)
{
_logger.Info("Setting status to Queued for {0} because the media has been modified since the original sync.", jobItem.ItemId);
jobItem.Status = SyncJobItemStatus.Queued;
jobItem.Progress = 0;
requiresSaving = true;
}
} }
else else
{ {
@ -881,6 +888,13 @@ namespace MediaBrowser.Server.Implementations.Sync
removeFromDevice = true; removeFromDevice = true;
} }
} }
else if (libraryItem != null && libraryItem.DateModified.Ticks != jobItem.ItemDateModifiedTicks && jobItem.ItemDateModifiedTicks > 0)
{
_logger.Info("Setting status to Queued for {0} because the media has been modified since the original sync.", jobItem.ItemId);
jobItem.Status = SyncJobItemStatus.Queued;
jobItem.Progress = 0;
requiresSaving = true;
}
} }
else else
{ {
@ -1117,7 +1131,7 @@ namespace MediaBrowser.Server.Implementations.Sync
public SyncJobOptions GetAudioOptions(SyncJobItem jobItem, SyncJob job) public SyncJobOptions GetAudioOptions(SyncJobItem jobItem, SyncJob job)
{ {
var options = GetSyncJobOptions(jobItem.TargetId, null, null); var options = GetSyncJobOptions(jobItem.TargetId, null, null);
if (job.Bitrate.HasValue) if (job.Bitrate.HasValue)
{ {
options.DeviceProfile.MaxStaticBitrate = job.Bitrate.Value; options.DeviceProfile.MaxStaticBitrate = job.Bitrate.Value;

View File

@ -50,7 +50,7 @@ namespace MediaBrowser.Server.Implementations.Sync
"create table if not exists SyncJobs (Id GUID PRIMARY KEY, TargetId TEXT NOT NULL, Name TEXT NOT NULL, Profile TEXT, Quality TEXT, Bitrate INT, Status TEXT NOT NULL, Progress FLOAT, UserId TEXT NOT NULL, ItemIds TEXT NOT NULL, Category TEXT, ParentId TEXT, UnwatchedOnly BIT, ItemLimit INT, SyncNewContent BIT, DateCreated DateTime, DateLastModified DateTime, ItemCount int)", "create table if not exists SyncJobs (Id GUID PRIMARY KEY, TargetId TEXT NOT NULL, Name TEXT NOT NULL, Profile TEXT, Quality TEXT, Bitrate INT, Status TEXT NOT NULL, Progress FLOAT, UserId TEXT NOT NULL, ItemIds TEXT NOT NULL, Category TEXT, ParentId TEXT, UnwatchedOnly BIT, ItemLimit INT, SyncNewContent BIT, DateCreated DateTime, DateLastModified DateTime, ItemCount int)",
"create index if not exists idx_SyncJobs on SyncJobs(Id)", "create index if not exists idx_SyncJobs on SyncJobs(Id)",
"create table if not exists SyncJobItems (Id GUID PRIMARY KEY, ItemId TEXT, ItemName TEXT, MediaSourceId TEXT, JobId TEXT, TemporaryPath TEXT, OutputPath TEXT, Status TEXT, TargetId TEXT, DateCreated DateTime, Progress FLOAT, AdditionalFiles TEXT, MediaSource TEXT, IsMarkedForRemoval BIT, JobItemIndex INT)", "create table if not exists SyncJobItems (Id GUID PRIMARY KEY, ItemId TEXT, ItemName TEXT, MediaSourceId TEXT, JobId TEXT, TemporaryPath TEXT, OutputPath TEXT, Status TEXT, TargetId TEXT, DateCreated DateTime, Progress FLOAT, AdditionalFiles TEXT, MediaSource TEXT, IsMarkedForRemoval BIT, JobItemIndex INT, ItemDateModifiedTicks BIGINT)",
"create index if not exists idx_SyncJobItems on SyncJobs(Id)", "create index if not exists idx_SyncJobItems on SyncJobs(Id)",
//pragmas //pragmas
@ -63,6 +63,7 @@ namespace MediaBrowser.Server.Implementations.Sync
_connection.AddColumn(Logger, "SyncJobs", "Profile", "TEXT"); _connection.AddColumn(Logger, "SyncJobs", "Profile", "TEXT");
_connection.AddColumn(Logger, "SyncJobs", "Bitrate", "INT"); _connection.AddColumn(Logger, "SyncJobs", "Bitrate", "INT");
_connection.AddColumn(Logger, "SyncJobItems", "ItemDateModifiedTicks", "BIGINT");
PrepareStatements(); PrepareStatements();
} }
@ -678,6 +679,7 @@ namespace MediaBrowser.Server.Implementations.Sync
cmd.GetParameter(index++).Value = jobItem.MediaSource == null ? null : _json.SerializeToString(jobItem.MediaSource); cmd.GetParameter(index++).Value = jobItem.MediaSource == null ? null : _json.SerializeToString(jobItem.MediaSource);
cmd.GetParameter(index++).Value = jobItem.IsMarkedForRemoval; cmd.GetParameter(index++).Value = jobItem.IsMarkedForRemoval;
cmd.GetParameter(index++).Value = jobItem.JobItemIndex; cmd.GetParameter(index++).Value = jobItem.JobItemIndex;
cmd.GetParameter(index++).Value = jobItem.ItemDateModifiedTicks;
cmd.Transaction = transaction; cmd.Transaction = transaction;
@ -782,6 +784,11 @@ namespace MediaBrowser.Server.Implementations.Sync
info.IsMarkedForRemoval = reader.GetBoolean(13); info.IsMarkedForRemoval = reader.GetBoolean(13);
info.JobItemIndex = reader.GetInt32(14); info.JobItemIndex = reader.GetInt32(14);
if (!reader.IsDBNull(15))
{
info.ItemDateModifiedTicks = reader.GetInt64(15);
}
return info; return info;
} }