-
Notifications
You must be signed in to change notification settings - Fork 0
/
photofix
executable file
·90 lines (72 loc) · 2.85 KB
/
photofix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env ruby
# frozen_string_literal: true
# require 'rubygems'
require 'pry'
require 'commander'
class PhotoFix
include Commander::Methods
def run
global_option('--verbose') { @verbose = true }
program :name, 'photofix'
program :version, '0.0.1'
program :description, 'Various tools for fixing photos'
command 'google' do |c|
c.syntax = 'photofix google source'
c.summary = 'Fix timestamps from photos downloaded from Google Photos'
c.description = <<~DESC
After downloading photos from Google photo using Google Takeout
the timestamps of both creation and modification are wrong (set
to the time the archive is creaetd).
This command fixes the photos using the supplied .json files within
the downloaded archive.
DESC
c.example 'Update Google exported photos in ~/some-folder', 'photofix google ~/some-folder'
c.option '--dest STRING', String, 'Directory where the images are copied to'
c.action do |args, options|
if args.length != 1
raise Commander::Runner::InvalidCommandError, "Invalid number of arguments #{args.length}, expected 1"
end
source = args.first
options.default dest: File.join(source, 'FINAL')
require_relative './fix_google_timestamp'
fixer = FixGoogleTimestamp.new(source, options.dest, @verbose)
fixer.call
end
end
command 'apple' do |c|
library_default = "#{Dir.home}/Pictures/Photos Library.photoslibrary/database/photos.db"
c.syntax = 'photofix apple source'
c.summary = 'Fix timestamps from photos downloaded from Apple Photos'
c.description = <<~DESC
After downloading unmodified originals from Apple Photos the timestamps
of some of the photos are incorrect.
This command fixes the photos using data from
the Apple Photos library database (sqlite) and exiftool.
DESC
c.example 'Update Apple Photos exported photos in ~/some-folder', 'photofix apple ~/some-folder'
c.option '--dest STRING', String, <<~DESC
Directory where the images are copied to.
Default: source/FINAL
DESC
c.option '--library STRING', String, <<~DESC
Location of the Apple Photos library.
Default: #{library_default}
DESC
c.action do |args, options|
if args.length != 1
raise Commander::Runner::InvalidCommandError, "Invalid number of arguments #{args.length}, expected 1"
end
source = args.first
options.default(
dest: File.join(source, 'FINAL'),
library: library_default
)
require_relative './fix_apple_timestamp'
fixer = FixAppleTimestamp.new(source, options.dest, options.library, @verbose)
fixer.call
end
end
run!
end
end
PhotoFix.new.run if $PROGRAM_NAME == __FILE__