No description
  • Python 98.2%
  • Dockerfile 1%
  • Shell 0.8%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Karma 3c3484cff6 Refactor GPS extraction and SRT file search in sort_media.py
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.
2025-05-01 17:26:14 +02:00
.dockerignore first commit 2025-05-01 11:14:33 +02:00
.gitignore first commit 2025-05-01 11:14:33 +02:00
docker-compose.yml first commit 2025-05-01 11:14:33 +02:00
Dockerfile first commit 2025-05-01 11:14:33 +02:00
entrypoint.sh first commit 2025-05-01 11:14:33 +02:00
README.md Enhance README and sort_media.py: added support for cleaning mode, improved GPS extraction patterns, and updated installation instructions. The README now details new features including handling of DJI hyperlapse sequences and panoramas, along with a retry mechanism for files in use. 2025-05-01 11:34:22 +02:00
requirements.txt first commit 2025-05-01 11:14:33 +02:00
sort_media.py Refactor GPS extraction and SRT file search in sort_media.py 2025-05-01 17:26:14 +02:00

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

For better metadata extraction, especially from DNG files, install ExifTool:

  • Windows: Download from ExifTool website and add to PATH
  • Linux: apt-get install exiftool or yum install perl-Image-ExifTool
  • macOS: brew install exiftool

This option includes all dependencies (including ExifTool) in a containerized environment:

  1. Make sure Docker and Docker Compose are installed.

  2. Edit the .env file 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
    
  3. 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_MODE setting in .env
  • To enable cleaning mode, set CLEAN_MODE=true in .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 sort
  • destination_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