aensley/media-organizer

Organize images and videos (or any files) into date-based folders.

1.0.2 2016-07-06 22:03 UTC

README

Organize images and videos (or any files) into date-based folders.

MIT License Latest Stable Version Packagist Downloads Build Status Tested Versions Status

GitHub Issues Dependency Status Code Climate Grade Code Climate Issues Code Climate Test Coverage

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:

  1. EXIF - Retrieve the date from the file's EXIF data (JPG and TIFF images only).
  2. File Name Masks - Match date/time patterns in the name of the file.
  3. 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 >= 5.6

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();

Supercharged by ZenHub.io