コード例 #1
0
 public MediaMetaTagPlugin(string path)
 {
     base.Name        = "Media Meta Tag Plugin";
     base.Author      = "Amir Rezaei";
     base.Description = "Reads attributes from images and videos.";
     base.Version     = "1.0";
     Entity           = new MediaMetaTag(path);
 }
コード例 #2
0
        public override IEnumerable <Entity> GetEntities()
        {
            var entities = new List <Entity>();

            try
            {
                FileInfo[] files = new DirectoryInfo(Path).GetFiles("*.*", SearchOption.AllDirectories);
                foreach (var file in files)
                {
                    try
                    {
                        Entity entity = new MediaMetaTag(file.FullName)
                        {
                            Name = file.Name
                        };
                        IReadOnlyList <MetadataExtractor.Directory> directories = ImageMetadataReader.ReadMetadata(file.FullName);
                        FileType fileType = GetFileType(file.FullName);

                        if (fileType != FileType.Mp4 && fileType != FileType.QuickTime && fileType != FileType.Unknown)
                        {
                            var directory = directories.OfType <MetadataExtractor.Formats.Exif.ExifSubIfdDirectory>().FirstOrDefault();
                            if (directory == null)
                            {
                                entity.Values.Add("Date Taken", "Missing");
                            }
                            else
                            {
                                DateTime dateTime = directory.GetDateTime(ExifDirectoryBase.TagDateTimeOriginal);
                                entity.Values.Add("Date Taken", dateTime.ToString(CultureInfo.InvariantCulture));
                            }
                            entity.Values.Add("Type", fileType.ToString());
                        }
                        else if ((fileType == FileType.Mp4 || fileType == FileType.QuickTime) && fileType != FileType.Unknown)
                        {
                            var directory = directories.OfType <MetadataExtractor.Formats.QuickTime.QuickTimeMovieHeaderDirectory>().FirstOrDefault();

                            if (directory == null)
                            {
                                entity.Values.Add("Date Taken", "Missing");
                            }
                            else
                            {
                                DateTime dateTime = directory.GetDateTime(MetadataExtractor.Formats.QuickTime.QuickTimeMovieHeaderDirectory.TagCreated);
                                entity.Values.Add("Date Taken", dateTime.ToString(CultureInfo.InvariantCulture));
                            }
                            entity.Values.Add("Type", fileType.ToString());
                        }
                        else
                        {
                            entity.Values.Add("Date Taken", "N/A");
                            entity.Values.Add("Type", "Unknown");
                        }

                        entities.Add(entity);
                    }
                    catch (UnauthorizedAccessException ex)
                    {
                        Logger.Error(ex.Message);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error(ex.Message);
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error(e.Message);
            }


            return(entities);
        }