This Python script organizes media files (images and videos) from a source directory into optimized "discs" based on a specified maximum size. It also generates HTML galleries for each disc with features like thumbnail generation, slideshows, and more.
- Media Organization: Packs media files into discs without exceeding the maximum size.
- Album Segmentation: Splits large albums into smaller segments to fit disc constraints.
- Optimized for Google Photos exports: Uses the meta data available within Google Takeout photo exports.
- Thumbnail Generation: Creates thumbnails for images and videos, including support for RAW image formats.
- HTML Gallery Generation: Generates an interactive HTML gallery for each disc with:
- Lazy loading of images.
- Modal view with slideshow functionality.
- Next and previous navigation.
- Keyboard navigation support.
- Video playback with fallback for unsupported formats.
- Hash Manifest Creation: Generates a
hash_manifest.jsonfile for each directory for integrity checks.
- Python 3.6+
- Operating System: Windows, macOS, or Linux
Install the required Python packages using:
pip install -r requirements.txt
The required packages are:
Pillowrawpytqdmexiftool
- FFmpeg: Used for video thumbnail generation and as a fallback for RAW image thumbnails.
- ExifTool: Used for extracting metadata from media files.
Ensure that both ffmpeg and exiftool are installed and added to your system's PATH so that they can be called from the command line. If on windows, they should be called ffmpeg.exe and exiftool.exe, and I just include them in the same folder as the Python script we intend to run.
-
Windows: Download from ffmpeg.org and add the
binfolder to your PATH. -
macOS: Install via Homebrew:
brew install ffmpeg -
Linux: Install via package manager:
sudo apt-get install ffmpeg
-
Windows: Download from exiftool.org and add the executable to your PATH.
-
macOS: Install via Homebrew:
brew install exiftool -
Linux: Install via package manager:
sudo apt-get install libimage-exiftool-perl
python script.py <source_directory> <destination_directory> [--move]
<source_directory>: The path to the directory containing your media files.<destination_directory>: The path where you want the organized discs and galleries to be created.--move(optional): If specified, files will be moved instead of copied.
python script.py /path/to/source /path/to/destination- The script will create subdirectories named
Disc_1,Disc_2, etc., in the destination directory. - Each disc will contain media files organized into albums, along with an
index.htmlfile for the gallery. - A
processed_files.logfile will be created in the destination directory, logging all successful operations. - If errors occur, error logs like
error_log_disc_1.txtwill be generated in the destination directory. - It make take hours to process 100 GB on an average computer, and potentially days if dealing with terabytes of data.
-
Scanning and Segmentation:
- The script scans the source directory for media files.
- Albums with more than 300 files are segmented into smaller albums to fit disc constraints.
-
Metadata Extraction:
- Uses
exiftoolto extract date taken and other metadata from media files. - If metadata is unavailable, falls back to file system timestamps.
- Uses
-
Disc Packing Optimization:
- Organizes media files into discs without exceeding the maximum size
- The default packing size targets 23.2 GB, which will safely fill a standard 25 GB BD-R disc.
- The target packing size can be changed at a code level with little fuss, if needed.
- Prioritizes filling discs to at least 90% capacity, so not to split albums too aggressively
- Organizes media files into discs without exceeding the maximum size
-
File Processing:
- Copies or moves files from the source to the destination discs.
- Preserves the directory structure and album organization.
-
Thumbnail Generation:
- Generates thumbnails for images and videos.
- Supports RAW image formats using
rawpyorffmpegas a fallback. - Creates placeholder thumbnails if thumbnail generation fails.
-
HTML Gallery Generation:
- Creates an
index.htmlfile for each disc with an interactive gallery. - Features include lazy loading, modal pop-ups, slideshows, and keyboard navigation.
- Creates an
-
Hash Manifest Creation:
- Generates a
hash_manifest.jsonfile in each album directory. - Useful for verifying file integrity.
- Generates a
- Adjusting Disc Size: Modify the
max_sizeparameter in theorganize_mediafunction call to change the maximum disc size. - Changing Files Per Segment: Adjust the
files_per_segmentparameter in theget_segmented_albumsfunction to change how albums are segmented. - Excluding Files or Folders: Update the
skip_filesset and the conditions in theget_segmented_albumsfunction to exclude specific files or folders.
-
Missing Thumbnails:
- Ensure
ffmpegis correctly installed and accessible. - Check for any error messages during thumbnail generation.
- Ensure
-
Videos Not Playing in Browser:
- Some browsers may not support certain video formats (e.g.,
.avi). - The gallery provides a download link for unsupported formats.
- Some browsers may not support certain video formats (e.g.,
-
Performance Issues:
- Thumbnail generation can be resource-intensive.
- Running the script on a machine with adequate resources is recommended.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License.



