photo-helper 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/photo-helper +2 -0
- data/lib/helpers/secrets.rb +7 -0
- data/lib/helpers/smugmug_api.rb +45 -10
- data/lib/photo-helper/delete.rb +2 -2
- data/lib/photo-helper/move.rb +2 -2
- data/lib/photo-helper/smugmug.rb +29 -2
- data/lib/photo-helper/version.rb +1 -1
- data/lib/photo_helper.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10936e1f4337f7ca26a766b16b69fe7a955b5e9d
|
4
|
+
data.tar.gz: 2b9a13e9b775b1974441c5933a9189299da634af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8626562041251a2d8f867fea3579d14dda11114c36d9934db2e6569248e2ee13a6cce1b1e8ca213b760aa6b47e5db29e0e401549a564b339cbb969a9972377c3
|
7
|
+
data.tar.gz: 7117f97c2b55af7fa1469c2c16d641cc6e64730e2dc2011980aef39ac0454ebd9d4f5690f362eff21bb623e4b2ee75b22a5ba6a644408ea4d4b5e0cb94af7ef9
|
data/Gemfile.lock
CHANGED
data/bin/photo-helper
CHANGED
data/lib/helpers/secrets.rb
CHANGED
@@ -5,7 +5,10 @@ require 'pathname'
|
|
5
5
|
require 'json'
|
6
6
|
|
7
7
|
class Secrets
|
8
|
+
attr_reader :ejson_config_file
|
9
|
+
|
8
10
|
def initialize(config_file = nil, required = [])
|
11
|
+
@ejson_config_file = config_file
|
9
12
|
@secrets = {}
|
10
13
|
unless config_file.nil?
|
11
14
|
load_from_ejson(config_file)
|
@@ -52,6 +55,10 @@ class Secrets
|
|
52
55
|
required.each { |key| raise "required secrets not set: #{key}" if @secrets[key].nil? }
|
53
56
|
end
|
54
57
|
|
58
|
+
def [](key)
|
59
|
+
@secrets[key.to_sym]
|
60
|
+
end
|
61
|
+
|
55
62
|
def method_missing(key, *args)
|
56
63
|
value = @secrets[key]
|
57
64
|
return value unless value.nil?
|
data/lib/helpers/smugmug_api.rb
CHANGED
@@ -12,12 +12,12 @@ class SmugmugAPI
|
|
12
12
|
ACCESS_TOKEN_URL = '/services/oauth/1.0a/getAccessToken'.freeze
|
13
13
|
AUTHORIZE_URL = '/services/oauth/1.0a/authorize'.freeze
|
14
14
|
API_ENDPOINT = 'https://api.smugmug.com'.freeze
|
15
|
-
UPLOAD_ENDPOINT = '
|
15
|
+
UPLOAD_ENDPOINT = 'https://upload.smugmug.com/'.freeze
|
16
16
|
|
17
17
|
def initialize(ejson_file = '~/.photo_helper.ejson')
|
18
18
|
ejson_file = File.expand_path(ejson_file)
|
19
19
|
@secrets = Secrets.new(ejson_file, %i[api_key api_secret])
|
20
|
-
|
20
|
+
request_access_token if !@secrets["access_token"] || !@secrets["access_secret"]
|
21
21
|
|
22
22
|
@http = get_access_token
|
23
23
|
@uploader = get_access_token(UPLOAD_ENDPOINT)
|
@@ -54,7 +54,8 @@ class SmugmugAPI
|
|
54
54
|
name: node['Name'],
|
55
55
|
web_uri: node['WebUri'],
|
56
56
|
node_uri: node['Uri'],
|
57
|
-
id: File.basename(node['Uris']['Album']['Uri'])
|
57
|
+
id: File.basename(node['Uris']['Album']['Uri']),
|
58
|
+
type: 'node')
|
58
59
|
end
|
59
60
|
end
|
60
61
|
album_list
|
@@ -102,10 +103,10 @@ class SmugmugAPI
|
|
102
103
|
resp = post(url, Name: album_name,
|
103
104
|
UrlName: album_url.tr(' ', '-').capitalize,
|
104
105
|
Privacy: 'Unlisted',
|
105
|
-
SmugSearchable:
|
106
|
-
SortMethod:
|
107
|
-
LargestSize:
|
108
|
-
SortDirection:
|
106
|
+
SmugSearchable: 'No',
|
107
|
+
SortMethod: 'Date Taken',
|
108
|
+
LargestSize: 'X4Large',
|
109
|
+
SortDirection: 'Ascending',
|
109
110
|
WorldSearchable: false,
|
110
111
|
EXIF: false,
|
111
112
|
Printable: false,
|
@@ -210,12 +211,38 @@ class SmugmugAPI
|
|
210
211
|
end
|
211
212
|
end
|
212
213
|
|
213
|
-
private
|
214
|
-
|
215
214
|
def request_access_token
|
216
|
-
|
215
|
+
@consumer = OAuth::Consumer.new(@secrets.api_key, @secrets.api_secret,
|
216
|
+
site: OAUTH_ORIGIN,
|
217
|
+
name: 'photo-helper',
|
218
|
+
request_token_path: REQUEST_TOKEN_URL,
|
219
|
+
authorize_path: AUTHORIZE_URL,
|
220
|
+
access_token_path: ACCESS_TOKEN_URL)
|
221
|
+
|
222
|
+
# Generate request token
|
223
|
+
@request_token = @consumer.get_request_token
|
224
|
+
|
225
|
+
# Get authorize URL
|
226
|
+
@request_token.authorize_url
|
227
|
+
|
228
|
+
url = add_auth_params(@request_token.authorize_url, 'Access' => 'Full', 'Permissions' => 'Modify')
|
229
|
+
|
230
|
+
puts "Go to #{url} and enter shown 6 digit number:"
|
231
|
+
verifier = STDIN.gets.strip
|
232
|
+
|
233
|
+
# Now go to that url and when you're done authorization you can run the
|
234
|
+
# following command where you put in the value for oauth_verifier that you got
|
235
|
+
# from completely the above URL request:
|
236
|
+
access_token = @request_token.get_access_token(oauth_verifier: verifier)
|
237
|
+
|
238
|
+
puts "Add the following to your ejson file #{@secrets.ejson_config_file}:"
|
239
|
+
puts "\"access_token\": \"#{access_token.token}\","
|
240
|
+
puts "\"access_secret\": \"#{access_token.secret}\""
|
241
|
+
exit 0
|
217
242
|
end
|
218
243
|
|
244
|
+
private
|
245
|
+
|
219
246
|
def http_raw(method, url, headers = {}, _body = nil)
|
220
247
|
url.tr!(' ', '-')
|
221
248
|
headers['Accept'] = 'application/json'
|
@@ -265,4 +292,12 @@ class SmugmugAPI
|
|
265
292
|
type: 'image'
|
266
293
|
}
|
267
294
|
end
|
295
|
+
|
296
|
+
def add_auth_params(url, params)
|
297
|
+
uri = URI.parse(url)
|
298
|
+
new_query_ar = URI.decode_www_form(uri.query || '')
|
299
|
+
params.to_a.each { |el| new_query_ar << el }
|
300
|
+
uri.query = URI.encode_www_form(new_query_ar)
|
301
|
+
uri.to_s
|
302
|
+
end
|
268
303
|
end
|
data/lib/photo-helper/delete.rb
CHANGED
@@ -22,9 +22,9 @@ module PhotoHelper
|
|
22
22
|
|
23
23
|
files =
|
24
24
|
if options[:recursive]
|
25
|
-
Dir["#{search_path}
|
25
|
+
Dir["#{search_path}/**/*.{#{JPEG_EXTENSIONS.join(",")}}"]
|
26
26
|
else
|
27
|
-
Dir["#{search_path}
|
27
|
+
Dir["#{search_path}/*.{#{JPEG_EXTENSIONS.join(",")}}"]
|
28
28
|
end
|
29
29
|
|
30
30
|
files.each do |file|
|
data/lib/photo-helper/move.rb
CHANGED
@@ -22,9 +22,9 @@ module PhotoHelper
|
|
22
22
|
|
23
23
|
files =
|
24
24
|
if options[:recursive]
|
25
|
-
Dir["#{search_path}
|
25
|
+
Dir["#{search_path}/**/*.{#{JPEG_EXTENSIONS.join(",")}}"]
|
26
26
|
else
|
27
|
-
Dir["#{search_path}
|
27
|
+
Dir["#{search_path}/*.{#{JPEG_EXTENSIONS.join(",")}}"]
|
28
28
|
end
|
29
29
|
|
30
30
|
files.each do |file|
|
data/lib/photo-helper/smugmug.rb
CHANGED
@@ -33,9 +33,9 @@ module PhotoHelper
|
|
33
33
|
puts "Using album: #{album_name}"
|
34
34
|
|
35
35
|
@smugmug = SmugmugAPI.new
|
36
|
-
album = @smugmug.get_or_create_album(album_name, album_url: location
|
36
|
+
album = @smugmug.get_or_create_album(album_name, album_url: location&.downcase)
|
37
37
|
puts "#{album[:web_uri]}\n"
|
38
|
-
pictures = Dir["#{search_path}/**/*.
|
38
|
+
pictures = Dir["#{search_path}/**/*.{#{IMAGE_EXTENSIONS.join(",")}}"]
|
39
39
|
|
40
40
|
# remove uploaded pictures
|
41
41
|
uploaded = @smugmug.image_list(album[:id])
|
@@ -44,5 +44,32 @@ module PhotoHelper
|
|
44
44
|
|
45
45
|
@smugmug.upload_images(pictures, album[:id], workers: 8)
|
46
46
|
end
|
47
|
+
|
48
|
+
desc 'oauth', "fetch oauth credentials"
|
49
|
+
def oauth()
|
50
|
+
SmugmugAPI.new.request_access_token
|
51
|
+
end
|
52
|
+
|
53
|
+
desc 'albums', "list albums with their weburl"
|
54
|
+
method_option :folder, aliases: '-f', type: :string, default: '.'
|
55
|
+
def albums(folder = nil, album_name = nil)
|
56
|
+
@smugmug = SmugmugAPI.new
|
57
|
+
albums = @smugmug.albums_long
|
58
|
+
|
59
|
+
current_month = albums.first[:path].split("/")[1]
|
60
|
+
output = ["# Photos", "## #{current_month}"]
|
61
|
+
|
62
|
+
albums.each do |a|
|
63
|
+
month = a[:path].split("/")[1]
|
64
|
+
next unless month
|
65
|
+
if month != current_month
|
66
|
+
current_month = month
|
67
|
+
output.push("## #{current_month}")
|
68
|
+
end
|
69
|
+
output.push("[#{a[:name]}](#{a[:web_uri].gsub('http://', 'https://')})")
|
70
|
+
end
|
71
|
+
|
72
|
+
puts output.join("\n\n")
|
73
|
+
end
|
47
74
|
end
|
48
75
|
end
|
data/lib/photo-helper/version.rb
CHANGED
data/lib/photo_helper.rb
CHANGED
@@ -14,6 +14,8 @@ require 'photo-helper/smugmug'
|
|
14
14
|
# RAW_EXTENSION = "ORF"
|
15
15
|
RAW_EXTENSION = "dng"
|
16
16
|
JPEG_EXTENSION = "JPG"
|
17
|
+
JPEG_EXTENSIONS = ["JPG", "jpg", "jpeg"]
|
18
|
+
IMAGE_EXTENSIONS = JPEG_EXTENSIONS.merge([])
|
17
19
|
PHOTOS_ROOT = "/Users/benjamincaldwell/Pictures/Pictures"
|
18
20
|
JPEG_ROOT ="/Users/benjamincaldwell/Pictures/jpegs"
|
19
21
|
IGNORE_FOLDERS = ["instagram", "exported", "edited"]
|
@@ -25,7 +27,7 @@ module PhotoHelper
|
|
25
27
|
|
26
28
|
desc "version", "displays installed version"
|
27
29
|
def version
|
28
|
-
puts
|
30
|
+
puts PhotoHelper::VERSION
|
29
31
|
end
|
30
32
|
|
31
33
|
register PhotoHelper::Generate, :generate, "generate", "Do something else"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: photo-helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Caldwell
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|