@ -3,6 +3,7 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library ;
using MediaBrowser.Controller.Sync ;
using MediaBrowser.Model.Dto ;
using MediaBrowser.Model.Logging ;
using MediaBrowser.Model.Sync ;
using System ;
using System.Collections.Generic ;
@ -16,10 +17,12 @@ namespace MediaBrowser.Server.Implementations.Sync
{
private readonly SyncManager _syncManager ;
private readonly IServerApplicationHost _appHost ;
private readonly ILogger _logger ;
public SyncedMediaSourceProvider ( ISyncManager syncManager , IServerApplicationHost appHost )
public SyncedMediaSourceProvider ( ISyncManager syncManager , IServerApplicationHost appHost , ILogger logger )
{
_appHost = appHost ;
_logger = logger ;
_syncManager = ( SyncManager ) syncManager ;
}
@ -28,7 +31,7 @@ namespace MediaBrowser.Server.Implementations.Sync
var jobItemResult = _syncManager . GetJobItems ( new SyncJobItemQuery
{
AddMetadata = false ,
Statuses = new SyncJobItemStatus [ ] { SyncJobItemStatus . Synced } ,
Statuses = new [ ] { SyncJobItemStatus . Synced } ,
ItemId = item . Id . ToString ( "N" )
} ) ;
@ -49,14 +52,17 @@ namespace MediaBrowser.Server.Implementations.Sync
if ( targetTuple ! = null )
{
var syncTarget = targetTuple . Item2 ;
var syncProvider = targetTuple . Item1 ;
var dataProvider = _syncManager . GetDataProvider ( targetTuple . Item1 , syncTarget ) ;
var localItems = await dataProvider . GetCachedItems ( syncTarget , serverId , item . Id . ToString ( "N" ) ) . ConfigureAwait ( false ) ;
foreach ( var localItem in localItems )
{
list . AddRange ( localItem . Item . MediaSources ) ;
foreach ( var mediaSource in localItem . Item . MediaSources )
{
await TryAddMediaSource ( list , localItem , mediaSource , syncProvider , syncTarget , cancellationToken ) . ConfigureAwait ( false ) ;
}
}
}
}
@ -64,5 +70,42 @@ namespace MediaBrowser.Server.Implementations.Sync
return list ;
}
private async Task TryAddMediaSource ( List < MediaSourceInfo > list ,
LocalItem item ,
MediaSourceInfo mediaSource ,
IServerSyncProvider provider ,
SyncTarget target ,
CancellationToken cancellationToken )
{
var requiresDynamicAccess = provider as IRequiresDynamicAccess ;
if ( requiresDynamicAccess = = null )
{
list . Add ( mediaSource ) ;
return ;
}
try
{
var dynamicInfo = await requiresDynamicAccess . GetFileInfo ( item . LocalPath , target , cancellationToken ) . ConfigureAwait ( false ) ;
foreach ( var stream in mediaSource . MediaStreams )
{
var dynamicStreamInfo = await requiresDynamicAccess . GetFileInfo ( stream . ExternalId , target , cancellationToken ) . ConfigureAwait ( false ) ;
stream . Path = dynamicStreamInfo . Path ;
}
mediaSource . Path = dynamicInfo . Path ;
mediaSource . Protocol = dynamicInfo . Protocol ;
list . Add ( mediaSource ) ;
}
catch ( Exception ex )
{
_logger . ErrorException ( "Error getting dynamic media source info" , ex ) ;
}
}
}
}