mediasort

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultFileTypes are the default media types handled by the sorter if none are specified.
	// NOTE: This default list should match the known mediatypes in the ./internal/mediatype package.
	DefaultFileTypes = []string{
		mediatype.JPEG{}.String(),
		mediatype.PNG{}.String(),
		mediatype.HEIF{}.String(),
		mediatype.TIFF{}.String(),
		mediatype.QTFF{}.String(),
		mediatype.MP4{}.String(),
	}
	// DefaultBlocklist are default regexes that are ignored by the sorter.
	DefaultBlocklist = []*regexp.Regexp{

		regexp.MustCompile(`(\/)?\d{4}\/(\d{2}\/){2}`),
	}
)

Functions

This section is empty.

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is a param that can be used to configure the media metadata sorter.

func WithDestinationDirectory

func WithDestinationDirectory(d string) Option

WithDestinationDirectory is an absolute or relative filepath where sorted media will be saved to.

func WithDetectDuplicates

func WithDetectDuplicates() Option

WithDetectDuplicates will use perception hash algorithm of each file to determine whether to images with the same EXIF metadata are duplicate files.

func WithDryRun

func WithDryRun() Option

WithDryRun instructs the sorter to make no changes

func WithFileTypes

func WithFileTypes(t []string) Option

WithFileTypes is an array of filetypes that we intend to locate. Extensions are matched case-insensitive. *.jpg is treated the same as *.JPG, etc. Can handle any file type; not just EXIF-enabled file types when used in conjunction with WithUseLastModifiedDate().

func WithInputFileMagicSignature

func WithInputFileMagicSignature() Option

WithInputFileMagicSignature instructs the sorter to idenitify media files using the file's magic signature ignoring the exisiting file extension on the media. See the manual page for file(1) to understand how this works.

func WithLastModifiedFallback

func WithLastModifiedFallback() Option

WithLastModifiedFallback instructs the sorter to fallback to using the file's last modified date if there is no media metadata. If false, images without media metadata data are ignored

func WithOutputFileMagicSignature

func WithOutputFileMagicSignature() Option

WithOutputFileMagicSignature instructs the sorter to use the known file signature when saving the output file. See the manual page for file(1) to understand how this works.

func WithOverwriteExisting

func WithOverwriteExisting() Option

WithOverwriteExisting instructs the sorter to overwrite any existing files that may already exist with the same desired destination file name Warning: Can be useful for removing duplicates by ensuring no two files with the same timestamp can exist, however, can cause data loss if not careful

func WithRegexBlocklist

func WithRegexBlocklist(d []string) Option

WithRegexBlocklist is an array of regular expressions for matching on paths to ignore when finding folders. Directory are matched case-insensitive

func WithSourceDirectory

func WithSourceDirectory(s string) Option

WithSourceDirectory is an absolute or relative filepath where sorted media will looked for.

func WithStopOnError

func WithStopOnError() Option

WithStopOnError instructs the sorter to exit quickly when any error occurs during walking the directory tree

func WithTimestampAsFilename

func WithTimestampAsFilename() Option

WithTimestampAsFilename instructs the sorter to rename the source file using it's timestamp and file extension. Note: This option can help eliminate duplicate images during sorting.

type Sorter

type Sorter interface {
	// Run runs the sorter
	Run(ctx context.Context) error
}

Sorter sorts media from file metadata

func NewSorter

func NewSorter(ctx context.Context, opts ...Option) (Sorter, error)

NewSorter returns a sorter configured with the provided Option(s). The WithSourceDirectory Option is the only required option.

Jump to

Keyboard shortcuts

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