mirror of
				https://github.com/jellyfin/jellyfin.git
				synced 2025-11-04 03:27:21 -05:00 
			
		
		
		
	Merge pull request #11119 from PeachesMLG/cleanup-emby-photos
Cleanup PhotoProvider.cs using new .NET 8 features
This commit is contained in:
		
						commit
						ededaa95b4
					
				@ -16,18 +16,18 @@ using TagLib.IFD;
 | 
				
			|||||||
using TagLib.IFD.Entries;
 | 
					using TagLib.IFD.Entries;
 | 
				
			||||||
using TagLib.IFD.Tags;
 | 
					using TagLib.IFD.Tags;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Emby.Photos
 | 
					namespace Emby.Photos;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// <summary>
 | 
				
			||||||
 | 
					/// Metadata provider for photos.
 | 
				
			||||||
 | 
					/// </summary>
 | 
				
			||||||
 | 
					public class PhotoProvider : ICustomMetadataProvider<Photo>, IForcedProvider, IHasItemChangeMonitor
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /// <summary>
 | 
					 | 
				
			||||||
    /// Metadata provider for photos.
 | 
					 | 
				
			||||||
    /// </summary>
 | 
					 | 
				
			||||||
    public class PhotoProvider : ICustomMetadataProvider<Photo>, IForcedProvider, IHasItemChangeMonitor
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
    private readonly ILogger<PhotoProvider> _logger;
 | 
					    private readonly ILogger<PhotoProvider> _logger;
 | 
				
			||||||
    private readonly IImageProcessor _imageProcessor;
 | 
					    private readonly IImageProcessor _imageProcessor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // These are causing taglib to hang
 | 
					    // These are causing taglib to hang
 | 
				
			||||||
        private readonly string[] _includeExtensions = new string[] { ".jpg", ".jpeg", ".png", ".tiff", ".cr2", ".webp", ".avif" };
 | 
					    private readonly string[] _includeExtensions = [".jpg", ".jpeg", ".png", ".tiff", ".cr2", ".webp", ".avif"];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// <summary>
 | 
					    /// <summary>
 | 
				
			||||||
    /// Initializes a new instance of the <see cref="PhotoProvider" /> class.
 | 
					    /// Initializes a new instance of the <see cref="PhotoProvider" /> class.
 | 
				
			||||||
@ -65,27 +65,23 @@ namespace Emby.Photos
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            try
 | 
					            try
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                    using (var file = TagLib.File.Create(item.Path))
 | 
					                using var file = TagLib.File.Create(item.Path);
 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                if (file.GetTag(TagTypes.TiffIFD) is IFDTag tag)
 | 
					                if (file.GetTag(TagTypes.TiffIFD) is IFDTag tag)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    var structure = tag.Structure;
 | 
					                    var structure = tag.Structure;
 | 
				
			||||||
                            if (structure is not null
 | 
					                    if (structure?.GetEntry(0, (ushort)IFDEntryTag.ExifIFD) is SubIFDEntry exif)
 | 
				
			||||||
                                && structure.GetEntry(0, (ushort)IFDEntryTag.ExifIFD) is SubIFDEntry exif)
 | 
					 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        var exifStructure = exif.Structure;
 | 
					                        var exifStructure = exif.Structure;
 | 
				
			||||||
                        if (exifStructure is not null)
 | 
					                        if (exifStructure is not null)
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                                    var entry = exifStructure.GetEntry(0, (ushort)ExifEntryTag.ApertureValue) as RationalIFDEntry;
 | 
					                            if (exifStructure.GetEntry(0, (ushort)ExifEntryTag.ApertureValue) is RationalIFDEntry apertureEntry)
 | 
				
			||||||
                                    if (entry is not null)
 | 
					 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
                                        item.Aperture = (double)entry.Value.Numerator / entry.Value.Denominator;
 | 
					                                item.Aperture = (double)apertureEntry.Value.Numerator / apertureEntry.Value.Denominator;
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                                    entry = exifStructure.GetEntry(0, (ushort)ExifEntryTag.ShutterSpeedValue) as RationalIFDEntry;
 | 
					                            if (exifStructure.GetEntry(0, (ushort)ExifEntryTag.ShutterSpeedValue) is RationalIFDEntry shutterSpeedEntry)
 | 
				
			||||||
                                    if (entry is not null)
 | 
					 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
                                        item.ShutterSpeed = (double)entry.Value.Numerator / entry.Value.Denominator;
 | 
					                                item.ShutterSpeed = (double)shutterSpeedEntry.Value.Numerator / shutterSpeedEntry.Value.Denominator;
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
@ -99,8 +95,7 @@ namespace Emby.Photos
 | 
				
			|||||||
                    item.Width = image.Properties.PhotoWidth;
 | 
					                    item.Width = image.Properties.PhotoWidth;
 | 
				
			||||||
                    item.Height = image.Properties.PhotoHeight;
 | 
					                    item.Height = image.Properties.PhotoHeight;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                            var rating = image.ImageTag.Rating;
 | 
					                    item.CommunityRating = image.ImageTag.Rating;
 | 
				
			||||||
                            item.CommunityRating = rating.HasValue ? rating : null;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    item.Overview = image.ImageTag.Comment;
 | 
					                    item.Overview = image.ImageTag.Comment;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -148,7 +143,6 @@ namespace Emby.Photos
 | 
				
			|||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            catch (Exception ex)
 | 
					            catch (Exception ex)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                _logger.LogError(ex, "Image Provider - Error reading image tag for {0}", item.Path);
 | 
					                _logger.LogError(ex, "Image Provider - Error reading image tag for {0}", item.Path);
 | 
				
			||||||
@ -178,5 +172,4 @@ namespace Emby.Photos
 | 
				
			|||||||
        const ItemUpdateType Result = ItemUpdateType.ImageUpdate | ItemUpdateType.MetadataImport;
 | 
					        const ItemUpdateType Result = ItemUpdateType.ImageUpdate | ItemUpdateType.MetadataImport;
 | 
				
			||||||
        return Task.FromResult(Result);
 | 
					        return Task.FromResult(Result);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user