photo-helper 0.5.6 → 0.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 267cd7787b42ba92cc8a5cbb0b2fc3b6df7c89e9f9e329448d15ca2b0497f312
4
- data.tar.gz: 50a2f2411eb195e74445652ce13e6bd3e5aaefc7b2e9a9fba8134cb0530d786d
3
+ metadata.gz: 82761f9bc4418f056200d2b7ecd7584375f2b38f4aef619801ea5ea7693cb42e
4
+ data.tar.gz: a50dcf77c1bd0a5afba585036dff711d2fdf9f6f691ed5676a9af0b8c964c2f5
5
5
  SHA512:
6
- metadata.gz: 3b9af79a851d3be2e57a1c20189fd0e145a415f09046a95820b8c97cf6d9dc82d64dd6b6cba3effc9edd6bde73a05bab5fc1705e0f2dfaa74de0d93519a48b50
7
- data.tar.gz: 626ca8ea86130530e073ec17f3144376e104b618edbff9c057f26203d15423899b7e8fa6d2721b0ea0f453f5f94df5c33e6a5f990562fa3ffaea5b06b961b904
6
+ metadata.gz: 16183ad1cc973700b9483896fca9c55ffb6abca4c4e418a931ae8f53aec7849c3d3e8d25c74414842caae7f6b134d0d5db9175adc7ed59f20697356abe279a4a
7
+ data.tar.gz: ff19d5858d07f83a962b603e421579b2cfe856e93b43e32e5e0f8fc4370882560f3dda114d71eaa28e5cd5385acb5edc63c0fa5908673afd6f71dfb36eefbf94
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- photo-helper (0.5.6)
4
+ photo-helper (0.5.7)
5
5
  ejson
6
6
  mimemagic
7
7
  mini_magick
@@ -66,4 +66,4 @@ DEPENDENCIES
66
66
  rubocop
67
67
 
68
68
  BUNDLED WITH
69
- 1.16.1
69
+ 1.16.2
@@ -25,12 +25,14 @@ class ImageHelper
25
25
 
26
26
  def self.rating(image)
27
27
  contents = xmp(image)
28
+ return 0 unless contents
28
29
  matches = contents.match(RATING_REGEX)
29
- matches[1] if matches
30
+ return matches[1].to_i if matches && matches[1].match(/^\d+$/)
31
+ 0
30
32
  end
31
33
 
32
34
  def self.is_select?(image)
33
- contains_color_class?(image, SELECT_COLOR_TAGS)
35
+ contains_color_class?(image, SELECT_COLOR_TAGS) || rating(image) >= SELECT_RATING
34
36
  end
35
37
 
36
38
  def self.is_5_star?(image)
@@ -123,6 +123,7 @@ class SmugmugAlbumHelper
123
123
  to_upload = {}
124
124
  to_update = {}
125
125
  to_delete = []
126
+ to_update_keywords = []
126
127
 
127
128
  image_list_hash.each do |filename, images|
128
129
  images.each do |image|
@@ -133,7 +134,12 @@ class SmugmugAlbumHelper
133
134
 
134
135
  if uploaded_hash.key?(filename)
135
136
  !uploaded_hash[filename].each do |uploaded|
136
- next unless uploaded_match_requested?(image, uploaded)
137
+ unless uploaded_match_requested?(image, uploaded)
138
+ if uploaded[:md5] == image[:md5]
139
+ to_update_keywords.push(uploaded)
140
+ end
141
+ next
142
+ end
137
143
 
138
144
  # & returns if in both arrays
139
145
  upload_image = false
@@ -143,7 +149,7 @@ class SmugmugAlbumHelper
143
149
  break
144
150
  end
145
151
  end
146
-
152
+
147
153
  if upload_image
148
154
  push_hash_array(to_upload, image[:keywords], image[:file])
149
155
  end
@@ -187,8 +187,10 @@ class SmugmugAPI
187
187
  def post(url, body = {}, headers = {})
188
188
  url = url.tr(' ', '-')
189
189
  headers['Accept'] = 'application/json'
190
+ headers['Content-Type'] = 'application/json'
191
+ headers['Connection'] = 'keep-alive'
190
192
  response = @http.post(url, body, headers)
191
- raise "Request failed\n#{response.body}" unless response.is_a? Net::HTTPSuccess
193
+ raise "Request failed\n#{URI.unescape(response.body)}" unless response.is_a? Net::HTTPSuccess
192
194
  JSON.parse(response.body)['Response']
193
195
  end
194
196
 
@@ -213,7 +215,7 @@ class SmugmugAPI
213
215
  def upload_images(images, album_id, headers = {}, workers: 4, filename_as_title: false)
214
216
  Parallel.each(images, in_processes: workers, progress: "Uploading images") do |image|
215
217
  upload(image, album_id, headers, filename_as_title: filename_as_title)
216
- puts "Done #{image}"
218
+ puts "Done #{image}\n"
217
219
  end
218
220
  end
219
221
 
@@ -222,7 +224,7 @@ class SmugmugAPI
222
224
  # replace not working, delete then upload
223
225
  http(:delete, image[:uri])
224
226
  upload(image[:file], album_id, headers, filename_as_title: filename_as_title)
225
- puts "Done #{image[:file]}"
227
+ puts "Done #{image[:file]}\n"
226
228
  end
227
229
  end
228
230
 
@@ -238,6 +240,14 @@ class SmugmugAPI
238
240
  post("/api/v2/album/#{album_id}!moveimages", "MoveUris" => images)
239
241
  end
240
242
 
243
+ def update_keywords(image, keywords, overwrite = false)
244
+ return if image.nil?
245
+ keywords = (image[:keywords] + keywords).uniq unless overwrite
246
+
247
+ # inspect need outwise it isnt encoded right
248
+ pp post("#{image[:image_uri]}?_method=PATCH", KeywordArray: keywords.inspect)
249
+ end
250
+
241
251
  def request_access_token
242
252
  @consumer = OAuth::Consumer.new(@secrets.api_key, @secrets.api_secret,
243
253
  site: OAUTH_ORIGIN,
@@ -314,6 +324,7 @@ class SmugmugAPI
314
324
  id: image['ImageKey'],
315
325
  md5: image['ArchivedMD5'],
316
326
  uri: image['Uri'],
327
+ image_uri: image['Uris']['Image']['Uri'],
317
328
  web_uri: image['WebUri'],
318
329
  type: 'image'
319
330
  }
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module PhotoHelper
3
- VERSION = '0.5.6'
3
+ VERSION = '0.5.7'
4
4
  end
@@ -24,6 +24,7 @@ SCREENSAVER_ROOT = File.expand_path("~/Pictures/screensaver")
24
24
  JPEG_ROOT = File.expand_path("~/Pictures/jpegs")
25
25
  IGNORE_FOLDERS = %w(instagram exported edited)
26
26
  SELECT_COLOR_TAGS = ["Winner", "Winner alt", "Superior", "Superior alt", "Typical", "Typical alt"]
27
+ SELECT_RATING = 1 #greater than or equal to
27
28
 
28
29
  module PhotoHelper
29
30
  class CLI < Thor
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.5.6
4
+ version: 0.5.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Caldwell
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-02 00:00:00.000000000 Z
11
+ date: 2018-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -262,7 +262,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
262
262
  version: '0'
263
263
  requirements: []
264
264
  rubyforge_project:
265
- rubygems_version: 2.7.6
265
+ rubygems_version: 2.7.7
266
266
  signing_key:
267
267
  specification_version: 4
268
268
  summary: A tool to automatate my photo workflows