don't duplicate synced items
This commit is contained in:
parent
865b3b6fbe
commit
ede3746ea7
|
@ -63,4 +63,15 @@ namespace MediaBrowser.Controller.Sync
|
|||
/// <returns>Task<SyncedFileInfo>.</returns>
|
||||
Task<SyncedFileInfo> SendFile(string path, string[] pathParts, SyncTarget target, IProgress<double> progress, CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
public interface IHasDuplicateCheck
|
||||
{
|
||||
/// <summary>
|
||||
/// Allows the duplicate job item.
|
||||
/// </summary>
|
||||
/// <param name="original">The original.</param>
|
||||
/// <param name="duplicate">The duplicate.</param>
|
||||
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
|
||||
bool AllowDuplicateJobItem(SyncJobItem original, SyncJobItem duplicate);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings.Emby
|
|||
{
|
||||
Id = info.listingID.ToString(CultureInfo.InvariantCulture),
|
||||
Name = GetStringValue(info.showName),
|
||||
EpisodeTitle = GetStringValue(info.episodeTitle),
|
||||
HomePageUrl = GetStringValue(info.webLink),
|
||||
Overview = info.description,
|
||||
IsHD = info.hd,
|
||||
|
@ -101,6 +100,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings.Emby
|
|||
program.SeriesId = info.seriesID.ToString(CultureInfo.InvariantCulture);
|
||||
program.IsSeries = true;
|
||||
program.IsRepeat = info.repeat;
|
||||
|
||||
program.EpisodeTitle = GetStringValue(info.episodeTitle);
|
||||
|
||||
if (string.Equals(program.Name, program.EpisodeTitle, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
program.EpisodeTitle = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (info.starRating > 0)
|
||||
|
|
|
@ -9,7 +9,7 @@ using System.Linq;
|
|||
|
||||
namespace MediaBrowser.Server.Implementations.Sync
|
||||
{
|
||||
public class AppSyncProvider : ISyncProvider, IHasUniqueTargetIds, IHasSyncQuality
|
||||
public class AppSyncProvider : ISyncProvider, IHasUniqueTargetIds, IHasSyncQuality, IHasDuplicateCheck
|
||||
{
|
||||
private readonly IDeviceManager _deviceManager;
|
||||
|
||||
|
@ -104,5 +104,10 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
IsConverting = isConverting
|
||||
};
|
||||
}
|
||||
|
||||
public bool AllowDuplicateJobItem(SyncJobItem original, SyncJobItem duplicate)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -466,6 +466,32 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
return;
|
||||
}
|
||||
|
||||
// See if there's already another active job item for the same target
|
||||
var existingJobItems = _syncManager.GetJobItems(new SyncJobItemQuery
|
||||
{
|
||||
AddMetadata = false,
|
||||
ItemId = jobItem.ItemId,
|
||||
TargetId = job.TargetId,
|
||||
Statuses = new[] { SyncJobItemStatus.Converting, SyncJobItemStatus.Queued, SyncJobItemStatus.ReadyToTransfer, SyncJobItemStatus.Synced, SyncJobItemStatus.Transferring }
|
||||
});
|
||||
|
||||
var duplicateJobItems = existingJobItems.Items
|
||||
.Where(i => !string.Equals(i.Id, jobItem.Id, StringComparison.OrdinalIgnoreCase))
|
||||
.ToList();
|
||||
|
||||
if (duplicateJobItems.Count > 0)
|
||||
{
|
||||
var syncProvider = _syncManager.GetSyncProvider(jobItem, job) as IHasDuplicateCheck;
|
||||
|
||||
if (!duplicateJobItems.Any(i => AllowDuplicateJobItem(syncProvider, i, jobItem)))
|
||||
{
|
||||
_logger.Debug("Cancelling sync job item because there is already another active job for the same target.");
|
||||
jobItem.Status = SyncJobItemStatus.Cancelled;
|
||||
await _syncManager.UpdateSyncJobItemInternal(jobItem).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var video = item as Video;
|
||||
if (video != null)
|
||||
{
|
||||
|
@ -488,6 +514,16 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
}
|
||||
}
|
||||
|
||||
private bool AllowDuplicateJobItem(IHasDuplicateCheck provider, SyncJobItem original, SyncJobItem duplicate)
|
||||
{
|
||||
if (provider != null)
|
||||
{
|
||||
return provider.AllowDuplicateJobItem(original, duplicate);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task Sync(SyncJobItem jobItem, SyncJob job, Video item, User user, bool enableConversion, SyncOptions syncOptions, IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
var jobOptions = _syncManager.GetVideoOptions(jobItem, job);
|
||||
|
|
|
@ -1159,6 +1159,21 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
return options;
|
||||
}
|
||||
|
||||
public ISyncProvider GetSyncProvider(SyncJobItem jobItem, SyncJob job)
|
||||
{
|
||||
foreach (var provider in _providers)
|
||||
{
|
||||
foreach (var target in GetSyncTargets(provider))
|
||||
{
|
||||
if (string.Equals(target.Id, jobItem.TargetId, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public SyncJobOptions GetVideoOptions(SyncJobItem jobItem, SyncJob job)
|
||||
{
|
||||
var options = GetSyncJobOptions(jobItem.TargetId, job.Profile, job.Quality);
|
||||
|
|
Loading…
Reference in New Issue
Block a user