/// <summary>Reads metadata from an <see cref="Stream"/>.</summary> /// <param name="stream">A stream from which the file data may be read. The stream must be positioned at the beginning of the file's data.</param> /// <returns>A list of <see cref="Directory"/> instances containing the various types of metadata found within the file's data.</returns> /// <exception cref="ImageProcessingException">The file type is unknown, or processing errors occurred.</exception> /// <exception cref="System.IO.IOException"/> public static DirectoryList ReadMetadata(Stream stream) { var fileType = FileTypeDetector.DetectFileType(stream); var directories = new List <Directory>(); directories.AddRange(fileType switch { FileType.Arw => TiffMetadataReader.ReadMetadata(stream), FileType.Avi => AviMetadataReader.ReadMetadata(stream), FileType.Bmp => BmpMetadataReader.ReadMetadata(stream), FileType.Crx => QuickTimeMetadataReader.ReadMetadata(stream), FileType.Cr2 => TiffMetadataReader.ReadMetadata(stream), FileType.Eps => EpsMetadataReader.ReadMetadata(stream), FileType.Gif => GifMetadataReader.ReadMetadata(stream), FileType.Ico => IcoMetadataReader.ReadMetadata(stream), FileType.Jpeg => JpegMetadataReader.ReadMetadata(stream), FileType.Mp3 => Mp3MetadataReader.ReadMetadata(stream), FileType.Nef => TiffMetadataReader.ReadMetadata(stream), FileType.Netpbm => new Directory[] { NetpbmMetadataReader.ReadMetadata(stream) }, FileType.Orf => TiffMetadataReader.ReadMetadata(stream), FileType.Pcx => new Directory[] { PcxMetadataReader.ReadMetadata(stream) }, FileType.Png => PngMetadataReader.ReadMetadata(stream), FileType.Psd => PsdMetadataReader.ReadMetadata(stream), FileType.QuickTime => QuickTimeMetadataReader.ReadMetadata(stream), FileType.Raf => RafMetadataReader.ReadMetadata(stream), FileType.Rw2 => TiffMetadataReader.ReadMetadata(stream), FileType.Tga => TgaMetadataReader.ReadMetadata(stream), FileType.Tiff => TiffMetadataReader.ReadMetadata(stream), FileType.Wav => WavMetadataReader.ReadMetadata(stream), FileType.WebP => WebPMetadataReader.ReadMetadata(stream), FileType.Unknown => throw new ImageProcessingException("File format could not be determined"), _ => Enumerable.Empty <Directory>() });
///<summary>Get when a video file was taken.</summary> ///<returns>True if this file had data.</returns> private static bool GetVideoDateTaken(string path, out DateTime dateTaken, out DateTakenSrc src) { dateTaken = DateTime.Now; src = DateTakenSrc.Now; try { IEnumerable <MetadataExtractor.Directory> directories = QuickTimeMetadataReader.ReadMetadata(new FileStream(path, FileMode.Open)); QuickTimeMovieHeaderDirectory directory = directories.OfType <QuickTimeMovieHeaderDirectory>().FirstOrDefault(); if (directory != null && directory.TryGetDateTime(QuickTimeMovieHeaderDirectory.TagCreated, out dateTaken)) { src = DateTakenSrc.Metadata; return(true); } } catch (Exception) { src = DateTakenSrc.Now; bool hasData = GetFilenameTimestamp(Path.GetFileName(path), out dateTaken, out src); if (hasData) { return(true); } dateTaken = DateTime.Now; src = DateTakenSrc.Now; return(false); } return(false); }
ReadMetadata([NotNull] Stream stream) { var fileType = FileTypeDetector.DetectFileType(stream); switch (fileType) { case FileType.Jpeg: return(JpegMetadataReader.ReadMetadata(stream)); case FileType.Tiff: case FileType.Arw: case FileType.Cr2: case FileType.Nef: case FileType.Orf: case FileType.Rw2: return(TiffMetadataReader.ReadMetadata(stream)); case FileType.Psd: return(PsdMetadataReader.ReadMetadata(stream)); case FileType.Png: return(PngMetadataReader.ReadMetadata(stream)); case FileType.Bmp: return(new Directory[] { BmpMetadataReader.ReadMetadata(stream) }); case FileType.Gif: return(GifMetadataReader.ReadMetadata(stream)); case FileType.Ico: return(IcoMetadataReader.ReadMetadata(stream)); case FileType.Pcx: return(new Directory[] { PcxMetadataReader.ReadMetadata(stream) }); case FileType.Riff: return(WebPMetadataReader.ReadMetadata(stream)); case FileType.Raf: return(RafMetadataReader.ReadMetadata(stream)); case FileType.QuickTime: return(QuickTimeMetadataReader.ReadMetadata(stream)); case FileType.Netpbm: return(new Directory[] { NetpbmMetadataReader.ReadMetadata(stream) }); } throw new ImageProcessingException("File format is not supported"); }
/// <summary>Reads metadata from an <see cref="Stream"/>.</summary> /// <param name="stream">A stream from which the file data may be read. The stream must be positioned at the beginning of the file's data.</param> /// <returns>A list of <see cref="Directory"/> instances containing the various types of metadata found within the file's data.</returns> /// <exception cref="ImageProcessingException">The file type is unknown, or processing errors occurred.</exception> /// <exception cref="System.IO.IOException"/> public static DirectoryList ReadMetadata(Stream stream) { var fileType = FileTypeDetector.DetectFileType(stream); var fileTypeDirectory = new FileTypeDirectory(fileType); switch (fileType) { case FileType.Jpeg: return(Append(JpegMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Tiff: case FileType.Arw: case FileType.Cr2: case FileType.Nef: case FileType.Orf: case FileType.Rw2: return(Append(TiffMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Psd: return(Append(PsdMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Png: return(Append(PngMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Bmp: return(Append(BmpMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Gif: return(Append(GifMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Ico: return(Append(IcoMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Pcx: return(new Directory[] { PcxMetadataReader.ReadMetadata(stream), fileTypeDirectory }); case FileType.WebP: return(Append(WebPMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Avi: return(Append(AviMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Wav: return(Append(WavMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Raf: return(Append(RafMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.QuickTime: case FileType.Crx: return(Append(QuickTimeMetadataReader.ReadMetadata(stream), fileTypeDirectory)); case FileType.Netpbm: return(new Directory[] { NetpbmMetadataReader.ReadMetadata(stream), fileTypeDirectory }); case FileType.Unknown: throw new ImageProcessingException("File format could not be determined"); case FileType.Riff: case FileType.Crw: default: throw new ImageProcessingException("File format is not supported"); }