You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.4 KiB
68 lines
2.4 KiB
using MediaBrowser.Controller;
|
|
using MediaBrowser.Controller.Entities;
|
|
using MediaBrowser.Controller.Library;
|
|
using MediaBrowser.Controller.Sync;
|
|
using MediaBrowser.Model.Dto;
|
|
using MediaBrowser.Model.Sync;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MediaBrowser.Server.Implementations.Sync
|
|
{
|
|
public class SyncedMediaSourceProvider : IMediaSourceProvider
|
|
{
|
|
private readonly SyncManager _syncManager;
|
|
private readonly IServerApplicationHost _appHost;
|
|
|
|
public SyncedMediaSourceProvider(ISyncManager syncManager, IServerApplicationHost appHost)
|
|
{
|
|
_appHost = appHost;
|
|
_syncManager = (SyncManager)syncManager;
|
|
}
|
|
|
|
public async Task<IEnumerable<MediaSourceInfo>> GetMediaSources(IHasMediaSources item, CancellationToken cancellationToken)
|
|
{
|
|
var jobItemResult = _syncManager.GetJobItems(new SyncJobItemQuery
|
|
{
|
|
AddMetadata = false,
|
|
Statuses = new List<SyncJobItemStatus> { SyncJobItemStatus.Synced },
|
|
ItemId = item.Id.ToString("N")
|
|
});
|
|
|
|
var list = new List<MediaSourceInfo>();
|
|
|
|
if (jobItemResult.Items.Length > 0)
|
|
{
|
|
var targets = _syncManager.ServerSyncProviders
|
|
.SelectMany(i => i.GetAllSyncTargets().Select(t => new Tuple<IServerSyncProvider, SyncTarget>(i, t)))
|
|
.ToList();
|
|
|
|
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);
|
|
var localItemId = MediaSync.GetLocalId(_appHost.SystemId, item.Id.ToString("N"));
|
|
|
|
var localItem = await dataProvider.GetCachedItem(syncTarget, localItemId).ConfigureAwait(false);
|
|
|
|
if (localItem != null)
|
|
{
|
|
list.AddRange(localItem.Item.MediaSources);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return list;
|
|
}
|
|
}
|
|
}
|