mirror of
				https://github.com/jellyfin/jellyfin.git
				synced 2025-10-26 08:12:42 -04:00 
			
		
		
		
	update dynamic images
This commit is contained in:
		
							parent
							
								
									9bfb2f0813
								
							
						
					
					
						commit
						8ea02ee020
					
				| @ -38,7 +38,7 @@ namespace MediaBrowser.LocalMetadata.Images | |||||||
|         { |         { | ||||||
|             var collectionFolder = (CollectionFolder)item; |             var collectionFolder = (CollectionFolder)item; | ||||||
| 
 | 
 | ||||||
|             return new LocalImageProvider(_fileSystem).GetImages(item, collectionFolder.PhysicalLocations, false, directoryService); |             return new LocalImageProvider(_fileSystem).GetImages(item, collectionFolder.PhysicalLocations, directoryService); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -46,7 +46,7 @@ namespace MediaBrowser.LocalMetadata.Images | |||||||
| 
 | 
 | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
|                 return new LocalImageProvider(_fileSystem).GetImages(item, path, false, directoryService); |                 return new LocalImageProvider(_fileSystem).GetImages(item, path, directoryService); | ||||||
|             } |             } | ||||||
|             catch (DirectoryNotFoundException) |             catch (DirectoryNotFoundException) | ||||||
|             { |             { | ||||||
|  | |||||||
| @ -66,7 +66,7 @@ namespace MediaBrowser.LocalMetadata.Images | |||||||
| 
 | 
 | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
|                 return new LocalImageProvider(_fileSystem).GetImages(item, path, true, directoryService); |                 return new LocalImageProvider(_fileSystem).GetImages(item, path, directoryService); | ||||||
|             } |             } | ||||||
|             catch (DirectoryNotFoundException) |             catch (DirectoryNotFoundException) | ||||||
|             { |             { | ||||||
|  | |||||||
| @ -1,5 +1,4 @@ | |||||||
| using MediaBrowser.Common.IO; | using MediaBrowser.Controller.Entities; | ||||||
| using MediaBrowser.Controller.Entities; |  | ||||||
| using MediaBrowser.Controller.Entities.Audio; | using MediaBrowser.Controller.Entities.Audio; | ||||||
| using MediaBrowser.Controller.Entities.TV; | using MediaBrowser.Controller.Entities.TV; | ||||||
| using MediaBrowser.Controller.Providers; | using MediaBrowser.Controller.Providers; | ||||||
| @ -97,12 +96,12 @@ namespace MediaBrowser.LocalMetadata.Images | |||||||
|             return list; |             return list; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public List<LocalImageInfo> GetImages(IHasImages item, string path, bool checkForCacheKeyFiles, IDirectoryService directoryService) |         public List<LocalImageInfo> GetImages(IHasImages item, string path, IDirectoryService directoryService) | ||||||
|         { |         { | ||||||
|             return GetImages(item, new[] { path }, checkForCacheKeyFiles, directoryService); |             return GetImages(item, new[] { path }, directoryService); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public List<LocalImageInfo> GetImages(IHasImages item, IEnumerable<string> paths, bool checkForCacheKeyFiles, IDirectoryService directoryService) |         public List<LocalImageInfo> GetImages(IHasImages item, IEnumerable<string> paths, IDirectoryService directoryService) | ||||||
|         { |         { | ||||||
|             var files = paths.SelectMany(directoryService.GetFiles) |             var files = paths.SelectMany(directoryService.GetFiles) | ||||||
|                 .Where(i => |                 .Where(i => | ||||||
| @ -119,12 +118,6 @@ namespace MediaBrowser.LocalMetadata.Images | |||||||
| 
 | 
 | ||||||
|             PopulateImages(item, list, files, false, directoryService); |             PopulateImages(item, list, files, false, directoryService); | ||||||
| 
 | 
 | ||||||
|             if (checkForCacheKeyFiles) |  | ||||||
|             { |  | ||||||
|                 AddCacheKeyImage(files, list, ImageType.Primary); |  | ||||||
|                 AddCacheKeyImage(files, list, ImageType.Thumb); |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             return list; |             return list; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| @ -383,26 +376,6 @@ namespace MediaBrowser.LocalMetadata.Images | |||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void AddCacheKeyImage(IEnumerable<FileSystemMetadata> files, List<LocalImageInfo> images, ImageType type) |  | ||||||
|         { |  | ||||||
|             var candidates = files |  | ||||||
|                 .Where(i => _fileSystem.GetFileNameWithoutExtension(i).StartsWith(type.ToString() + "_key_", StringComparison.OrdinalIgnoreCase)) |  | ||||||
|                 .ToList(); |  | ||||||
| 
 |  | ||||||
|             var image = BaseItem.SupportedImageExtensions |  | ||||||
|                 .Select(i => candidates.FirstOrDefault(c => string.Equals(c.Extension, i, StringComparison.OrdinalIgnoreCase))) |  | ||||||
|                 .FirstOrDefault(i => i != null); |  | ||||||
| 
 |  | ||||||
|             if (image != null) |  | ||||||
|             { |  | ||||||
|                 images.Add(new LocalImageInfo |  | ||||||
|                 { |  | ||||||
|                     FileInfo = image, |  | ||||||
|                     Type = type |  | ||||||
|                 }); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         private FileSystemMetadata GetImage(IEnumerable<FileSystemMetadata> files, string name) |         private FileSystemMetadata GetImage(IEnumerable<FileSystemMetadata> files, string name) | ||||||
|         { |         { | ||||||
|             return files.FirstOrDefault(i => ((i.Attributes & FileAttributes.Directory) != FileAttributes.Directory) && string.Equals(name, _fileSystem.GetFileNameWithoutExtension(i), StringComparison.OrdinalIgnoreCase)); |             return files.FirstOrDefault(i => ((i.Attributes & FileAttributes.Directory) != FileAttributes.Directory) && string.Equals(name, _fileSystem.GetFileNameWithoutExtension(i), StringComparison.OrdinalIgnoreCase)); | ||||||
|  | |||||||
| @ -119,13 +119,9 @@ namespace MediaBrowser.Providers.Manager | |||||||
| 
 | 
 | ||||||
|             var index = imageIndex ?? 0; |             var index = imageIndex ?? 0; | ||||||
| 
 | 
 | ||||||
|             var paths = !string.IsNullOrEmpty(internalCacheKey) ? |             var paths = GetSavePaths(item, type, imageIndex, mimeType, saveLocally); | ||||||
|                 new[] { GetCacheKeyPath(item, type, mimeType, internalCacheKey) } : |  | ||||||
|                 GetSavePaths(item, type, imageIndex, mimeType, saveLocally); |  | ||||||
| 
 | 
 | ||||||
|             var retryPaths = !string.IsNullOrEmpty(internalCacheKey) ? |             var retryPaths = GetSavePaths(item, type, imageIndex, mimeType, false); | ||||||
|                 new[] { GetCacheKeyPath(item, type, mimeType, internalCacheKey) } : |  | ||||||
|                 GetSavePaths(item, type, imageIndex, mimeType, false); |  | ||||||
| 
 | 
 | ||||||
|             // If there are more than one output paths, the stream will need to be seekable |             // If there are more than one output paths, the stream will need to be seekable | ||||||
|             var memoryStream = new MemoryStream(); |             var memoryStream = new MemoryStream(); | ||||||
| @ -213,12 +209,6 @@ namespace MediaBrowser.Providers.Manager | |||||||
|             await SaveImageToLocation(source, retryPath, cancellationToken).ConfigureAwait(false); |             await SaveImageToLocation(source, retryPath, cancellationToken).ConfigureAwait(false); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private string GetCacheKeyPath(IHasImages item, ImageType type, string mimeType, string key) |  | ||||||
|         { |  | ||||||
|             var extension = MimeTypes.ToExtension(mimeType); |  | ||||||
|             return Path.Combine(item.GetInternalMetadataPath(), type.ToString().ToLower() + "_key_" + key + extension); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// Saves the image to location. |         /// Saves the image to location. | ||||||
|         /// </summary> |         /// </summary> | ||||||
|  | |||||||
| @ -76,20 +76,13 @@ namespace MediaBrowser.Server.Implementations.Photos | |||||||
|         protected async Task<ItemUpdateType> FetchAsync(IHasImages item, ImageType imageType, MetadataRefreshOptions options, CancellationToken cancellationToken) |         protected async Task<ItemUpdateType> FetchAsync(IHasImages item, ImageType imageType, MetadataRefreshOptions options, CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var items = await GetItemsWithImages(item).ConfigureAwait(false); |             var items = await GetItemsWithImages(item).ConfigureAwait(false); | ||||||
|             var cacheKey = GetConfigurationCacheKey(items, item.Name); |  | ||||||
| 
 | 
 | ||||||
|             if (!HasChanged(item, imageType, cacheKey)) |             return await FetchToFileInternal(item, items, imageType, cancellationToken).ConfigureAwait(false); | ||||||
|             { |  | ||||||
|                 return ItemUpdateType.None; |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             return await FetchToFileInternal(item, items, imageType, cacheKey, cancellationToken).ConfigureAwait(false); |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         protected async Task<ItemUpdateType> FetchToFileInternal(IHasImages item, |         protected async Task<ItemUpdateType> FetchToFileInternal(IHasImages item, | ||||||
|             List<BaseItem> itemsWithImages, |             List<BaseItem> itemsWithImages, | ||||||
|             ImageType imageType, |             ImageType imageType, | ||||||
|             string cacheKey, |  | ||||||
|             CancellationToken cancellationToken) |             CancellationToken cancellationToken) | ||||||
|         { |         { | ||||||
|             var outputPathWithoutExtension = Path.Combine(ApplicationPaths.TempDirectory, Guid.NewGuid().ToString("N")); |             var outputPathWithoutExtension = Path.Combine(ApplicationPaths.TempDirectory, Guid.NewGuid().ToString("N")); | ||||||
| @ -101,22 +94,13 @@ namespace MediaBrowser.Server.Implementations.Photos | |||||||
|                 return ItemUpdateType.None; |                 return ItemUpdateType.None; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             await ProviderManager.SaveImage(item, outputPath, "image/png", imageType, null, cacheKey, cancellationToken).ConfigureAwait(false); |             await ProviderManager.SaveImage(item, outputPath, "image/png", imageType, null, Guid.NewGuid().ToString("N"), cancellationToken).ConfigureAwait(false); | ||||||
| 
 | 
 | ||||||
|             return ItemUpdateType.ImageUpdate; |             return ItemUpdateType.ImageUpdate; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         protected abstract Task<List<BaseItem>> GetItemsWithImages(IHasImages item); |         protected abstract Task<List<BaseItem>> GetItemsWithImages(IHasImages item); | ||||||
| 
 | 
 | ||||||
|         private const string Version = "32"; |  | ||||||
|         protected string GetConfigurationCacheKey(List<BaseItem> items, string itemName) |  | ||||||
|         { |  | ||||||
|             var parts = Version + "_" + (itemName ?? string.Empty) + "_" + |  | ||||||
|                         string.Join(",", items.Select(i => i.Id.ToString("N")).ToArray()); |  | ||||||
| 
 |  | ||||||
|             return parts.GetMD5().ToString("N"); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         protected Task<string> CreateThumbCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath) |         protected Task<string> CreateThumbCollage(IHasImages primaryItem, List<BaseItem> items, string outputPath) | ||||||
|         { |         { | ||||||
|             return CreateCollage(primaryItem, items, outputPath, 640, 360); |             return CreateCollage(primaryItem, items, outputPath, 640, 360); | ||||||
| @ -224,7 +208,10 @@ namespace MediaBrowser.Server.Implementations.Photos | |||||||
|             throw new ArgumentException("Unexpected image type"); |             throw new ArgumentException("Unexpected image type"); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private const int MaxImageAgeDays = 7; |         protected virtual int MaxImageAgeDays | ||||||
|  |         { | ||||||
|  |             get { return 7; } | ||||||
|  |         } | ||||||
| 
 | 
 | ||||||
|         public bool HasChanged(IHasMetadata item, IDirectoryService directoryService, DateTime date) |         public bool HasChanged(IHasMetadata item, IDirectoryService directoryService, DateTime date) | ||||||
|         { |         { | ||||||
| @ -235,8 +222,6 @@ namespace MediaBrowser.Server.Implementations.Photos | |||||||
| 
 | 
 | ||||||
|             var supportedImages = GetSupportedImages(item).ToList(); |             var supportedImages = GetSupportedImages(item).ToList(); | ||||||
| 
 | 
 | ||||||
|             if (item is UserView || item is ICollectionFolder) |  | ||||||
|             { |  | ||||||
|             if (supportedImages.Contains(ImageType.Primary) && HasChanged(item, ImageType.Primary)) |             if (supportedImages.Contains(ImageType.Primary) && HasChanged(item, ImageType.Primary)) | ||||||
|             { |             { | ||||||
|                 return true; |                 return true; | ||||||
| @ -249,47 +234,6 @@ namespace MediaBrowser.Server.Implementations.Photos | |||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|             var items = GetItemsWithImages(item).Result; |  | ||||||
|             var cacheKey = GetConfigurationCacheKey(items, item.Name); |  | ||||||
| 
 |  | ||||||
|             if (supportedImages.Contains(ImageType.Primary) && HasChanged(item, ImageType.Primary, cacheKey)) |  | ||||||
|             { |  | ||||||
|                 return true; |  | ||||||
|             } |  | ||||||
|             if (supportedImages.Contains(ImageType.Thumb) && HasChanged(item, ImageType.Thumb, cacheKey)) |  | ||||||
|             { |  | ||||||
|                 return true; |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             return false; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         protected bool HasChanged(IHasImages item, ImageType type, string cacheKey) |  | ||||||
|         { |  | ||||||
|             var image = item.GetImageInfo(type, 0); |  | ||||||
| 
 |  | ||||||
|             if (image != null) |  | ||||||
|             { |  | ||||||
|                 if (!image.IsLocalFile) |  | ||||||
|                 { |  | ||||||
|                     return false; |  | ||||||
|                 } |  | ||||||
| 
 |  | ||||||
|                 if (!FileSystem.ContainsSubPath(item.GetInternalMetadataPath(), image.Path)) |  | ||||||
|                 { |  | ||||||
|                     return false; |  | ||||||
|                 } |  | ||||||
| 
 |  | ||||||
|                 var currentPathCacheKey = (Path.GetFileNameWithoutExtension(image.Path) ?? string.Empty).Split('_').LastOrDefault(); |  | ||||||
|                 if (string.Equals(cacheKey, currentPathCacheKey, StringComparison.OrdinalIgnoreCase)) |  | ||||||
|                 { |  | ||||||
|                     return false; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             return true; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         protected bool HasChanged(IHasImages item, ImageType type) |         protected bool HasChanged(IHasImages item, ImageType type) | ||||||
|         { |         { | ||||||
|             var image = item.GetImageInfo(type, 0); |             var image = item.GetImageInfo(type, 0); | ||||||
|  | |||||||
| @ -21,7 +21,7 @@ namespace MediaBrowser.Server.Implementations.Photos | |||||||
|         protected override Task<List<BaseItem>> GetItemsWithImages(IHasImages item) |         protected override Task<List<BaseItem>> GetItemsWithImages(IHasImages item) | ||||||
|         { |         { | ||||||
|             var photoAlbum = (PhotoAlbum)item; |             var photoAlbum = (PhotoAlbum)item; | ||||||
|             var items = GetFinalItems(photoAlbum.Children.ToList(), 1); |             var items = GetFinalItems(photoAlbum.Children.ToList()); | ||||||
| 
 | 
 | ||||||
|             return Task.FromResult(items); |             return Task.FromResult(items); | ||||||
|         } |         } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user