sync updates
This commit is contained in:
parent
d9518be3ed
commit
4389f47fb6
|
@ -118,9 +118,23 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
|
|||
index++;
|
||||
}
|
||||
|
||||
DeleteEmptyFolders(directory);
|
||||
|
||||
progress.Report(100);
|
||||
}
|
||||
|
||||
private static void DeleteEmptyFolders(string parent)
|
||||
{
|
||||
foreach (var directory in Directory.GetDirectories(parent))
|
||||
{
|
||||
DeleteEmptyFolders(directory);
|
||||
if (!Directory.EnumerateFileSystemEntries(directory).Any())
|
||||
{
|
||||
Directory.Delete(directory, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteFile(string path)
|
||||
{
|
||||
try
|
||||
|
|
|
@ -37,5 +37,13 @@ namespace MediaBrowser.Controller.Sync
|
|||
/// <param name="id">The identifier.</param>
|
||||
/// <returns>Task<LocalItem>.</returns>
|
||||
Task<LocalItem> Get(SyncTarget target, string id);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the cached item.
|
||||
/// </summary>
|
||||
/// <param name="target">The target.</param>
|
||||
/// <param name="id">The identifier.</param>
|
||||
/// <returns>Task<LocalItem>.</returns>
|
||||
Task<LocalItem> GetCachedItem(SyncTarget target, string id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,11 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
VideoCodec = "h264,mpeg4",
|
||||
AudioCodec = mp4Audio,
|
||||
Type = DlnaProfileType.Video
|
||||
},
|
||||
new DirectPlayProfile
|
||||
{
|
||||
Container = "mp3",
|
||||
Type = DlnaProfileType.Audio
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -214,14 +214,14 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
}
|
||||
}
|
||||
|
||||
private string GetLocalId(string serverId, string itemId)
|
||||
internal static string GetLocalId(string serverId, string itemId)
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes(serverId + itemId);
|
||||
bytes = CreateMD5(bytes);
|
||||
bytes = CreateMd5(bytes);
|
||||
return BitConverter.ToString(bytes, 0, bytes.Length).Replace("-", string.Empty);
|
||||
}
|
||||
|
||||
private byte[] CreateMD5(byte[] value)
|
||||
private static byte[] CreateMd5(byte[] value)
|
||||
{
|
||||
using (var provider = MD5.Create())
|
||||
{
|
||||
|
@ -341,10 +341,6 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
{
|
||||
itemFile.Type = ItemFileType.Subtitles;
|
||||
}
|
||||
else if (!IsImageFile(file.Name))
|
||||
{
|
||||
itemFile.Type = ItemFileType.Media;
|
||||
}
|
||||
|
||||
itemFiles.Add(itemFile);
|
||||
}
|
||||
|
@ -352,14 +348,6 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
return itemFiles;
|
||||
}
|
||||
|
||||
private static readonly string[] SupportedImageExtensions = { ".png", ".jpg", ".jpeg", ".webp" };
|
||||
private bool IsImageFile(string path)
|
||||
{
|
||||
var ext = Path.GetExtension(path) ?? string.Empty;
|
||||
|
||||
return SupportedImageExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
private static readonly string[] SupportedSubtitleExtensions = { ".srt", ".vtt" };
|
||||
private bool IsSubtitleFile(string path)
|
||||
{
|
||||
|
|
|
@ -692,8 +692,7 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
|
||||
syncedItem.Item = _dtoService().GetBaseItemDto(libraryItem, dtoOptions);
|
||||
|
||||
var mediaSource = syncedItem.Item.MediaSources
|
||||
.FirstOrDefault(i => string.Equals(i.Id, jobItem.MediaSourceId));
|
||||
var mediaSource = jobItem.MediaSource;
|
||||
|
||||
syncedItem.Item.MediaSources = new List<MediaSourceInfo>();
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
using MediaBrowser.Controller.Entities;
|
||||
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;
|
||||
|
@ -12,11 +14,13 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
{
|
||||
public class SyncedMediaSourceProvider : IMediaSourceProvider
|
||||
{
|
||||
private readonly ISyncManager _syncManager;
|
||||
private readonly SyncManager _syncManager;
|
||||
private readonly IServerApplicationHost _appHost;
|
||||
|
||||
public SyncedMediaSourceProvider(ISyncManager syncManager)
|
||||
public SyncedMediaSourceProvider(ISyncManager syncManager, IServerApplicationHost appHost)
|
||||
{
|
||||
_syncManager = syncManager;
|
||||
_appHost = appHost;
|
||||
_syncManager = (SyncManager)syncManager;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<MediaSourceInfo>> GetMediaSources(IHasMediaSources item, CancellationToken cancellationToken)
|
||||
|
@ -28,11 +32,36 @@ namespace MediaBrowser.Server.Implementations.Sync
|
|||
ItemId = item.Id.ToString("N")
|
||||
});
|
||||
|
||||
var jobItems = jobItemResult
|
||||
.Items
|
||||
.Where(i => true);
|
||||
var list = new List<MediaSourceInfo>();
|
||||
|
||||
return 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user