Пример #1
0
        private void ParseJpgMetaData(string filename, MediaFileMetaData metaData)
        {
            // https://github.com/drewnoakes/metadata-extractor-images/blob/master/jpg/metadata/dotnet/FujiFilm%20X10.jpg.txt
            var metadataExtractorDirectories = ImageMetadataReader.ReadMetadata(filename); // very fast!

            var exifIfd0Directory = metadataExtractorDirectories.OfType <ExifIfd0Directory>().FirstOrDefault();
            var cameraModel       = exifIfd0Directory?.GetDescription(ExifDirectoryBase.TagModel);
            var copyright         = exifIfd0Directory?.GetDescription(ExifDirectoryBase.TagCopyright)?.Trim();

            var subIfdDirectory     = metadataExtractorDirectories.OfType <ExifSubIfdDirectory>().FirstOrDefault(); // contains image related data
            var exposureTime        = subIfdDirectory?.GetDescription(ExifDirectoryBase.TagExposureTime);
            var isoSpeed            = subIfdDirectory?.GetDescription(ExifDirectoryBase.TagIsoEquivalent);
            var focalLength         = subIfdDirectory?.GetDescription(ExifDirectoryBase.TagFocalLength);
            var dateTimeTakenString = subIfdDirectory?.GetDescription(ExifDirectoryBase.TagDateTimeOriginal);
            var aperture            = subIfdDirectory?.GetDescription(ExifDirectoryBase.TagAperture);
            var widthInPixel        = subIfdDirectory?.GetDescription(ExifDirectoryBase.TagExifImageWidth);
            var heightInPixel       = subIfdDirectory?.GetDescription(ExifDirectoryBase.TagExifImageHeight);

            metaData.Copyright       = copyright;
            metaData.CameraModel     = cameraModel;
            metaData.Width           = widthInPixel;
            metaData.Height          = heightInPixel;
            metaData.IsoValue        = isoSpeed;
            metaData.ExposureTime    = exposureTime;
            metaData.FocalLength     = focalLength;
            metaData.Aperture        = aperture;
            metaData.DateTakenString = dateTimeTakenString;
            metaData.DateTaken       = ParseExifDate(dateTimeTakenString);
        }
Пример #2
0
        public List <MediaFileMetaData> ReadAllFiles(string selectedFolder)
        {
            var result = new List <MediaFileMetaData>();

            if (string.IsNullOrWhiteSpace(selectedFolder) || !Directory.Exists(selectedFolder))
            {
                return(result);
            }

            var files = Directory.GetFiles(selectedFolder).ToList();

            foreach (var file in files)
            {
                var metaData = new MediaFileMetaData();

                try
                {
                    var fileInfo = new FileInfo(file);
                    metaData.FilePath        = fileInfo.DirectoryName;
                    metaData.CurrentFilename = fileInfo.Name;
                    metaData.FileSize        = fileInfo.Length;

                    metaData.FileType = GetFileType(file);

                    switch (metaData.FileType)
                    {
                    case FileTypeEnum.Jpg:
                        ParseJpgMetaData(file, metaData);
                        break;

                    case FileTypeEnum.Mp4:
                        ParseMp4MetaData(file, metaData);
                        break;

                    case FileTypeEnum.Undefined:
                        metaData.IncludeInRenaming = false;
                        break;
                    }
                }
                catch (Exception e)
                {
                    metaData.ParsingRemarks += $"Error: {e.Message}";
                    Console.WriteLine(e);
                }

                result.Add(metaData);
            }

            return(result.OrderBy(mf => mf.DateTaken ?? new DateTime()).ToList());
        }
Пример #3
0
        private string ReplaceCustomFields(string template, MediaFileMetaData mediaFile)
        {
            var newFilename = template;

            if (template.Contains("%F1"))
            {
                newFilename = newFilename.Replace("%F1", mediaFile.CustomField1);
            }

            if (template.Contains("%V"))
            {
                var isVideo = mediaFile.FileType == FileTypeEnum.Mp4 || mediaFile.FileType == FileTypeEnum.Mov;
                newFilename = newFilename.Replace("%V", isVideo ? "v" : "");
            }

            return(newFilename);
        }
Пример #4
0
        private string ReplaceDateFields(string template, MediaFileMetaData mediaFile)
        {
            var newFilename = template;

            if (template.Contains("%Y"))
            {
                newFilename = newFilename.Replace("%Y", mediaFile.DateTaken?.Year.ToString());
            }

            if (template.Contains("%M"))
            {
                newFilename = newFilename.Replace("%M", mediaFile.DateTaken?.Month.ToString().PadLeft(2, '0'));
            }
            newFilename = newFilename.Replace("%D", mediaFile.DateTaken?.Day.ToString().PadLeft(2, '0'));

            return(newFilename);
        }
Пример #5
0
        private void ParseMp4MetaData(string filename, MediaFileMetaData metaData)
        {
            // https://github.com/drewnoakes/metadata-extractor-images/blob/master/mp4/metadata/dotnet/sample_mpeg4.mp4.txt

            var metadataExtractorDirectories = ImageMetadataReader.ReadMetadata(filename); // very fast!

            var quickTimeMovieHeader = metadataExtractorDirectories.OfType <QuickTimeMovieHeaderDirectory>().FirstOrDefault();
            var dateTimeTakenString  = quickTimeMovieHeader?.GetDescription(QuickTimeMovieHeaderDirectory.TagCreated);

            var quickTimeTrackHeaderLast = metadataExtractorDirectories.OfType <QuickTimeTrackHeaderDirectory>().FirstOrDefault();
            var widthInPixel             = quickTimeTrackHeaderLast?.GetDescription(QuickTimeTrackHeaderDirectory.TagWidth);
            var heightInPixel            = quickTimeTrackHeaderLast?.GetDescription(QuickTimeTrackHeaderDirectory.TagHeight);

            //metaData.CameraModel = cameraModel;
            metaData.Width           = widthInPixel;
            metaData.Height          = heightInPixel;
            metaData.DateTakenString = dateTimeTakenString;
            metaData.DateTaken       = ParseMp4Date(dateTimeTakenString);
        }