aensley / media-organizer
Organize images and videos (or any files) into date-based folders.
Fund package maintenance!
aensley
paypal.me/AndrewEnsley
Requires
- php: >=5.5.0
Requires (Dev)
- codacy/coverage: dev-master
- codeclimate/php-test-reporter: dev-master
- phpunit/phpcov: dev-master
- satooshi/php-coveralls: 1.0.x-dev
Suggests
- bramus/monolog-colored-line-formatter: Colored log output in bash
- monolog/monolog: Advanced logging options
This package is not auto-updated.
Last update: 2025-01-11 13:38:27 UTC
README
Organize images and videos (or any files) into date-based folders.
What it does
Description for the impatient reader: This library moves files from one place to another.
Detailed description: This library helps organize files into date-based folders. The date is retrieved from each file in a number of configurable ways. The structure of the date-based folders can be designed any way you want.
This was primarily written to organize JPG images, but it will work for files of any type. Available date-retrieval methods are:
- EXIF - Retrieve the date from the file's EXIF data (JPG and TIFF images only).
- File Name Masks - Match date/time patterns in the name of the file.
- Modified Time - Use the file's "last modified" time. This property is set by the operating system and is often not as reliable as the first two.
Installation
Install the latest version with
composer require aensley/media-organizer
Options
Profiles
You can specify any number of profiles to process. They will be processed in order. Each profile can have its own separate options. Available options are documented in the code.
Logger
You can specify a logger object implementing the PRS-3 Logger Interface for custom handling of log messages. I recommend Monolog (and monolog-colored-line-formatter for bonus points in bash).
Otherwise, you can specify a log level string (one of: 'none', 'error', 'warning', 'info', 'debug') to use the simple internal logger. The internal logger directly echoes messages followed by newline characters \n
.
Requirements
- PHP >= 7.1
Example usage
Simple example
<?php require '/path/to/composer/autoload.php'; $organizer = new \Aensley\MediaOrganizer\MediaOrganizer( array( 'images' => array( 'source_directory' => '/data/unorganized_pictures/', 'target_directory' => '/data/Organized/Pictures/', 'valid_extensions' => array('jpg'), ), 'videos' => array( 'source_directory' => '/data/unorganized_videos/', 'target_directory' => '/data/Organized/Videos/', 'valid_extensions' => array('mp4'), 'scan_exif' => false, ), ), 'debug' ); $organizer->organize();
Advanced Usage
<?php require '/path/to/composer/autoload.php'; use \Monolog\Logger; use \Monolog\Handler\StreamHandler; use \Bramus\Monolog\Formatter\ColoredLineFormatter; use \Aensley\MediaOrganizer\MediaOrganizer; $logger = new Logger('mediaOrganizer'); // Colored output in Bash $handler = new StreamHandler('php://stdout', Logger::DEBUG); $handler->setFormatter(new ColoredLineFormatter()); $logger->pushHandler($handler); // Put everything in a log file, too. $logger->pushHandler(new StreamHandler('/var/log/mediaOrganizer/mediaOrganizer.log', Logger::DEBUG)); $organizer = new MediaOrganizer( array( 'images' => array( 'source_directory' => '/data/unorganized_pictures/', 'target_directory' => '/data/Organized/Pictures/', 'valid_extensions' => array('jpg'), ), 'videos' => array( 'source_directory' => '/data/unorganized_videos/', 'target_directory' => '/data/Organized/Videos/', 'valid_extensions' => array('mp4'), 'scan_exif' => false, ), 'gifs' => array( 'source_directory' => '/data/unorganized_gifs/', 'target_directory' => '/data/Organized/Gifs/', 'valid_extensions' => array('gif'), 'scan_exif' => false, 'file_name_masks' => false, 'modified_time' => true, 'search_recursive' => true, 'target_mask' => 'Y/F/d', 'overwrite' => true, ), ), $logger ); $organizer->organize();