2015-03-08 05:37:48 +00:00
|
|
|
|
using MediaBrowser.Controller;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
2015-03-07 22:43:53 +00:00
|
|
|
|
using MediaBrowser.Controller.Library;
|
2015-03-07 23:39:24 +00:00
|
|
|
|
using MediaBrowser.Controller.Sync;
|
2015-03-07 22:43:53 +00:00
|
|
|
|
using MediaBrowser.Model.Dto;
|
2015-03-07 23:39:24 +00:00
|
|
|
|
using MediaBrowser.Model.Sync;
|
2015-03-08 05:37:48 +00:00
|
|
|
|
using System;
|
2015-03-07 22:43:53 +00:00
|
|
|
|
using System.Collections.Generic;
|
2015-03-07 23:39:24 +00:00
|
|
|
|
using System.Linq;
|
2015-03-07 22:43:53 +00:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Server.Implementations.Sync
|
|
|
|
|
{
|
|
|
|
|
public class SyncedMediaSourceProvider : IMediaSourceProvider
|
|
|
|
|
{
|
2015-03-08 05:37:48 +00:00
|
|
|
|
private readonly SyncManager _syncManager;
|
|
|
|
|
private readonly IServerApplicationHost _appHost;
|
2015-03-07 23:39:24 +00:00
|
|
|
|
|
2015-03-08 05:37:48 +00:00
|
|
|
|
public SyncedMediaSourceProvider(ISyncManager syncManager, IServerApplicationHost appHost)
|
2015-03-07 23:39:24 +00:00
|
|
|
|
{
|
2015-03-08 05:37:48 +00:00
|
|
|
|
_appHost = appHost;
|
|
|
|
|
_syncManager = (SyncManager)syncManager;
|
2015-03-07 23:39:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-07 22:43:53 +00:00
|
|
|
|
public async Task<IEnumerable<MediaSourceInfo>> GetMediaSources(IHasMediaSources item, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2015-03-07 23:39:24 +00:00
|
|
|
|
var jobItemResult = _syncManager.GetJobItems(new SyncJobItemQuery
|
|
|
|
|
{
|
|
|
|
|
AddMetadata = false,
|
2015-03-17 19:52:25 +00:00
|
|
|
|
Statuses = new SyncJobItemStatus[] { SyncJobItemStatus.Synced },
|
2015-03-07 23:39:24 +00:00
|
|
|
|
ItemId = item.Id.ToString("N")
|
|
|
|
|
});
|
|
|
|
|
|
2015-03-08 05:37:48 +00:00
|
|
|
|
var list = new List<MediaSourceInfo>();
|
2015-03-07 23:39:24 +00:00
|
|
|
|
|
2015-03-08 05:37:48 +00:00
|
|
|
|
if (jobItemResult.Items.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
var targets = _syncManager.ServerSyncProviders
|
|
|
|
|
.SelectMany(i => i.GetAllSyncTargets().Select(t => new Tuple<IServerSyncProvider, SyncTarget>(i, t)))
|
|
|
|
|
.ToList();
|
|
|
|
|
|
2015-03-10 18:10:38 +00:00
|
|
|
|
var serverId = _appHost.SystemId;
|
|
|
|
|
|
2015-03-08 05:37:48 +00:00
|
|
|
|
foreach (var jobItem in jobItemResult.Items)
|
|
|
|
|
{
|
|
|
|
|
var targetTuple = targets.FirstOrDefault(i => string.Equals(i.Item2.Id, jobItem.TargetId, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
|
|
|
|
|
if (targetTuple != null)
|
|
|
|
|
{
|
|
|
|
|
var syncTarget = targetTuple.Item2;
|
|
|
|
|
|
|
|
|
|
var dataProvider = _syncManager.GetDataProvider(targetTuple.Item1, syncTarget);
|
|
|
|
|
|
2015-03-10 18:10:38 +00:00
|
|
|
|
var localItems = await dataProvider.GetCachedItems(syncTarget, serverId, item.Id.ToString("N")).ConfigureAwait(false);
|
2015-03-08 05:37:48 +00:00
|
|
|
|
|
2015-03-11 02:38:31 +00:00
|
|
|
|
foreach (var localItem in localItems)
|
|
|
|
|
{
|
2015-03-13 05:29:39 +00:00
|
|
|
|
list.AddRange(localItem.Item.MediaSources);
|
2015-03-11 02:38:31 +00:00
|
|
|
|
}
|
2015-03-08 05:37:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
2015-03-07 22:43:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|