PHPackages                             aensley/media-organizer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. aensley/media-organizer

ActiveLibrary[Image &amp; Media](/categories/media)

aensley/media-organizer
=======================

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

2.0.1(1mo ago)2561MITPHPPHP &gt;=7.1CI passing

Since Jul 6Pushed 4w ago1 watchersCompare

[ Source](https://github.com/aensley/media-organizer)[ Packagist](https://packagist.org/packages/aensley/media-organizer)[ Docs](https://github.com/aensley/media-organizer/)[ GitHub Sponsors](https://github.com/sponsors/aensley)[ Fund](https://paypal.me/AndrewEnsley)[ RSS](/packages/aensley-media-organizer/feed)WikiDiscussions main Synced 4w ago

READMEChangelog (9)Dependencies (7)Versions (11)Used By (0)

aensley/media-organizer
=======================

[](#aensleymedia-organizer)

[![Version](https://camo.githubusercontent.com/f90b8286bd0818374cf77e85f87b10dd9e6d5b1557d771986c0cfe8443b60eac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61656e736c65792f6d656469612d6f7267616e697a65722e7376673f6c6f676f3d7061636b6167697374266c6f676f436f6c6f723d666666)](https://packagist.org/packages/aensley/media-organizer)[![PHP Version](https://camo.githubusercontent.com/3e9c54d1c05277b5200cc68b51520b4eed39936ad8806469fe3ecffd49f49172/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f61656e736c65792f6d656469612d6f7267616e697a65722f7068703f6c6f676f3d706870266c6f676f436f6c6f723d666666)](https://camo.githubusercontent.com/3e9c54d1c05277b5200cc68b51520b4eed39936ad8806469fe3ecffd49f49172/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f61656e736c65792f6d656469612d6f7267616e697a65722f7068703f6c6f676f3d706870266c6f676f436f6c6f723d666666)[![License](https://camo.githubusercontent.com/4316d95d01b7139e2d9ba3a396e1ce2dd9962f6f369ac3517feaf1df11195040/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f61656e736c65792f6d656469612d6f7267616e697a65722e737667)](https://github.com/aensley/media-organizer/blob/master/LICENSE)[![prettier](https://camo.githubusercontent.com/91181288753ce08af361aa2d49dc57f34a5e249800971abfac9a02cb6b977c75/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70726574746965722d6666363962342e7376673f266c6f676f3d7072657474696572266c6f676f436f6c6f723d666666)](https://prettier.io/)[![Downloads](https://camo.githubusercontent.com/00010fd605c9b67753d2c04d0e80f1f77f94a1d22f2859a67cf63502b38e192b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61656e736c65792f6d656469612d6f7267616e697a65722e7376673f6c6f676f3d7061636b6167697374266c6f676f436f6c6f723d666666)](https://packagist.org/packages/aensley/media-organizer)[![dependencies](https://camo.githubusercontent.com/03121ad14c87beba2a3ed238a2df7847f81ea30f6591938a3d1ff28a8d1b990b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d636865636b2d627269676874677265656e3f6c6f676f3d7061636b6167697374266c6f676f436f6c6f723d666666)](https://libraries.io/packagist/aensley%2Fmedia-organizer)
[![Maintainability](https://camo.githubusercontent.com/660c095c3157d3dc0f493bf7bd0a30d8a340bc66d0548eb11301291d0367af5c/68747470733a2f2f716c74792e73682f67682f61656e736c65792f70726f6a656374732f6d656469612d6f7267616e697a65722f6d61696e7461696e6162696c6974792e737667)](https://qlty.sh/gh/aensley/projects/media-organizer)[![Code Coverage](https://camo.githubusercontent.com/14a933449aa761072e4a847dc30f4c8e9975fc0becc686dc502af490a6c3c23b/68747470733a2f2f716c74792e73682f67682f61656e736c65792f70726f6a656374732f6d656469612d6f7267616e697a65722f636f7665726167652e737667)](https://qlty.sh/gh/aensley/projects/media-organizer)[![Tests](https://github.com/aensley/media-organizer/actions/workflows/test.yml/badge.svg)](https://github.com/aensley/media-organizer/actions/workflows/test.yml)[![Socket](https://camo.githubusercontent.com/bb7b67c15b9bfdfdd82e7175db8bf0deb9be69a58b6c204ffc24b57fad354992/68747470733a2f2f62616467652e736f636b65742e6465762f636f6d706f7365722f7061636b6167652f61656e736c65792f6d656469612d6f7267616e697a6572)](https://socket.dev/composer/package/aensley/media-organizer)[![Snyk](https://camo.githubusercontent.com/6a23bca1a9c3c2a8c743a425d75d3cc7fa7104109e0d284ac597e77ba4392224/68747470733a2f2f736e796b2e696f2f746573742f6769746875622f61656e736c65792f6d656469612d6f7267616e697a65722f62616467652e737667)](https://security.snyk.io/package/composer/aensley%2Fmedia-organizer)

Organize image, video, and audio files (or any files) into date-based folders.

What it does
------------

[](#what-it-does)

**TL;DR**: This library moves files from one place to another.

`media-organizer` 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.

Although primarily written to organize JPG images, this library will work for files of any type.

### Date Retrieval Methods

[](#date-retrieval-methods)

Enabled date-retrieval methods run in the following order. When the file date is found by one method, the remaining methods are skipped for that file.

MethodDescriptionSupported File Types**EXIF**Retrieve the date from the file's EXIF data.jpeg, jpg, heic, heif, webp, tiff, dng, raw, avif, png**XMP**Retrieve the date from the file's XMP data.jpeg, jpg, png, gif, svg, heic, heif, webp, tiff, dng, raw, pdf, ai, eps, avif, psd, psb, mp4, mov**ID3**Use [`getid3`](#getid3) for advanced file metadata retrieval methods.mp4, m4a, mov, mkv, webm, mp3, riff, avi, vorbis, flac, ogg, oga, mka**File Name Masks**Match date/time patterns in the name of the file.all files**Modified Time**Use the file's "last modified" time.

*This property is set by the operating system and is not as reliable as the other methods.*all filesInstallation
------------

[](#installation)

Install the latest version

```
composer require aensley/media-organizer
```

Configuration
-------------

[](#configuration)

### Profiles

[](#profiles)

Profiles are defined in associative arrays.

```
[
    'images' => [
        'source_directory' => '/data/unorganized_pictures/',
        'target_directory' => '/data/Organized/Pictures/',
        'valid_extensions' => ['jpg'],
    ],
]
```

You can specify any number of profiles. each is processed in order with its own options.

#### Profile Options

[](#profile-options)

OptionDescriptionDefault**source\_directory****REQUIRED**: Directory to search for files.
Ending slash required.`""`search\_recursiveSet to true to look in all subdirectories of source\_directory for files.`false`valid\_extensionsArray of file extensions to search for.
Set to an empty array (`[]`) to include all files.`['jpg', 'jpeg']`**target\_directory****REQUIRED**: Destination directory for organized files.
Ending slash required.`""`target\_maskDirectory structure to use for target.

**Y** = 4-digit year, **y** = 2-digit year, **m** = 2-digit month, **d** = 2-digit day.

Anything supported by [`date()`](http://php.net/date) will work, except time-based options as they will not be consistent.`"Y/Y-m-d"`overwriteWhether to overwrite destination files.
**true** = overwrite same files that already exist in target.
**false** = add incrementing counter to identical file names to avoid collisions.`false`scan\_exif**Date Retrieval Method**: Scan EXIF data for file date.

Supports image files (JPG, TIFF, HEIC, WEBP, etc.).`true`scan\_xmp**Date Retrieval Method**: Scan XMP data for file date.

Supports mostly image files (JPG, PNG, GIF, SVG, etc.) and some video files (MP4, MOV, etc.).`false`scan\_id3**Date Retrieval Method**: Scan metadata via [getid3](#getid3) for file date.

Supports video files (MP4, MOV, MKV, AVI, etc.) and audio files (MP3, FLAC, OGG, etc.).`false`file\_name\_masks**Date Retrieval Method**: Patterns to search for in file names for date. Set to `false` to disable filename logic.

**Y** = year digit, **M** = month digit, **D** = day digit. All are replaced with digits for regex search.`['YYYY-MM-DD', 'YYYYMMDD']`modified\_time**Date Retrieval Method**: Whether or not to use the file's modified time.`false`### GetID3

[](#getid3)

Important

Installing [james-heinrich/getid3](https://github.com/JamesHeinrich/getID3) is strongly recommended to enable advanced metadata processing for video and audio files.

This library is excluded by default due to its substantial size, providing the option to omit it if it does not apply to your use case.

Enable advanced video and audio file processing with `'scan_id3' => true` in your profile after installing the dependency.

```
composer require james-heinrich/getid3
```

With this library installed, the following additional date-retrieval methods are enabled via `scan_id3`.

File FormatMetadataMP4 / MOV`quicktime.timestamps_unix.create['moov.mvhd']`MKV / WebM`matroska.info[n].DateUTC_unix`ID3v2 (MP3)`comments.recording_time` or `comments.date`RIFF/AVI`comments.creationdate` or `comments.digitizationdate`Vorbis/FLAC/OGG`comments.date`ID3v1 year-only`comments.year` (returns `YYYY-01-01`)### Logger

[](#logger)

You can specify a logger object implementing the [PRS-3 Logger Interface](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md) for handling of log messages.

Tip

[monolog](https://github.com/Seldaek/monolog) is recommended for comprehensive logging options.

[monolog-colored-line-formatter](https://github.com/bramus/monolog-colored-line-formatter) can be added for colored output in bash.

If no logger is provided, the package will simply echo all log messages directly.

Requirements
------------

[](#requirements)

- PHP &gt;= 7.1

Example usage
-------------

[](#example-usage)

### Simple example

[](#simple-example)

```
