private async void ReadImageMetadata(MediaItemM mi, BitmapMetadata bm, bool gpsOnly) { // Lat Lng var tmpLat = bm.GetQuery("System.GPS.Latitude.Proxy")?.ToString(); if (tmpLat != null) { var vals = tmpLat[..^ 1].Split(',');
public async Task <bool> ReadMetadata(MediaItemM mi, bool gpsOnly = false) { try { if (mi.MediaType == MediaType.Video) { await Core.RunOnUiThread(() => ReadVideoMetadata(mi)); } else { using Stream srcFileStream = File.Open(mi.FilePath, FileMode.Open, FileAccess.Read, FileShare.Read); var decoder = BitmapDecoder.Create(srcFileStream, BitmapCreateOptions.None, BitmapCacheOption.None); var frame = decoder.Frames[0]; mi.Width = frame.PixelWidth; mi.Height = frame.PixelHeight; mi.SetThumbSize(true); Model.DataAdapter.IsModified = true; // true because only media item dimensions are required if (frame.Metadata is not BitmapMetadata bm) { return(true); } ReadImageMetadata(mi, bm, gpsOnly); mi.SetThumbSize(true); } mi.IsOnlyInDb = false; } catch (Exception ex) { _core.LogError(ex, mi.FilePath); // No imaging component suitable to complete this operation was found. if ((ex.InnerException as COMException)?.HResult == -2003292336) { return(false); } mi.IsOnlyInDb = true; // true because only media item dimensions are required return(true); } return(true); }
public static string ToCsv(MediaItemM mediaItem) => string.Join("|", mediaItem.Id.ToString(), mediaItem.Folder.Id.ToString(), mediaItem.FileName, mediaItem.Width.ToString(), mediaItem.Height.ToString(), mediaItem.Orientation.ToString(), mediaItem.Rating.ToString(), mediaItem.Comment ?? string.Empty, mediaItem.GeoName?.Id.ToString(), mediaItem.People == null ? string.Empty : string.Join(",", mediaItem.People.Select(x => x.Id)), mediaItem.Keywords == null ? string.Empty : string.Join(",", mediaItem.Keywords.Select(x => x.Id)), mediaItem.IsOnlyInDb ? "1" : string.Empty);
private void ReadVideoMetadata(MediaItemM mi) { try { var size = ShellStuff.FileInformation.GetVideoMetadata(mi.Folder.FullPath, mi.FileName); mi.Height = (int)size[0]; mi.Width = (int)size[1]; mi.Orientation = (int)size[2] switch { 90 => (int)MediaOrientation.Rotate90, 180 => (int)MediaOrientation.Rotate180, 270 => (int)MediaOrientation.Rotate270, _ => (int)MediaOrientation.Normal, }; mi.SetThumbSize(true); Model.DataAdapter.IsModified = true; } catch (Exception ex) { _core.LogError(ex, mi.FilePath); } }
public override void FromCsv(string csv) { var props = csv.Split('|'); if (props.Length != 12) { throw new ArgumentException("Incorrect number of values.", csv); } var mi = new MediaItemM(int.Parse(props[0]), null, props[2]) { Csv = props, Width = props[3].IntParseOrDefault(0), Height = props[4].IntParseOrDefault(0), Orientation = props[5].IntParseOrDefault(1), Rating = props[6].IntParseOrDefault(0), Comment = string.IsNullOrEmpty(props[7]) ? null : props[7], IsOnlyInDb = props[11] == "1" }; _model.All.Add(mi); _model.AllDic.Add(mi.Id, mi); }
public MediaItemDeletedEventArgs(MediaItemM mediaItem) { MediaItem = mediaItem; }