diff --git a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs index 779f992d32..eb2b46c223 100644 --- a/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs +++ b/MediaBrowser.Common.Implementations/ScheduledTasks/Tasks/DeleteCacheFileTask.cs @@ -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 diff --git a/MediaBrowser.Controller/Sync/ISyncDataProvider.cs b/MediaBrowser.Controller/Sync/ISyncDataProvider.cs index cf698dd3c0..5a86b74d80 100644 --- a/MediaBrowser.Controller/Sync/ISyncDataProvider.cs +++ b/MediaBrowser.Controller/Sync/ISyncDataProvider.cs @@ -37,5 +37,13 @@ namespace MediaBrowser.Controller.Sync /// The identifier. /// Task<LocalItem>. Task Get(SyncTarget target, string id); + + /// + /// Gets the cached item. + /// + /// The target. + /// The identifier. + /// Task<LocalItem>. + Task GetCachedItem(SyncTarget target, string id); } } diff --git a/MediaBrowser.Server.Implementations/Sync/CloudSyncProfile.cs b/MediaBrowser.Server.Implementations/Sync/CloudSyncProfile.cs index babdf3f800..e13042538c 100644 --- a/MediaBrowser.Server.Implementations/Sync/CloudSyncProfile.cs +++ b/MediaBrowser.Server.Implementations/Sync/CloudSyncProfile.cs @@ -40,6 +40,11 @@ namespace MediaBrowser.Server.Implementations.Sync VideoCodec = "h264,mpeg4", AudioCodec = mp4Audio, Type = DlnaProfileType.Video + }, + new DirectPlayProfile + { + Container = "mp3", + Type = DlnaProfileType.Audio } }; diff --git a/MediaBrowser.Server.Implementations/Sync/MediaSync.cs b/MediaBrowser.Server.Implementations/Sync/MediaSync.cs index 246a82b203..ff298a9998 100644 --- a/MediaBrowser.Server.Implementations/Sync/MediaSync.cs +++ b/MediaBrowser.Server.Implementations/Sync/MediaSync.cs @@ -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) { diff --git a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs index 8474cc8c51..3df807e576 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs @@ -691,9 +691,8 @@ namespace MediaBrowser.Server.Implementations.Sync dtoOptions.Fields.Remove(ItemFields.SyncInfo); 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(); diff --git a/MediaBrowser.Server.Implementations/Sync/SyncedMediaSourceProvider.cs b/MediaBrowser.Server.Implementations/Sync/SyncedMediaSourceProvider.cs index 9194ff1c95..91e7a25370 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncedMediaSourceProvider.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncedMediaSourceProvider.cs @@ -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> 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(); - return new List(); + if (jobItemResult.Items.Length > 0) + { + var targets = _syncManager.ServerSyncProviders + .SelectMany(i => i.GetAllSyncTargets().Select(t => new Tuple(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; } } }