exifsort

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package lib implements libraries to sort media by date using exif and modtime information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExifTimeGet

func ExifTimeGet(filepath string) (time.Time, error)

ExifTimeGet accepts a filepath, returns the 'IFD/EXIF/DateTimeOriginal' contained in its metadata.

func ExtensionsMovie

func ExtensionsMovie() []string

ExtensionsMovie returns the set of extensions for files that take a long time to extract "IFD/EXIF/DateTimeOriginal" so we only check modTime. Set includes: 3g2, 3gp, avi, m4v, mov, mp4, mpg, wmv.

func ExtensionsPhoto

func ExtensionsPhoto() []string

ExtensionsPhoto returns set of supported Extensions that we process by checking "IFD/EXIF/DateTimeOriginal" data then if needed modTime.

Set includes: bmp, cr2, dng, gif, jpeg, jpg, nef, png, psd, raf, raw, tif, tiff.

func SynologySkip

func SynologySkip() []string

SynologySkip returns the set of files or directories that contain strings we find on Synology file servers and ignore. The check is case insensitive.

Set includes: @eadir, @syno, synofile_thumb

Types

type Action

type Action int

Action user specifies to transfer files from src to dst.

const (
	// ActionCopy : Copying files from src to dst
	ActionCopy Action = iota
	// ActionMove : Moving files from src to dst
	ActionMove
	// ActionNone : Error Value
	ActionNone
)

User can specify how to transfer files from one directory to another.

func ActionParse

func ActionParse(str string) (Action, error)

ActionParse returns Action from string (must be lower case). Returns ActionNone if invalid.

func Actions

func Actions() []Action

Actions returns all actions values used excluding ActionNone.

func (Action) String

func (a Action) String() string

Returns name of action value (all lower case).

type Merger

type Merger struct {
	Merged  map[string]string
	Errors  map[string]string
	Removed []string
	// contains filtered or unexported fields
}

Merger holds the API and statistics to merge sorted directories.

func NewMerger

func NewMerger(src string, dst string, action Action, filter string) *Merger

NewMerger returns a Merger to execute a merge of two sorted directories. src is the sorted directory to transfer from. dst is the sorted directory to transfer to. action is how to transfer files. filter is a regexp to use to filter which files to transfer

func (*Merger) Merge

func (m *Merger) Merge(logger io.Writer) error

Merge performs several actions. It checks that its src and dst directories are correctly sorted and determines by what method for each. If the directories' sort methods don't match an error is returned. Src directory is walked and all files are transferred to the appropriate directory in dst. New directories are made if necessary. If the move action was specified then duplicate files are removd from src. If files have the same filename and end up in the same dst directory they will be renamed to not collide.

func (*Merger) Reset

func (m *Merger) Reset(src string, dst string, action Action, filter string)

Reset will clear all previous state of a merge from the struct so it is ready to Merge again. src is the sorted directory to transfer from. dst is the sorted directory to transfer to. action is how to transfer files. filter is a regexp to use to filter which files to transfer

type Method

type Method int

Method user specifies indexing and structuring sorted directories.

const (
	// MethodYear : dst -> year-> media
	MethodYear Method = iota
	// MethodMonth : dst -> year-> month -> media
	MethodMonth
	// MethodDay : dst -> year-> month -> day -> media
	MethodDay
	// MethodNone : Error Value
	MethodNone
)

func MethodParse

func MethodParse(str string) (Method, error)

MethodParse returns Method from string (must be lower case). Returns MethodNone if invalid.

func Methods

func Methods() []Method

Methods returns all method values used excluding MethodNone.

func (Method) String

func (m Method) String() string

Returns name of method value (all lower case).

type Scanner

type Scanner struct {
	Input             ScannerInput
	SkippedCount      int
	Data              map[string]time.Time
	NumDataTypes      map[string]int
	ExifErrors        map[string]string
	NumExifErrorTypes map[string]int
	ScanErrors        map[string]string
}

Scanner is your API to scan directory of media.

It holds errors and data results of the scan after scanning.

func NewScanner

func NewScanner() Scanner

NewScanner allocates a new Scanner.

func (*Scanner) Load

func (s *Scanner) Load(jsonPath string) error

Load Scanner from a json file.

func (*Scanner) NumTotal

func (s *Scanner) NumTotal() int

NumTotal returns the total number of files skipped, scanned and errors.

func (*Scanner) Reset

func (s *Scanner) Reset()

Reset clears data so Scanner can be reused.

func (*Scanner) Save

func (s *Scanner) Save(jsonPath string) error

Save Scanner to a json file.

func (*Scanner) ScanDir

func (s *Scanner) ScanDir(src string, logger io.Writer) error

ScanDir will examine the contents of every file in the src directory and print it's time of creation as stored by exifdata as it scans.

ScanDir only scans media files listed as constants as documented, other files are skipped.

logger specifies where to send output while scanning.

func (*Scanner) ScanFile

func (s *Scanner) ScanFile(path string) (time.Time, error)

ScanFile accepts a filepath, reads the exifdata stored inside and returns the 'Exif/DateTimeOriginal' value as a golang time.Time format. If the exifData is not valid it will return the time based on FileInfo's ModTime.

It returns an error if the file has no exif data and cannot be statted.

type ScannerInput

type ScannerInput int

ScannerInput specifies how scanner receives data

const (
	// ScannerInputJSON : Input via JSON file
	ScannerInputJSON ScannerInput = iota
	// ScannerInputDir : Input via dir
	ScannerInputDir
	// ScannerInputNone : Error valueI
	ScannerInputNone
)

type Sorter

type Sorter struct {
	IndexErrors    map[string]string
	TransferErrors map[string]string
	Duplicates     []string
	// contains filtered or unexported fields
}

Sorter is your API to perform sorting actions after a scan.

Sorting is composed of two stages. The first is "indexing", where the scanned data is organized by the specified method. The second is "transferring", where the media is transferred from the src to the dst directory.

It holds the index of sorted media and errors found in constructing or transferring it.

func NewSorter

func NewSorter(scanner Scanner, method Method) (*Sorter, error)

NewSorter creates the sorter based on the WalkState generated by a scan and the method desired to sort.

The structure of how it will organize the the dst directory is specified by 'method'. This routine will index via the method speficied.

func (*Sorter) Reset

func (s *Sorter) Reset(scanner Scanner, method Method) error

Reset clears data so Sorter can be reused.

func (*Sorter) Transfer

func (s *Sorter) Transfer(dst string, action Action, logger io.Writer) error

Transfer will transfer files after indexing according to action. Transfer will fail if dst directory does not exist and is not accessible.

Jump to

Keyboard shortcuts

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