diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-09-14 13:39:35 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2015-09-14 13:39:35 -0400 |
| commit | 11d7585aa3bf14ec4d02026d5b494ec6837fffaa (patch) | |
| tree | a2ec6f6956d768df743277611de59cac533df319 /MediaBrowser.Providers/Photos | |
| parent | 960d45587db34acf29517f6900223ba31f6b864c (diff) | |
use taglibsharp to read image sizes
Diffstat (limited to 'MediaBrowser.Providers/Photos')
| -rw-r--r-- | MediaBrowser.Providers/Photos/PhotoProvider.cs | 159 |
1 files changed, 80 insertions, 79 deletions
diff --git a/MediaBrowser.Providers/Photos/PhotoProvider.cs b/MediaBrowser.Providers/Photos/PhotoProvider.cs index b635d4ead..ef3144958 100644 --- a/MediaBrowser.Providers/Photos/PhotoProvider.cs +++ b/MediaBrowser.Providers/Photos/PhotoProvider.cs @@ -31,110 +31,111 @@ namespace MediaBrowser.Providers.Photos try { - var file = File.Create(item.Path); - - var image = file as TagLib.Image.File; - - var tag = file.GetTag(TagTypes.TiffIFD) as IFDTag; - - if (tag != null) + using (var file = TagLib.File.Create(item.Path)) { - var structure = tag.Structure; + var image = file as TagLib.Image.File; - if (structure != null) + var tag = file.GetTag(TagTypes.TiffIFD) as IFDTag; + + if (tag != null) { - var exif = structure.GetEntry(0, (ushort)IFDEntryTag.ExifIFD) as SubIFDEntry; + var structure = tag.Structure; - if (exif != null) + if (structure != null) { - var exifStructure = exif.Structure; + var exif = structure.GetEntry(0, (ushort)IFDEntryTag.ExifIFD) as SubIFDEntry; - if (exifStructure != null) + if (exif != null) { - var entry = exifStructure.GetEntry(0, (ushort)ExifEntryTag.ApertureValue) as RationalIFDEntry; + var exifStructure = exif.Structure; - if (entry != null) + if (exifStructure != null) { - double val = entry.Value.Numerator; - val /= entry.Value.Denominator; - item.Aperture = val; - } - - entry = exifStructure.GetEntry(0, (ushort)ExifEntryTag.ShutterSpeedValue) as RationalIFDEntry; - - if (entry != null) - { - double val = entry.Value.Numerator; - val /= entry.Value.Denominator; - item.ShutterSpeed = val; + var entry = exifStructure.GetEntry(0, (ushort)ExifEntryTag.ApertureValue) as RationalIFDEntry; + + if (entry != null) + { + double val = entry.Value.Numerator; + val /= entry.Value.Denominator; + item.Aperture = val; + } + + entry = exifStructure.GetEntry(0, (ushort)ExifEntryTag.ShutterSpeedValue) as RationalIFDEntry; + + if (entry != null) + { + double val = entry.Value.Numerator; + val /= entry.Value.Denominator; + item.ShutterSpeed = val; + } } } } } - } - - item.CameraMake = image.ImageTag.Make; - item.CameraModel = image.ImageTag.Model; - item.Width = image.Properties.PhotoWidth; - item.Height = image.Properties.PhotoHeight; + item.CameraMake = image.ImageTag.Make; + item.CameraModel = image.ImageTag.Model; - var rating = image.ImageTag.Rating; - if (rating.HasValue) - { - item.CommunityRating = rating; - } - else - { - item.CommunityRating = null; - } + item.Width = image.Properties.PhotoWidth; + item.Height = image.Properties.PhotoHeight; - item.Overview = image.ImageTag.Comment; + var rating = image.ImageTag.Rating; + if (rating.HasValue) + { + item.CommunityRating = rating; + } + else + { + item.CommunityRating = null; + } - if (!string.IsNullOrWhiteSpace(image.ImageTag.Title)) - { - item.Name = image.ImageTag.Title; - } + item.Overview = image.ImageTag.Comment; - var dateTaken = image.ImageTag.DateTime; - if (dateTaken.HasValue) - { - item.DateCreated = dateTaken.Value; - item.PremiereDate = dateTaken.Value; - item.ProductionYear = dateTaken.Value.Year; - } + if (!string.IsNullOrWhiteSpace(image.ImageTag.Title)) + { + item.Name = image.ImageTag.Title; + } - item.Genres = image.ImageTag.Genres.ToList(); - item.Tags = image.ImageTag.Keywords.ToList(); - item.Software = image.ImageTag.Software; + var dateTaken = image.ImageTag.DateTime; + if (dateTaken.HasValue) + { + item.DateCreated = dateTaken.Value; + item.PremiereDate = dateTaken.Value; + item.ProductionYear = dateTaken.Value.Year; + } - if (image.ImageTag.Orientation == TagLib.Image.ImageOrientation.None) - { - item.Orientation = null; - } - else - { - Model.Drawing.ImageOrientation orientation; - if (Enum.TryParse(image.ImageTag.Orientation.ToString(), true, out orientation)) + item.Genres = image.ImageTag.Genres.ToList(); + item.Tags = image.ImageTag.Keywords.ToList(); + item.Software = image.ImageTag.Software; + + if (image.ImageTag.Orientation == TagLib.Image.ImageOrientation.None) { - item.Orientation = orientation; + item.Orientation = null; + } + else + { + Model.Drawing.ImageOrientation orientation; + if (Enum.TryParse(image.ImageTag.Orientation.ToString(), true, out orientation)) + { + item.Orientation = orientation; + } } - } - item.ExposureTime = image.ImageTag.ExposureTime; - item.FocalLength = image.ImageTag.FocalLength; + item.ExposureTime = image.ImageTag.ExposureTime; + item.FocalLength = image.ImageTag.FocalLength; - item.Latitude = image.ImageTag.Latitude; - item.Longitude = image.ImageTag.Longitude; - item.Altitude = image.ImageTag.Altitude; + item.Latitude = image.ImageTag.Latitude; + item.Longitude = image.ImageTag.Longitude; + item.Altitude = image.ImageTag.Altitude; - if (image.ImageTag.ISOSpeedRatings.HasValue) - { - item.IsoSpeedRating = Convert.ToInt32(image.ImageTag.ISOSpeedRatings.Value); - } - else - { - item.IsoSpeedRating = null; + if (image.ImageTag.ISOSpeedRatings.HasValue) + { + item.IsoSpeedRating = Convert.ToInt32(image.ImageTag.ISOSpeedRatings.Value); + } + else + { + item.IsoSpeedRating = null; + } } } catch (Exception e) |
