Overview
Theutils package provides essential utility functions for file operations, date extraction from metadata, path manipulation, and dependency checking. It includes platform-specific implementations for optimal performance on macOS, Linux, and Windows.
Date Extraction
GetFileDate
Extracts the creation date from media file metadata with multiple fallback methods.Path to media file
File creation date extracted from metadata
Returns an error if no valid date is found
Extraction Priority
- macOS mdls metadata (most reliable for RAW files)
- EXIF data (DateTimeOriginal, DateTime, etc.)
- Video metadata (creation_time from FFprobe)
- File modification time (validated as fallback)
Example
getMacOSMetadataDate
Extracts creation date using macOSmdls command (macOS only).
Path to file
Platform Support
Only works on macOS (darwin). Returns error on other platforms.
getImageMetadataDate
Extracts creation date from image EXIF metadata using ImageMagick.Path to image file
EXIF Fields (Priority Order)
EXIF:DateTimeOriginal- Camera capture time (preferred)EXIF:DateTime- File save timedate:create- General creation timedate:modify- Modification time
getVideoMetadataDate
Extracts creation date from video metadata using FFprobe.Path to video file
isValidDate
Validates that a date is reasonable for media files.Date to validate
Validation Rules
- Rejects dates in the future
- Rejects dates before 1990 (pre-digital photography era)
File Organization
CreateDestinationPath
Generates the destination path for a media file based on date and organization settings.Base destination directory
File creation date
Type of media (“image” or “video”)
Whether to organize by date
Language code for month names (“en”, “fr”, “es”, “de”)
Full destination directory path
Path Structure
With date organization:GetMonthName
Returns the localized month name for a given month number.Month number (1-12)
Language code (“en”, “fr”, “es”, “de”)
Formatted as “MM-MonthName” (e.g., “03-March”)
Supported Languages
- English (en): January, February, March, …
- French (fr): Janvier, Fevrier, Mars, …
- Spanish (es): Enero, Febrero, Marzo, …
- German (de): Januar, Februar, Maerz, …
CleanFilename
Generates a clean, safe filename with date prefix.Original filename (without extension)
File extension (without dot)
File date
Counter for uniqueness (3 digits)
Cleaned filename in format: YYYY-MM-DD_cleanname_###.ext
Cleaning Operations
- Remove special characters (keep alphanumeric,
.,_,-) - Replace consecutive underscores with single underscore
- Trim leading/trailing underscores
- Add date prefix and counter
Example
GetUniqueFilename
Generates a unique filename by adding counters if file already exists.Directory path
Base filename
File extension
Full path with unique filename
Counter Limit
Returns error after 9999 attempts to prevent infinite loops.File Type Detection
HasExtension
Checks if a file has one of the specified extensions.File path or name
List of valid extensions (without dots)
True if file has one of the specified extensions
Example
Path Operations
IsPathWithin
Checks if a path is within a parent directory.Path to check
Parent directory
True if path is within parent directory
Example
EnsureDir
Creates a directory and all parent directories if they don’t exist.Directory path to create
Permissions
Creates directories with0755 permissions.
System Entry Filtering
ShouldSkipSystemEntry
Determines if a file or directory should be skipped.Entry name
Whether entry is a directory
Skipped Entries
Directories:.Spotlight-V100.fseventsd.TemporaryItems.DocumentRevisions-V100System Volume Information__MACOSX.Trash*(any trash folder)
.DS_StoreThumbs.dbdesktop.ini._*(resource forks)
IsPermissionError
Checks if an error is a permission-related error.Error to check
Video Utilities
GetVideoDuration
Extracts video duration using FFprobe.Path to video file
Video duration
Example
Acceleration
ResolveFFmpegCommand
Finds the best FFmpeg binary for the current platform.FFmpeg command to use (path or just “ffmpeg”)
Informational message about which FFmpeg was selected
Apple Silicon Optimization
On Apple Silicon (arm64), automatically detects and prefers native arm64 FFmpeg binaries for best performance. Checks:- FFmpeg in PATH
/opt/homebrew/bin/ffmpeg/opt/homebrew/opt/ffmpeg/bin/ffmpeg
CheckVideoAcceleration
Verifies hardware acceleration availability.FFmpeg command from ResolveFFmpegCommand
Whether hardware acceleration is available
Description of acceleration status
Supported Acceleration
- macOS: VideoToolbox H.265 encoder (
hevc_videotoolbox) - Other platforms: Not yet supported
Dependency Checking
CheckDependencies
Verifies that all required external tools are installed.Returns an error listing missing dependencies
Required Dependencies
ffmpeg- Video conversionffprobe- Video metadata extractionmagick- ImageMagick for image conversion