squarepusher 0.0.6 → 0.0.8
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 +4 -4
- data/lib/squarepusher/core.rb +50 -31
- data/lib/squarepusher/version.rb +1 -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: 89a2f891450d7acd7d93fb4e2acaa67a235962a4
|
4
|
+
data.tar.gz: 4e73934a2ad455c8ef34e90893d0ba7e53432241
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b6411977c5b5aea4861090e690347b5dd5876ca2568919373e861e4a4174a3bf2ef14ffc084e1afdacb31b8411854893dcdd6e61f43755cad5b59f0111959a1
|
7
|
+
data.tar.gz: c77411eabb63dbb63cb4573df147faed887ac19bec65277760c814720edd1b3346d12503430261c78ca5bdcf595c58e2b80fa12a2ac0bbc68dfdf95736639f99
|
data/lib/squarepusher/core.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'optparse'
|
3
|
+
require 'set'
|
4
|
+
|
3
5
|
|
4
6
|
FlickRawOptions = {}
|
5
7
|
|
@@ -31,8 +33,13 @@ module Squarepusher
|
|
31
33
|
else
|
32
34
|
ownername = owner
|
33
35
|
end
|
36
|
+
elsif p.respond_to?(:ownername)
|
37
|
+
# I want to remove this since the ownername is the human readable form and not the owner id,
|
38
|
+
# so isn't always safe to build a URL with. but for photoset.getList the only way to get the owner name
|
39
|
+
# is by specifying the extra "owner_name" - need to find a way to get the owner id
|
40
|
+
ownername = p.ownername
|
34
41
|
else
|
35
|
-
raise Exception("photo does not contain 'owner' attribute: #{p.inspect}")
|
42
|
+
raise Exception.new("photo does not contain 'owner' attribute: #{p.inspect}")
|
36
43
|
end
|
37
44
|
|
38
45
|
"http://flickr.com/photos/#{ownername}"
|
@@ -140,29 +147,9 @@ module Squarepusher
|
|
140
147
|
flickr.access_token = token
|
141
148
|
flickr.access_secret = token_secret
|
142
149
|
|
143
|
-
size = args[:size] || :small_square
|
144
|
-
|
145
|
-
# TODO: use url_for() method
|
146
|
-
@url_for_photo = case size
|
147
|
-
when :original
|
148
|
-
lambda { |p| FlickRaw.url_o(p) }
|
149
|
-
when :large
|
150
|
-
lambda { |p| FlickRaw.url_b(p) }
|
151
|
-
when :medium_640
|
152
|
-
lambda { |p| FlickRaw.url_z(p) }
|
153
|
-
when :medium_500
|
154
|
-
lambda { |p| FlickRaw.url(p) }
|
155
|
-
when :small
|
156
|
-
lambda { |p| FlickRaw.url_m(p) }
|
157
|
-
when :thumb
|
158
|
-
lambda { |p| FlickRaw.url_t(p) }
|
159
|
-
when :small_square
|
160
|
-
lambda { |p| FlickRaw.url_s(p) }
|
161
|
-
else
|
162
|
-
raise Exception("unrecognized size: #{size}")
|
163
|
-
end
|
150
|
+
@size = args[:size] || :small_square
|
164
151
|
end
|
165
|
-
|
152
|
+
|
166
153
|
def get_photo(photo_id)
|
167
154
|
flickr.photos.getInfo(:photo_id => photo_id)
|
168
155
|
end
|
@@ -245,16 +232,26 @@ module Squarepusher
|
|
245
232
|
if count == 100 then download_favorites(output_dir, page+1, &photo_call) end
|
246
233
|
end
|
247
234
|
|
248
|
-
def download_photoset(photoset, output_dir)
|
249
|
-
|
235
|
+
def download_photoset(photoset, output_dir, args={})
|
236
|
+
size = args[:size] || @size
|
237
|
+
|
238
|
+
pset_normalized_title = Squarepusher.normalize(photoset.title)
|
239
|
+
dirname = pset_normalized_title
|
250
240
|
set_dir = File.join(output_dir, dirname)
|
251
241
|
$fileutils.mkdir_p set_dir
|
252
242
|
|
253
|
-
#
|
243
|
+
# contains the following keys
|
244
|
+
# error
|
245
|
+
# exists
|
254
246
|
results = {}
|
247
|
+
local_paths = []
|
248
|
+
results[:local_photoset_dir] = set_dir
|
249
|
+
results[:local_paths] = local_paths
|
250
|
+
|
251
|
+
# handles socket timeout when loading photoset info
|
255
252
|
status, photoset_result = handle_error { flickr.photosets.getPhotos(:photoset_id => photoset.id,
|
256
253
|
:privacy_filter => @privacy,
|
257
|
-
:extras => "original_format,url_o")["photo"] }
|
254
|
+
:extras => "original_format,url_o,date_taken")["photo"] }
|
258
255
|
if status == :error
|
259
256
|
error photoset_result
|
260
257
|
results[status] = 1
|
@@ -264,15 +261,16 @@ module Squarepusher
|
|
264
261
|
end
|
265
262
|
|
266
263
|
photos.each do |p|
|
267
|
-
#
|
268
|
-
|
269
|
-
|
264
|
+
# removes all non digits from date
|
265
|
+
date_taken = p["datetaken"].gsub(/[^\d]+/, '')
|
266
|
+
|
267
|
+
name = "#{date_taken}-#{p.id}-#{pset_normalized_title}"
|
270
268
|
if not p.title.empty?
|
271
269
|
normalized_title = Squarepusher.normalize(p.title)
|
272
270
|
name << "-#{normalized_title}"
|
273
271
|
end
|
274
272
|
|
275
|
-
url =
|
273
|
+
url = Squarepusher.url_for(p, size)
|
276
274
|
|
277
275
|
# TODO: only add .jpg suffix if it's not in the image name already
|
278
276
|
path = File.join(set_dir, name)
|
@@ -290,10 +288,31 @@ module Squarepusher
|
|
290
288
|
else
|
291
289
|
results[result] = 1
|
292
290
|
end
|
291
|
+
|
292
|
+
if result == :success || result == :exists
|
293
|
+
local_paths << path
|
294
|
+
end
|
293
295
|
end
|
294
296
|
results
|
295
297
|
end
|
296
298
|
|
299
|
+
# syncs local directory with flickr photoset
|
300
|
+
# meaning, if a file exists locally that is no longer in the set, it will be deleted
|
301
|
+
def sync_photoset(photoset, output_dir, args={})
|
302
|
+
results = download_photoset(photoset, output_dir, args)
|
303
|
+
local_pset_dir = results[:local_photoset_dir]
|
304
|
+
|
305
|
+
# converts list to set for faster lookups
|
306
|
+
local_paths = Set.new(results[:local_paths])
|
307
|
+
|
308
|
+
Dir.entries(local_pset_dir).collect { |e| "#{local_pset_dir}/#{e}"}.select { |e| File.file?(e) }.each do |e|
|
309
|
+
if not local_paths.include?(e)
|
310
|
+
# puts "deleting #{e}"
|
311
|
+
$fileutils.rm e
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
297
316
|
private
|
298
317
|
|
299
318
|
def fire_event(args={})
|
data/lib/squarepusher/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: squarepusher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mhawthorne
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: flickraw
|