sync updates
This commit is contained in:
parent
d8cbd64917
commit
d12bcc2d24
|
@ -393,6 +393,7 @@
|
|||
<Compile Include="Subtitles\SubtitleDownloadEventArgs.cs" />
|
||||
<Compile Include="Subtitles\SubtitleResponse.cs" />
|
||||
<Compile Include="Subtitles\SubtitleSearchRequest.cs" />
|
||||
<Compile Include="Sync\IRequiresDynamicAccess.cs" />
|
||||
<Compile Include="Sync\IServerSyncProvider.cs" />
|
||||
<Compile Include="Sync\ISyncDataProvider.cs" />
|
||||
<Compile Include="Sync\ISyncManager.cs" />
|
||||
|
|
18
MediaBrowser.Controller/Sync/IRequiresDynamicAccess.cs
Normal file
18
MediaBrowser.Controller/Sync/IRequiresDynamicAccess.cs
Normal file
|
@ -0,0 +1,18 @@
|
|||
using MediaBrowser.Model.Sync;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.Controller.Sync
|
||||
{
|
||||
public interface IRequiresDynamicAccess
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the file information.
|
||||
/// </summary>
|
||||
/// <param name="remotePath">The remote path.</param>
|
||||
/// <param name="target">The target.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task<SendFileResult>.</returns>
|
||||
Task<SendFileResult> GetFileInfo(string remotePath, SyncTarget target, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
|
@ -54,14 +54,5 @@ namespace MediaBrowser.Controller.Sync
|
|||
/// <param name="target">The target.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
string GetParentDirectoryPath(string path, SyncTarget target);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the file system entries.
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <param name="target">The target.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
/// <returns>Task<List<DeviceFileInfo>>.</returns>
|
||||
Task<List<DeviceFileInfo>> GetFileSystemEntries(string path, SyncTarget target, CancellationToken cancellationToken);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -168,6 +168,12 @@ namespace MediaBrowser.Model.Entities
|
|||
/// <value>The filename.</value>
|
||||
public string Path { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the external identifier.
|
||||
/// </summary>
|
||||
/// <value>The external identifier.</value>
|
||||
public string ExternalId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the pixel format.
|
||||
/// </summary>
|
||||
|
|
|
@ -35,9 +35,15 @@ namespace MediaBrowser.Model.Sync
|
|||
/// </summary>
|
||||
/// <value>The user ids with access.</value>
|
||||
public List<string> UserIdsWithAccess { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the additional files.
|
||||
/// </summary>
|
||||
/// <value>The additional files.</value>
|
||||
public List<string> AdditionalFiles { get; set; }
|
||||
|
||||
public LocalItem()
|
||||
{
|
||||
AdditionalFiles = new List<string>();
|
||||
UserIdsWithAccess = new List<string>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -215,6 +215,13 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
var remotePath = GetRemoteSubtitlePath(localItem, mediaStream, provider, target);
|
||||
var sendFileResult = await SendFile(provider, mediaStream.Path, remotePath, target, new Progress<double>(), cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// This is the path that will be used when talking to the provider
|
||||
mediaStream.ExternalId = remotePath;
|
||||
|
||||
// Keep track of all additional files for cleanup later.
|
||||
localItem.AdditionalFiles.Add(remotePath);
|
||||
|
||||
// This is the public path clients will use
|
||||
mediaStream.Path = sendFileResult.Path;
|
||||
requiresSave = true;
|
||||
}
|
||||
|
@ -280,13 +287,14 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
|
||||
foreach (var localItem in localItems)
|
||||
{
|
||||
var files = await GetFiles(provider, localItem, target, cancellationToken);
|
||||
var files = localItem.AdditionalFiles.ToList();
|
||||
files.Insert(0, localItem.LocalPath);
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
_logger.Debug("Removing {0} from {1}.", file.Path, target.Name);
|
||||
_logger.Debug("Removing {0} from {1}.", file, target.Name);
|
||||
|
||||
await provider.DeleteFile(file.Path, target, cancellationToken).ConfigureAwait(false);
|
||||
await provider.DeleteFile(file, target, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await dataProvider.Delete(target, localItem.Id).ConfigureAwait(false);
|
||||
|
@ -417,43 +425,5 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
// We can always add this method to the sync provider if it's really needed
|
||||
return _fileSystem.GetValidFilename(filename);
|
||||
}
|
||||
|
||||
private async Task<List<ItemFileInfo>> GetFiles(IServerSyncProvider provider, LocalItem item, SyncTarget target, CancellationToken cancellationToken)
|
||||
{
|
||||
var path = item.LocalPath;
|
||||
path = provider.GetParentDirectoryPath(path, target);
|
||||
|
||||
var list = await provider.GetFileSystemEntries(path, target, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var itemFiles = new List<ItemFileInfo>();
|
||||
|
||||
var name = Path.GetFileNameWithoutExtension(item.LocalPath);
|
||||
|
||||
foreach (var file in list.Where(f => f.Name.IndexOf(name, StringComparison.OrdinalIgnoreCase) != -1))
|
||||
{
|
||||
var itemFile = new ItemFileInfo
|
||||
{
|
||||
Path = file.Path,
|
||||
Name = file.Name
|
||||
};
|
||||
|
||||
if (IsSubtitleFile(file.Name))
|
||||
{
|
||||
itemFile.Type = ItemFileType.Subtitles;
|
||||
}
|
||||
|
||||
itemFiles.Add(itemFile);
|
||||
}
|
||||
|
||||
return itemFiles;
|
||||
}
|
||||
|
||||
private static readonly string[] SupportedSubtitleExtensions = { ".srt", ".vtt" };
|
||||
private bool IsSubtitleFile(string path)
|
||||
{
|
||||
var ext = Path.GetExtension(path) ?? string.Empty;
|
||||
|
||||
return SupportedSubtitleExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>MediaBrowser.Common.Internal</id>
|
||||
<version>3.0.600</version>
|
||||
<version>3.0.602</version>
|
||||
<title>MediaBrowser.Common.Internal</title>
|
||||
<authors>Luke</authors>
|
||||
<owners>ebr,Luke,scottisafool</owners>
|
||||
|
@ -12,7 +12,7 @@
|
|||
<description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description>
|
||||
<copyright>Copyright © Media Browser 2013</copyright>
|
||||
<dependencies>
|
||||
<dependency id="MediaBrowser.Common" version="3.0.600" />
|
||||
<dependency id="MediaBrowser.Common" version="3.0.602" />
|
||||
<dependency id="NLog" version="3.2.0.0" />
|
||||
<dependency id="SimpleInjector" version="2.7.0" />
|
||||
</dependencies>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>MediaBrowser.Common</id>
|
||||
<version>3.0.600</version>
|
||||
<version>3.0.602</version>
|
||||
<title>MediaBrowser.Common</title>
|
||||
<authors>Media Browser Team</authors>
|
||||
<owners>ebr,Luke,scottisafool</owners>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>MediaBrowser.Model.Signed</id>
|
||||
<version>3.0.600</version>
|
||||
<version>3.0.602</version>
|
||||
<title>MediaBrowser.Model - Signed Edition</title>
|
||||
<authors>Media Browser Team</authors>
|
||||
<owners>ebr,Luke,scottisafool</owners>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>MediaBrowser.Server.Core</id>
|
||||
<version>3.0.600</version>
|
||||
<version>3.0.602</version>
|
||||
<title>Media Browser.Server.Core</title>
|
||||
<authors>Media Browser Team</authors>
|
||||
<owners>ebr,Luke,scottisafool</owners>
|
||||
|
@ -12,7 +12,7 @@
|
|||
<description>Contains core components required to build plugins for Media Browser Server.</description>
|
||||
<copyright>Copyright © Media Browser 2013</copyright>
|
||||
<dependencies>
|
||||
<dependency id="MediaBrowser.Common" version="3.0.600" />
|
||||
<dependency id="MediaBrowser.Common" version="3.0.602" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
|
|
Loading…
Reference in New Issue
Block a user