/// <summary> /// Get the EXIF/SubIFD or PNG Created Datetime /// </summary> /// <param name="allExifItems">Directory</param> /// <param name="cameraMakeModel">cameraMakeModel</param> /// <returns>Datetime</returns> internal DateTime?GetExifDateTime(List <Directory> allExifItems, CameraMakeModel cameraMakeModel = null) { var provider = CultureInfo.InvariantCulture; var itemDateTimeSubIfd = ParseSubIfdDateTime(allExifItems, provider); if (itemDateTimeSubIfd.Year >= 2) { return(itemDateTimeSubIfd); } var itemDateTimeQuickTime = ParseQuickTimeDateTime(cameraMakeModel, allExifItems, provider); // to avoid errors scanning gpx files (with this it would be Local) if (itemDateTimeQuickTime.Year >= 1970) { return(itemDateTimeQuickTime); } // 1970-01-01T02:00:03 formatted var xmpDirectory = allExifItems.OfType <XmpDirectory>().FirstOrDefault(); var photoShopDateCreated = GetXmpData(xmpDirectory, "photoshop:DateCreated"); DateTime.TryParseExact(photoShopDateCreated, "yyyy-MM-ddTHH:mm:ss", provider, DateTimeStyles.AdjustToUniversal, out var xmpItemDateTime); if (xmpItemDateTime.Year >= 2) { return(xmpItemDateTime); } return(null); }
internal DateTime ParseQuickTimeDateTime(CameraMakeModel cameraMakeModel, IEnumerable <Directory> allExifItems, IFormatProvider provider) { if (_appSettings == null) { Console.WriteLine("[ParseQuickTimeDateTime] app settings is null"); } if (cameraMakeModel == null) { cameraMakeModel = new CameraMakeModel(); } var useUseLocalTime = _appSettings?.VideoUseLocalTime?.Any(p => string.Equals(p.Make, cameraMakeModel.Make, StringComparison.InvariantCultureIgnoreCase) && ( string.Equals(p.Model, cameraMakeModel.Model, StringComparison.InvariantCultureIgnoreCase) || string.IsNullOrEmpty(p.Model))); var quickTimeDirectory = allExifItems.OfType <QuickTimeMovieHeaderDirectory>().FirstOrDefault(); var quickTimeCreated = quickTimeDirectory?.GetDescription(QuickTimeMovieHeaderDirectory.TagCreated); var dateTimeStyle = useUseLocalTime == true ? DateTimeStyles.AdjustToUniversal : DateTimeStyles.AssumeLocal; // [QuickTime Movie Header] Created = Tue Oct 11 09:40:04 2011 or Sat Mar 20 21:29:11 2010 // time is in UTC // Or Dutch (NL-nl) "zo mrt. 29 13:10:07 2020" DateTime.TryParseExact(quickTimeCreated, "ddd MMM dd HH:mm:ss yyyy", CultureInfo.CurrentCulture, dateTimeStyle, out var itemDateTimeQuickTime); // ReSharper disable once InvertIf if (useUseLocalTime != true && _appSettings?.CameraTimeZoneInfo != null) { itemDateTimeQuickTime = DateTime.SpecifyKind(itemDateTimeQuickTime, DateTimeKind.Utc); itemDateTimeQuickTime = TimeZoneInfo.ConvertTime(itemDateTimeQuickTime, TimeZoneInfo.Utc, _appSettings?.CameraTimeZoneInfo); } return(itemDateTimeQuickTime); }