This project is a collection of Python scripts that help to organize media files into a directory tree "year/month" based on file metadata, using exiftool
Used by me into my personal Nextcloud installation to organize unsorted files. Strongly inspired by: https://github.com/OneLogicalMyth/Random-Scripts/blob/master/NextCloud/SortPictures.py
Tested with Linux/Debian and MacOS python 2 and 3
ATTENTION alpha version backup your files before use!
This picture describe the final result:
- manages duplicate files due to milliseconds difference (the new file uses the same old name).
- support all file types supported by exiftool
- proccess video and photo at same time (see
config.json
) - if exists, add sub second time original (fraction of seconds) to file name
Clone the repository: git clone https://github.com/vpistis/OrganizeMediaFiles.git
.
Alternatively download tarball
or zip. There haven't been any releases yet.
No installation required, it's a simple python script :) It run in python
.
In order to use the script, is necessary install at least exiftool.
Also install all requirements.txt
sudo apt-get install exiftool
brew install exiftool
Configure using config.json
python organize_media_files.py
Important: process only photo/video files with specified extensions.
Use the config.json
to change paths and other stuff.
All paths are intended without any escaping char,like backslashes
Default: "LOG_LEVEL": "INFO"
Log files are in the source directory
Default: "LOG_DIR": "/tmp"
.
If not specified use this directory. If you cannot write into this path, maybe the best choice is to use /tmp
Default: "RENAME_SORTED_FILES": false
.
If true
rename sorted files according to metadata creation time.
See DATE_FORMAT_OUTPUT
for the name of new file.
Default: "REMOVE_OLD_FILES": false
.
If true
delete old file after creation of new processed file.
Default: "APPEND_ORIG_FILENAME": false
.
If true
append the original file name at the end of new created file.
Default: "REMOVE_SPACE_FROM_FILENAME": true
.
Sometimes some space remains into filename, i want to replace it with underscores: _
Default: "DATE_FORMAT_OUTPUT": "%Y%m%d_%H%M%S"
.
The date output string in python used to name the new created file.
Used only if RENAME_SORTED_FILE=true
.
Default: "PROCESS_IMAGES": true
.
If true
process image files according to the IMAGE_FILES_EXTENSIONS
.
Default: "IMAGE_FILENAME_SUFFIX": "IMG_"
.
Prepend this string to the new created file name.
Default: "IMAGES_SOURCE_PATH": "/media/drivemount/user/files/FilesToSort"
.
The path where original image files are stored.
Default: "IMAGES_DESTINATION_PATH": "/media/drivemount/user/files/FilesSorted"
.
The root path where store the new organized image files.
Default: "IMAGE_FILES_EXTENSIONS": [".jpg",".gif",".tiff"]
.
Files with these extensions are processed as images (NOTE: exiftool support internally many file types, and the command
used in this script is the same for images/videos)
Default: "PROCESS_VIDEOS": false
.
If true
process video files according to the VIDEO_FILES_EXTENSIONS
.
Default: "VIDEO_FILENAME_SUFFIX": "VID_"
.
Prepend this string to the new created file name.
Default: "VIDEOS_SOURCE_PATH": "/media/drivemount/user/files/FilesToSort"
The path where original video files are stored.
Default: "VIDEOS_DESTINATION_PATH": "/media/drivemount/user/files/FilesSorted"
.
The root path where store the new organized video files.
Default: "VIDEO_FILES_EXTENSIONS": [".mp4",".3gp"]
.
Files with these extensions are processed as videos see IMAGE_FILES_EXTENSIONS note.
Default: "NEXTCLOUD": false
.
If true
exec nextcloud command to rescan data directory for new files.
Default: "NEXTCLOUD_PATH": "/var/www/html/nextcloud"
.
The path of nextcloud installation.
Default: "NEXTCLOUD_USER": "www-data"
Launch nextcloud scan command as a "NEXTCLOUD_USER"
.
MIT License
Copyright (c) 2017-2023 Valentino Pistis
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.