Cleanup PhotoProvider.cs using new .NET 8 features

pull/11119/head
Peaches_MLG 3 months ago
parent a597f1e410
commit de750ac8a2

@ -16,8 +16,8 @@ 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> /// <summary>
/// Metadata provider for photos. /// Metadata provider for photos.
/// </summary> /// </summary>
@ -27,7 +27,7 @@ namespace Emby.Photos
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);
@ -179,4 +173,3 @@ namespace Emby.Photos
return Task.FromResult(Result); return Task.FromResult(Result);
} }
} }
}

Loading…
Cancel
Save