| 
					
				 | 
			
			
				@@ -1,16 +1,12 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-using MediaBrowser.Common.Extensions; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-using MediaBrowser.Common.IO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+using MediaBrowser.Common.IO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 using MediaBrowser.Controller.Configuration; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 using MediaBrowser.Controller.Entities; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-using MediaBrowser.Controller.IO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 using MediaBrowser.Controller.Library; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 using MediaBrowser.Controller.Providers; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 using MediaBrowser.Model.Logging; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 using System; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 using System.IO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 using System.Linq; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-using System.Threading; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-using System.Threading.Tasks; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 namespace MediaBrowser.Providers 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -19,22 +15,11 @@ namespace MediaBrowser.Providers 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /// </summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public class ImagesByNameProvider : ImageFromMediaLocationProvider 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        private readonly IFileSystem _fileSystem; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-         
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         public ImagesByNameProvider(ILogManager logManager, IServerConfigurationManager configurationManager, IFileSystem fileSystem) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            : base(logManager, configurationManager) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            : base(logManager, configurationManager, fileSystem) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            _fileSystem = fileSystem; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        public override ItemUpdateType ItemUpdateType 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            get 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return ItemUpdateType.ImageUpdate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-         
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// <summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// Supportses the specified item. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// </summary> 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -42,8 +27,8 @@ namespace MediaBrowser.Providers 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         public override bool Supports(BaseItem item) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            //only run for these generic types since we are expensive in file i/o 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return item is IndexFolder || item is BasePluginFolder || item is CollectionFolder; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // Only run for these generic types since we are expensive in file i/o 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return item is BasePluginFolder || item is CollectionFolder; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// <summary> 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -58,95 +43,6 @@ namespace MediaBrowser.Providers 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// <summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// Needses the refresh internal. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// </summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// <param name="item">The item.</param> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// <param name="providerInfo">The provider info.</param> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            // Force a refresh if the IBN path changed 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (providerInfo.FileStamp != ConfigurationManager.ApplicationPaths.ItemsByNamePath.GetMD5()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return base.NeedsRefreshInternal(item, providerInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// <summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// Gets a value indicating whether [refresh on file system stamp change]. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// </summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// <value><c>true</c> if [refresh on file system stamp change]; otherwise, <c>false</c>.</value> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        protected override bool RefreshOnFileSystemStampChange 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            get 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// <summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// Override this to return the date that should be compared to the last refresh date 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// to determine if this provider should be re-fetched. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// </summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// <param name="item">The item.</param> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// <returns>DateTime.</returns> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        protected override DateTime CompareDate(BaseItem item) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            // If the IBN location exists return the last modified date of any file in it 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            var location = GetLocation(item); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            var directoryInfo = new DirectoryInfo(location); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (!directoryInfo.Exists) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return DateTime.MinValue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            var files = directoryInfo.EnumerateFiles().ToList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (files.Count == 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return DateTime.MinValue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return files.Select(f => 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                var lastWriteTime = _fileSystem.GetLastWriteTimeUtc(f); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                var creationTime = _fileSystem.GetCreationTimeUtc(f); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return creationTime > lastWriteTime ? creationTime : lastWriteTime; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }).Max(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// <summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// Fetches metadata and returns true or false indicating if any work that requires persistence was done 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// </summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// <param name="item">The item.</param> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// <param name="force">if set to <c>true</c> [force].</param> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// <param name="cancellationToken">The cancellation token.</param> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        /// <returns>Task{System.Boolean}.</returns> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        public override async Task<bool> FetchAsync(BaseItem item, bool force, CancellationToken cancellationToken) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            var result = await base.FetchAsync(item, force, cancellationToken).ConfigureAwait(false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            BaseProviderInfo data; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (!item.ProviderData.TryGetValue(Id, out data)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                data = new BaseProviderInfo(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                item.ProviderData[Id] = data; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            data.FileStamp = ConfigurationManager.ApplicationPaths.ItemsByNamePath.GetMD5(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            SetLastRefreshed(item, DateTime.UtcNow); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// <summary> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// Gets the location. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// </summary> 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -154,7 +50,7 @@ namespace MediaBrowser.Providers 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /// <returns>System.String.</returns> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         protected string GetLocation(BaseItem item) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            var name = _fileSystem.GetValidFilename(item.Name); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            var name = FileSystem.GetValidFilename(item.Name); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return Path.Combine(ConfigurationManager.ApplicationPaths.GeneralPath, name); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -170,30 +66,34 @@ namespace MediaBrowser.Providers 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             var location = GetLocation(item); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            var directoryInfo = new DirectoryInfo(location); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (!directoryInfo.Exists) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            var files = directoryInfo.EnumerateFiles("*", SearchOption.TopDirectoryOnly).ToList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return GetImageFromLocation(location, filenameWithoutExtension); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            var file = files.FirstOrDefault(i => string.Equals(i.Name, filenameWithoutExtension + ".png", StringComparison.OrdinalIgnoreCase)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        protected override Guid GetFileSystemStamp(BaseItem item) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            var location = GetLocation(item); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (file != null) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            try 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return file; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                var files = new DirectoryInfo(location) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .EnumerateFiles("*", SearchOption.TopDirectoryOnly) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .Where(i => 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        var ext = i.Extension; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        return !string.IsNullOrEmpty(ext) && 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            BaseItem.SupportedImageExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    }) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .ToList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return GetFileSystemStamp(files); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            file = files.FirstOrDefault(i => string.Equals(i.Name, filenameWithoutExtension + ".jpg", StringComparison.OrdinalIgnoreCase)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (file != null) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            catch (DirectoryNotFoundException) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return file; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // User doesn't have the folder. No need to log or blow up 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return Guid.Empty; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |