No description
- Python 98.2%
- Dockerfile 1%
- Shell 0.8%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
Updated the extract_gps_from_srt function to streamline GPS coordinate extraction using regex patterns, improving detection for various DJI SRT formats. Enhanced the find_srt_files function to prioritize SRT files based on timestamp matching and introduced logic to handle files in the Unknown_Location directory more effectively, ensuring proper organization and processing. |
||
| .dockerignore | ||
| .gitignore | ||
| docker-compose.yml | ||
| Dockerfile | ||
| entrypoint.sh | ||
| README.md | ||
| requirements.txt | ||
| sort_media.py | ||
Media Sorter
A Python script that organizes media files (images and videos) into folders based on their date and location metadata.
Features
- Sorts media files by date (YYYY-MM-DD format)
- Sub-categorizes by location based on GPS coordinates
- Handles duplicate files
- Supports recursive directory scanning
- Works with common image formats (JPG, PNG, TIFF, DNG) and video formats (MP4, MOV, AVI, MKV)
- Extracts GPS data from DJI drone SRT subtitle files
- Provides both command-line and graphical user interfaces
- Supports cleaning mode to reorganize existing files
- Handles DJI hyperlapse sequences and panoramas
- Includes retry mechanism for files in use
- Tracks processed files to avoid duplicates
Installation Options
Option 1: Direct Installation
Requirements
pip install pillow pytz reverse_geocoder hachoir opencv-python numpy scipy
Optional (Recommended)
For better metadata extraction, especially from DNG files, install ExifTool:
- Windows: Download from ExifTool website and add to PATH
- Linux:
apt-get install exiftooloryum install perl-Image-ExifTool - macOS:
brew install exiftool
Option 2: Docker (Recommended)
This option includes all dependencies (including ExifTool) in a containerized environment:
-
Make sure Docker and Docker Compose are installed.
-
Edit the
.envfile with your source and destination paths:# Media Sorter Configuration # Source directory containing media files to sort SOURCE_DIR=P:/Librairy/Documents/Drone/DJI_003 # Destination directory where sorted files will be placed DEST_DIR=P:/Librairy/Documents/Sorted_Media # Set to true to process directories recursively RECURSIVE=true # Set to true to enable GUI mode (requires X server on host) GUI_MODE=false # Set to true to enable cleaning mode CLEAN_MODE=false -
Build and run the container:
docker-compose up --build
Docker Notes
- Use forward slashes (
/) in your paths even on Windows - For paths with spaces, use quotes:
SOURCE_DIR="/path/with spaces/photos" - To switch between GUI and CLI modes, change the
GUI_MODEsetting in.env - To enable cleaning mode, set
CLEAN_MODE=truein.env
Usage
GUI Mode
Simply run the script with no arguments to launch the graphical interface:
python sort_media.py
The GUI allows you to:
- Select source and destination folders using file browsers
- Toggle recursive scanning
- Enable cleaning mode
- View real-time progress with a status log
Command-Line Mode
Use the command-line interface with various options:
# Normal mode (copy files to destination)
python sort_media.py source_directory destination_directory [--recursive]
# Cleaning mode (reorganize files in source directory)
python sort_media.py source_directory -c [--recursive]
Or using the short form:
# Normal mode
python sort_media.py source_directory destination_directory [-r]
# Cleaning mode
python sort_media.py source_directory -c [-r]
Arguments
source_directory: Directory containing media files to sortdestination_directory: Directory where sorted files will be placed (not needed in cleaning mode)-r, --recursive: Optional flag to scan the source directory recursively-c, --clean: Enable cleaning mode to reorganize files in the source directory
Output Structure
The script will organize your files in the following structure:
destination_directory/
└── YYYY-MM-DD/
├── CityName_Country/
│ ├── Photos/
│ │ └── image1.jpg
│ ├── Videos/
│ │ ├── video1.mp4
│ │ └── video1.SRT
│ ├── Hyperlapses/
│ │ └── HYPERLAPSE_20240312171701.mp4
│ └── Panoramas/
│ └── PANORAMA_20240312171701.jpg
└── Unknown_Location/
└── image_without_gps.jpg
Notes
- Files without GPS metadata will be placed in an "Unknown_Location" folder
- For videos from DJI drones, GPS data is extracted from accompanying SRT subtitle files
- For DJI DNG files, multiple extraction methods are used, including ExifTool if available
- The script copies accompanying SRT files alongside the videos
- If no date metadata is found, the file's last modified date is used
- The script copies files rather than moving them to preserve originals
- Cleaning mode reorganizes files within the source directory
- Hyperlapse sequences are combined into videos
- Panorama sequences are stitched into single images
- Files in use are handled with a retry mechanism
- Processed files are tracked to avoid duplicates