Skip to content

Instantly share code, notes, and snippets.

@hexandcube
Last active March 12, 2024 21:58
Show Gist options
  • Save hexandcube/7b79d13d2e6edaf35e62b2b9b3db9b22 to your computer and use it in GitHub Desktop.
Save hexandcube/7b79d13d2e6edaf35e62b2b9b3db9b22 to your computer and use it in GitHub Desktop.
Organize - Sort media by year/month
# === Sort media by year/month - by Hexandcube ===
# This is a configuration file for Organize v3.x (https://github.com/tfeldmann/organize)
# for sorting media files (images and video) by year/month.
# Requires Pillow (https://pypi.org/project/pillow/)
# For more details about using Organize, check the documentation: https://organize.readthedocs.io/
sources: &sources
# File source path (path to the folder containing the media files)
- 'D:\Desktop\Import\'
rules:
# --- Sorting compressed images by date found in EXIF ---
- name: 'Sorting files by EXIF date'
enabled: true
locations: *sources
subfolders: true
filters:
- extension:
# Add more file extensions here
- .jpg
- .jpeg
- .png
- .gif
- .bmp
- .heif
- .heic
- python: |
import PIL.Image
from datetime import datetime
img = PIL.Image.open(path)
exif_data = img._getexif()
year = datetime.strptime(exif_data[36867], "%Y:%m:%d %H:%M:%S").year
month = datetime.strptime(exif_data[36867], "%Y:%m:%d %H:%M:%S").month
day = datetime.strptime(exif_data[36867], "%Y:%m:%d %H:%M:%S").day
return {"year": year, "month": month, "day": day}
actions:
- echo: 'Reading date from EXIF: {python.year}-{python.month}-{python.day}'
# Change the destination folder here. Keep the '\{python.year}\{python.month}\' part.
- move: 'D:\Desktop\Import-sorted\{python.year}\{python.month}\'
# --- Sorting video files by date found in the lastmodified attribute ---
- name: 'Sorting files by lastmodified date'
enabled: true
locations: *sources
subfolders: true
filters:
- extension:
- .mov
- .mp4
- .mkv
- .avi
- .wmv
- .3gp
- lastmodified
actions:
- echo: 'Reading date from the lastmodified attribute: {lastmodified.year}-{lastmodified.month}-{lastmodified.day}'
# Change the destination folder here. Keep the '\{lastmodified.year}\{lastmodified.month}\' part.
- move: 'D:\Desktop\Import-sorted\{lastmodified.year}\{lastmodified.month}\'
# --- Sorting RAW Images by date found in the lastmodified attribute ---
- name: 'Sorting RAW images lastmodified date'
enabled: true
locations: *sources
subfolders: true
filters:
- extension:
- .raw
- .cr2
- .dng
- lastmodified
actions:
- echo: 'Reading date from the lastmodified attribute: {lastmodified.year}-{lastmodified.month}-{lastmodified.day}'
# Change the destination folder here. Keep the '\{lastmodified.year}\{lastmodified.month}\' part.
- move: 'D:\Desktop\Import-sorted\{lastmodified.year}\{lastmodified.month}\RAW\'
@hexandcube
Copy link
Author

Updated for version 2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment