Great Script to tidy Up our Photos
I was looking for a way to tidy up out photos on the NAS at home and have tried a number of things that just did not fit the bill.
they were either just to difficult or completely wrong.
i then stumbled upon this blog post http://falesafe.wordpress.com/2009/07/07/photo-management/
What a gem. if you can install ruby on a machine you have to sort your photos this is it.
The post is from 2009 and so I had to update some of the gems it uses as well as change some of the code. but it was not much work.
Thanks to Falesafe for making it available it had another bonus in that I found out that we have 76000 photos.
I feel some culling is needed.
EDIT:
I had to work with the script a bit as the EXIF attribute it was using was causing my photos to be sorted incorrectly namely (date_time).
So I have updated the script to use the (date_time_original) atribute and this has now sorted my photos properly for me. The original post that was written has comments that are closed so I will upload the adjusted script here if you want to use it.
1#!/usr/bin/ruby
2# == Synopsis
3#
4# This script examines a source directory for photos and movie files and moves them to
5# a destination directory. The destination directory will contain a date-hierarchy of folders.
6#
7# == Usage
8#
9# ruby photo\_organizer.rb \[ -h | --help \] source\_dir destination\_dir
10#
11# == Author
12# Doug Fales, Falesafe Consulting, Inc.
13#
14# == Change Log
15# LANCE HAIG = changed the EXIF attribute used to determine photo date taken to .date\_time\_original
16#
17# == Copyright
18# Copyright (c) 2009 Doug Fales.
19# Licensed under the same terms as Ruby.
20require 'rubygems'
21require 'exifr'
22require 'find'
23require 'logger'
24require 'optparse'
25require 'pathname3'
26require 'digest/sha3'
27
28STDOUT.sync = true
29
30#$log = Logger.new("photo\_organizer.log", 3, 20\*1024\*1024) # Log files up to 20MB, keep at least three around
31#$log.info("Photo organizer started...")
32
33def log
34 @log ||= Logger.new("photo\_organizer.log", 3, 20\*1024\*1024) # Log files up to 20MB, keep at least three around
35 @log
36end
37
38log.info("Photo organizer started...")
39
40def usage()
41puts < e
42 if(f =~ /.DS\_Store/)
43 log.info("Skipping .DS\_Store")
44 next
45 elsif (e.message =~ /malformed JPEG/)
46 log.info("Malformed JPEG: #{f}")
47 next
48 end
49end
50
51if(time.nil?)
52 log.info("WARNING: No EXIF time for: #{f}. Will skip it.")
53 next
54end
55
56was\_moved = move\_image(f, time)
57increment\_counter if was\_moved
58
59 when File.directory?(f)
60 log.info("Processing directory: #{f}")
61 else "?"
62 log.info("Non-dir, non-file: #{f}")
63 end
64end
65
66puts "\\nFinished."