metaextractor

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 3, 2024 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

MetaExtractor

MetaExtractor is a Go package that provides comprehensive metadata extraction from files. It combines file system information, TrID file type analysis, and EXIF data extraction to give you a complete picture of your files.

Installation

To use this package, you need to have Go installed on your system. You also need to have the TrID command-line tool and ExifTool installed and accessible in your system's PATH.

  1. First, install the TrID command-line tool. You can download it from the official TrID website.

  2. Install ExifTool. You can download it from the official ExifTool website.

  3. Install the MetaExtractor Go package:

go get github.com/attilabuti/metaextractor

Usage

package main

import (
	"fmt"
	"log"

	"github.com/attilabuti/metaextractor"
)

func main() {
	// Create a new MetaExtractor instance
	me := metaextractor.NewMetaExtractor(metaextractor.Options{
		TridPath:     "/path/to/trid",
		TridDefs:     "/path/to/triddefs.trd",
		TridTimeout:  5 * time.Second,
		TridMatches:  5,
		ExifToolPath: "/path/to/exiftool",
	})

	// Extract metadata from a file
	metadata, err := me.Extract("/path/to/your/file")
	if err != nil {
		log.Fatalf("Error extracting metadata: %v", err)
	}

	// Print the extracted metadata
	fmt.Printf("File Name: %s\n", metadata.Name)
	fmt.Printf("File Size: %d bytes\n", metadata.Size)
	fmt.Printf("File Extension: %s\n", metadata.Extension)
	fmt.Printf("Extension Mismatch: %v\n", metadata.ExtMismatch)
	fmt.Printf("Last Modified: %v\n", metadata.Time.ModTime)

	if len(metadata.Types) > 0 {
		fmt.Printf("Detected File Type: %s (%s)\n", metadata.Types[0].Type, metadata.Types[0].Mime)
	}

	fmt.Println("EXIF Metadata:")
	for key, value := range metadata.Exif {
		fmt.Printf("  %s: %v\n", key, value)
	}
}

Options

The Options struct allows you to configure the MetaExtractor:

  • TridPath: Path to the TrID executable
  • TridDefs: Path to the TrID definitions file
  • TridTimeout: Maximum duration allowed for TrID execution
  • TridMatches: Maximum number of file type matches to return from TrID
  • ExifToolPath: Path to the ExifTool executable

Make sure to set these paths correctly according to your system configuration.

Issues

Submit the issues if you find any bug or have any suggestion.

Contribution

Fork the repo and submit pull requests.

License

This extension is licensed under the MIT License.

Documentation

Overview

Package metaextractor provides functionality for extracting comprehensive metadata from files. It combines file system information, TrID file type analysis, and EXIF data extraction.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoFileSpecified is returned when no file path is provided.
	ErrNoFileSpecified = errors.New("no file specified")

	// ErrFileNotFound is returned when the specified file cannot be located or accessed.
	ErrFileNotFound = errors.New("file not found")

	// ErrNoMetadataExtracted indicates that no metadata could be extracted from the file.
	ErrNoMetadataExtracted = errors.New("no metadata extracted")
)

Functions

This section is empty.

Types

type ExifMetadata

type ExifMetadata map[string]interface{}

ExifMetadata is a map of EXIF metadata extracted from a file.

type FileTime

type FileTime struct {
	// ModTime is the last modification time of the file.
	ModTime time.Time

	// AccessTime is the last access time of the file.
	AccessTime time.Time

	// ChangeTime is the last status change time of the file.
	// This can differ from ModTime as it includes changes to permissions, ownership, etc.
	ChangeTime time.Time

	// BirthTime is the creation time of the file.
	// Note: This may not be available on all file systems.
	BirthTime time.Time
}

FileTime represents various timestamps associated with a file.

type MetaExtractor

type MetaExtractor struct {
	// contains filtered or unexported fields
}

MetaExtractor represents a metadata extraction instance with specific configurations.

func NewMetaExtractor

func NewMetaExtractor(opts Options) *MetaExtractor

NewMetaExtractor creates a new MetaExtractor instance with the given options.

func (*MetaExtractor) Extract

func (me *MetaExtractor) Extract(filePath string) (Metadata, error)

Extract examines the given file, extracting its metadata, determining its type, and gathering EXIF information if available. It returns a Metadata struct or an error.

type Metadata

type Metadata struct {
	// Name is the base name of the file, including the extension.
	Name string

	// Extension is the file extension (e.g., ".txt", ".pdf").
	Extension string

	// ExtMismatch indicates whether the file's extension differs from its detected type.
	ExtMismatch bool

	// Size is the file size in bytes.
	Size int64

	// Time contains various timestamps associated with the file.
	Time FileTime

	// Types is a slice of detected file types.
	// The first element (if present) is considered the most likely file type.
	Types []trid.FileType

	// Exif contains extracted EXIF metadata from the file.
	Exif ExifMetadata
}

Metadata contains comprehensive metadata extracted from a file.

type Options

type Options struct {
	// TridPath is the file system path to the TrID executable.
	TridPath string

	// TridDefs is the file system path to the TrID definitions package.
	TridDefs string

	// TridTimeout is the maximum duration allowed for TrID execution.
	TridTimeout time.Duration

	// TridMatches specifies the maximum number of file type matches to return from TrID.
	TridMatches int

	// ExifToolPath is the file system path to the ExifTool executable.
	ExifToolPath string
}

Options configures the metadata extraction parameters.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址