Skip to content

a collection of Python scripts that help you organize media files into a directory tree "year/month" based on metadata , using exiftool

License

Notifications You must be signed in to change notification settings

vspaziani/OrganizeMediaFiles

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OrganizeMediaFiles Alpha

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: final result

Features

  • 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

Getting OrganizeMediaFiles:

Clone the repository: git clone https://github.com/vpistis/OrganizeMediaFiles.git. Alternatively download tarball or zip. There haven't been any releases yet.

Installation

No installation required, it's a simple python script :) It run in python.

Requirements

In order to use the script, is necessary install at least exiftool. Also install all requirements.txt

Debian based

sudo apt-get install exiftool

MacOS

brew install exiftool

Usage

Step 1: configuration

Configure using config.json

Step 2: run

python organize_media_files.py

Configuration

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

LOG_LEVEL

Default: "LOG_LEVEL": "INFO" Log files are in the source directory

LOG_PATH

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

RENAME_SORTED_FILES

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.

REMOVE_OLD_FILES

Default: "REMOVE_OLD_FILES": false. If true delete old file after creation of new processed file.

APPEND_ORIG_FILENAME

Default: "APPEND_ORIG_FILENAME": false. If true append the original file name at the end of new created file.

REMOVE_SPACE_FROM_FILENAME

Default: "REMOVE_SPACE_FROM_FILENAME": true. Sometimes some space remains into filename, i want to replace it with underscores: _

DATE_FORMAT_OUTPUT

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.

PROCESS_IMAGES

Default: "PROCESS_IMAGES": true. If true process image files according to the IMAGE_FILES_EXTENSIONS.

IMAGE_FILENAME_SUFFIX

Default: "IMAGE_FILENAME_SUFFIX": "IMG_". Prepend this string to the new created file name.

IMAGES_SOURCE_PATH

Default: "IMAGES_SOURCE_PATH": "/media/drivemount/user/files/FilesToSort". The path where original image files are stored.

IMAGES_DESTINATION_PATH

Default: "IMAGES_DESTINATION_PATH": "/media/drivemount/user/files/FilesSorted". The root path where store the new organized image files.

IMAGE_FILES_EXTENSIONS

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)

PROCESS_VIDEOS

Default: "PROCESS_VIDEOS": false. If true process video files according to the VIDEO_FILES_EXTENSIONS.

VIDEO_FILENAME_SUFFIX

Default: "VIDEO_FILENAME_SUFFIX": "VID_". Prepend this string to the new created file name.

VIDEOS_SOURCE_PATH

Default: "VIDEOS_SOURCE_PATH": "/media/drivemount/user/files/FilesToSort" The path where original video files are stored.

VIDEOS_DESTINATION_PATH

Default: "VIDEOS_DESTINATION_PATH": "/media/drivemount/user/files/FilesSorted". The root path where store the new organized video files.

VIDEO_FILES_EXTENSIONS

Default: "VIDEO_FILES_EXTENSIONS": [".mp4",".3gp"]. Files with these extensions are processed as videos see IMAGE_FILES_EXTENSIONS note.

NEXTCLOUD

Default: "NEXTCLOUD": false. If true exec nextcloud command to rescan data directory for new files.

NEXTCLOUD_PATH

Default: "NEXTCLOUD_PATH": "/var/www/html/nextcloud". The path of nextcloud installation.

NEXTCLOUD_USER

Default: "NEXTCLOUD_USER": "www-data" Launch nextcloud scan command as a "NEXTCLOUD_USER".

LICENSE

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.

About

a collection of Python scripts that help you organize media files into a directory tree "year/month" based on metadata , using exiftool

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%