diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-10-26 14:25:03 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2016-10-26 14:25:03 -0400 |
| commit | 0189f4c49dc89654e6aa10c5dd0fc50a0984bfec (patch) | |
| tree | 63f142411e538d5c6c6949299e82913d7441cc1b /MediaBrowser.Providers/Photos | |
| parent | 4b51233cc8faeea344661a2a3427579e534d8ea4 (diff) | |
move provider project towards portability
Diffstat (limited to 'MediaBrowser.Providers/Photos')
| -rw-r--r-- | MediaBrowser.Providers/Photos/PhotoHelper.cs | 98 | ||||
| -rw-r--r-- | MediaBrowser.Providers/Photos/PhotoProvider.cs | 169 |
2 files changed, 0 insertions, 267 deletions
diff --git a/MediaBrowser.Providers/Photos/PhotoHelper.cs b/MediaBrowser.Providers/Photos/PhotoHelper.cs deleted file mode 100644 index 2334c792e..000000000 --- a/MediaBrowser.Providers/Photos/PhotoHelper.cs +++ /dev/null @@ -1,98 +0,0 @@ -using System; -using System.Text; - -namespace MediaBrowser.Providers.Photos -{ - public static class PhotoHelper - { - public static string Dec2Frac(double dbl) - { - char neg = ' '; - double dblDecimal = dbl; - if (dblDecimal == (int)dblDecimal) return dblDecimal.ToString(); //return no if it's not a decimal - if (dblDecimal < 0) - { - dblDecimal = Math.Abs(dblDecimal); - neg = '-'; - } - var whole = (int)Math.Truncate(dblDecimal); - string decpart = dblDecimal.ToString().Replace(Math.Truncate(dblDecimal) + ".", ""); - double rN = Convert.ToDouble(decpart); - double rD = Math.Pow(10, decpart.Length); - - string rd = Recur(decpart); - int rel = Convert.ToInt32(rd); - if (rel != 0) - { - rN = rel; - rD = (int)Math.Pow(10, rd.Length) - 1; - } - //just a few prime factors for testing purposes - var primes = new[] { 47, 43, 37, 31, 29, 23, 19, 17, 13, 11, 7, 5, 3, 2 }; - foreach (int i in primes) ReduceNo(i, ref rD, ref rN); - - rN = rN + (whole * rD); - return string.Format("{0}{1}/{2}", neg, rN, rD); - } - - /// <summary> - /// Finds out the recurring decimal in a specified number - /// </summary> - /// <param name="db">Number to check</param> - /// <returns></returns> - private static string Recur(string db) - { - if (db.Length < 13) return "0"; - var sb = new StringBuilder(); - for (int i = 0; i < 7; i++) - { - sb.Append(db[i]); - int dlength = (db.Length / sb.ToString().Length); - int occur = Occurence(sb.ToString(), db); - if (dlength == occur || dlength == occur - sb.ToString().Length) - { - return sb.ToString(); - } - } - return "0"; - } - - /// <summary> - /// Checks for number of occurence of specified no in a number - /// </summary> - /// <param name="s">The no to check occurence times</param> - /// <param name="check">The number where to check this</param> - /// <returns></returns> - private static int Occurence(string s, string check) - { - int i = 0; - int d = s.Length; - string ds = check; - for (int n = (ds.Length / d); n > 0; n--) - { - if (ds.Contains(s)) - { - i++; - ds = ds.Remove(ds.IndexOf(s, System.StringComparison.Ordinal), d); - } - } - return i; - } - - /// <summary> - /// Reduces a fraction given the numerator and denominator - /// </summary> - /// <param name="i">Number to use in an attempt to reduce fraction</param> - /// <param name="rD">the Denominator</param> - /// <param name="rN">the Numerator</param> - private static void ReduceNo(int i, ref double rD, ref double rN) - { - //keep reducing until divisibility ends - while ((rD % i) < 1e-10 && (rN % i) < 1e-10) - { - rN = rN / i; - rD = rD / i; - } - } - } -} diff --git a/MediaBrowser.Providers/Photos/PhotoProvider.cs b/MediaBrowser.Providers/Photos/PhotoProvider.cs deleted file mode 100644 index c48c3d09b..000000000 --- a/MediaBrowser.Providers/Photos/PhotoProvider.cs +++ /dev/null @@ -1,169 +0,0 @@ -using MediaBrowser.Controller.Entities; -using MediaBrowser.Controller.Library; -using MediaBrowser.Controller.Providers; -using MediaBrowser.Model.Entities; -using MediaBrowser.Model.Logging; -using System; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using TagLib; -using TagLib.IFD; -using TagLib.IFD.Entries; -using TagLib.IFD.Tags; - -namespace MediaBrowser.Providers.Photos -{ - public class PhotoProvider : ICustomMetadataProvider<Photo>, IHasItemChangeMonitor, IForcedProvider - { - private readonly ILogger _logger; - - public PhotoProvider(ILogger logger) - { - _logger = logger; - } - - public Task<ItemUpdateType> FetchAsync(Photo item, MetadataRefreshOptions options, CancellationToken cancellationToken) - { - item.SetImagePath(ImageType.Primary, item.Path); - - // Examples: https://github.com/mono/taglib-sharp/blob/a5f6949a53d09ce63ee7495580d6802921a21f14/tests/fixtures/TagLib.Tests.Images/NullOrientationTest.cs - - try - { - using (var file = TagLib.File.Create(item.Path)) - { - var image = file as TagLib.Image.File; - - var tag = file.GetTag(TagTypes.TiffIFD) as IFDTag; - - if (tag != null) - { - var structure = tag.Structure; - - if (structure != null) - { - var exif = structure.GetEntry(0, (ushort)IFDEntryTag.ExifIFD) as SubIFDEntry; - - if (exif != null) - { - var exifStructure = exif.Structure; - - if (exifStructure != null) - { - 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; - - var rating = image.ImageTag.Rating; - if (rating.HasValue) - { - item.CommunityRating = rating; - } - else - { - item.CommunityRating = null; - } - - item.Overview = image.ImageTag.Comment; - - if (!string.IsNullOrWhiteSpace(image.ImageTag.Title)) - { - item.Name = image.ImageTag.Title; - } - - var dateTaken = image.ImageTag.DateTime; - if (dateTaken.HasValue) - { - item.DateCreated = dateTaken.Value; - item.PremiereDate = dateTaken.Value; - item.ProductionYear = dateTaken.Value.Year; - } - - 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 = 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.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; - } - } - } - catch (Exception e) - { - _logger.ErrorException("Image Provider - Error reading image tag for {0}", e, item.Path); - } - - const ItemUpdateType result = ItemUpdateType.ImageUpdate | ItemUpdateType.MetadataImport; - return Task.FromResult(result); - } - - public string Name - { - get { return "Embedded Information"; } - } - - public bool HasChanged(IHasMetadata item, IDirectoryService directoryService) - { - if (item.EnableRefreshOnDateModifiedChange && !string.IsNullOrWhiteSpace(item.Path) && item.LocationType == LocationType.FileSystem) - { - var file = directoryService.GetFile(item.Path); - if (file != null && file.LastWriteTimeUtc != item.DateModified) - { - return true; - } - } - - return false; - } - } -} |
