squarepusher 0.0.4 → 0.0.5
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 +7 -0
- data/bin/squarepusher +1 -115
- data/lib/squarepusher.rb +1 -208
- data/lib/squarepusher/cli.rb +11 -29
- data/lib/squarepusher/core.rb +153 -1
- data/lib/squarepusher/version.rb +1 -1
- metadata +32 -50
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5af95a1bb91651737acad0bd3c7bdbc9da54f32a
|
4
|
+
data.tar.gz: 0f0a0b49404d9c572cb9409c8ad85be2078691de
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 26dce1e4adf0be47f7e9be0588c898841d55faa009295102c411aee30928b02a7726586686003d88f2f1c952837b8fd281625d56f21532fb602c96ffc18892f4
|
7
|
+
data.tar.gz: 3d4f3a7853e96ef738a595830157ac32610bbf4bd550137b59dbb81772a39bc68f01e12e1dde18da6125b364984ebe33dfdbbd7475a29f66b9930da557bc20aa
|
data/bin/squarepusher
CHANGED
@@ -3,118 +3,4 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'squarepusher'
|
5
5
|
|
6
|
-
Squarepusher::CLI.main
|
7
|
-
|
8
|
-
# require 'rubygems'
|
9
|
-
# require 'squarepusher'
|
10
|
-
#
|
11
|
-
# def error_msg(msg)
|
12
|
-
# $stderr.puts "ERROR - #{msg}"
|
13
|
-
# end
|
14
|
-
#
|
15
|
-
# def fail(msg, code=1)
|
16
|
-
# error_msg(msg)
|
17
|
-
# exit code
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
#
|
21
|
-
# actions = {}
|
22
|
-
#
|
23
|
-
# actions[:list_sets] = lambda do |client, args|
|
24
|
-
# client.each_photoset do |pset|
|
25
|
-
# puts Squarepusher.describe_photoset(pset)
|
26
|
-
# end
|
27
|
-
# end
|
28
|
-
#
|
29
|
-
# actions[:grab_all_sets] = lambda do |client, args|
|
30
|
-
# if args.size != 1
|
31
|
-
# fail("expected: <output_dir>")
|
32
|
-
# end
|
33
|
-
#
|
34
|
-
# output_dir = args[0]
|
35
|
-
#
|
36
|
-
# total_results = {}
|
37
|
-
# client.each_photoset do |pset|
|
38
|
-
# pset_description = Squarepusher.describe_photoset(pset)
|
39
|
-
# puts "[set] #{pset_description}"
|
40
|
-
# pset_results = client.download_photoset(pset, output_dir)
|
41
|
-
# puts "[results] #{pset_description} #{pset_results.inspect}"
|
42
|
-
# total_results[pset_description] = pset_results
|
43
|
-
# puts
|
44
|
-
# end
|
45
|
-
#
|
46
|
-
# total_results.each_pair do |k, v|
|
47
|
-
# puts "#{k}: #{v.inspect}"
|
48
|
-
# end
|
49
|
-
# end
|
50
|
-
#
|
51
|
-
# actions[:grab_set] = lambda do |client, args|
|
52
|
-
# if args.size != 2
|
53
|
-
# fail("expected: <photoset_id> <output_dir>")
|
54
|
-
# end
|
55
|
-
#
|
56
|
-
# pset_id, output_dir = args
|
57
|
-
# pset = client.get_photoset(pset_id)
|
58
|
-
# results = client.download_photoset(pset, output_dir)
|
59
|
-
# puts results.inspect
|
60
|
-
# end
|
61
|
-
#
|
62
|
-
# actions[:find_set] = lambda do |client, args|
|
63
|
-
# if args.size != 1
|
64
|
-
# fail("expected: <photoset_id>")
|
65
|
-
# end
|
66
|
-
#
|
67
|
-
# pset_id, output_dir = args
|
68
|
-
# pset = client.get_photoset(pset_id)
|
69
|
-
# puts Squarepusher.describe_photoset(pset)
|
70
|
-
# end
|
71
|
-
#
|
72
|
-
#
|
73
|
-
# def action_str(actions)
|
74
|
-
# actions.keys.join(",")
|
75
|
-
# end
|
76
|
-
#
|
77
|
-
# def size_str
|
78
|
-
# Squarepusher.sizes.join(",")
|
79
|
-
# end
|
80
|
-
#
|
81
|
-
#
|
82
|
-
# options = { :size => :original }
|
83
|
-
# args = nil
|
84
|
-
# action = nil
|
85
|
-
# client = nil
|
86
|
-
# OptionParser.new do |opts|
|
87
|
-
# opts.banner = "USAGE: squarepusher [options] <api-key> <api-secret> <token> <action:(#{action_str(actions)})> [args]"
|
88
|
-
#
|
89
|
-
# opts.on("-o", "--overwrite", "overwrite already downloaded files") do |v|
|
90
|
-
# options[:overwrite] = v
|
91
|
-
# end
|
92
|
-
#
|
93
|
-
# opts.on("-s", "--size SIZE", "size of photos to download (#{size_str()})") do |v|
|
94
|
-
# options[:size] = v.to_sym
|
95
|
-
# end
|
96
|
-
#
|
97
|
-
# opts.on("-v", "--verbose", "log verbosely") do |v|
|
98
|
-
# options[:verbose] = v
|
99
|
-
# end
|
100
|
-
#
|
101
|
-
# opts.parse!(ARGV)
|
102
|
-
#
|
103
|
-
# if ARGV.size < 4
|
104
|
-
# $stderr.puts opts
|
105
|
-
# exit 1
|
106
|
-
# end
|
107
|
-
#
|
108
|
-
# key, secret, token, action = ARGV.slice!(0...4)
|
109
|
-
# args = ARGV
|
110
|
-
#
|
111
|
-
# action = action.to_sym
|
112
|
-
# if not actions.has_key?(action)
|
113
|
-
# $stderr.puts opts
|
114
|
-
# exit 2
|
115
|
-
# end
|
116
|
-
#
|
117
|
-
# client = Squarepusher::Client.new(key, secret, token, options)
|
118
|
-
# end
|
119
|
-
#
|
120
|
-
# actions[action].call(client, args || [])
|
6
|
+
Squarepusher::CLI.main
|
data/lib/squarepusher.rb
CHANGED
@@ -1,210 +1,3 @@
|
|
1
1
|
require 'squarepusher/cli'
|
2
2
|
require 'squarepusher/core'
|
3
|
-
require 'squarepusher/version'
|
4
|
-
|
5
|
-
# require 'fileutils'
|
6
|
-
# require 'optparse'
|
7
|
-
#
|
8
|
-
# FlickRawOptions = {}
|
9
|
-
#
|
10
|
-
# $fileutils = FileUtils::Verbose
|
11
|
-
#
|
12
|
-
# # TODO: detect "photo unavailable" and don't download image
|
13
|
-
# UNAVAILABLE_URL = 'http://l.yimg.com/g/images/photo_unavailable.gif'
|
14
|
-
#
|
15
|
-
# # TODO: keep track of failures
|
16
|
-
#
|
17
|
-
# module Squarepusher
|
18
|
-
#
|
19
|
-
# class << self
|
20
|
-
#
|
21
|
-
# def describe_photoset(pset)
|
22
|
-
# "#{pset.id} '#{pset.title}'"
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# def normalize(name)
|
26
|
-
# name.gsub(/[^a-zA-Z0-9_+\.=-]+/, '-')
|
27
|
-
# end
|
28
|
-
#
|
29
|
-
# def sizes
|
30
|
-
# return [:original, :large, :medium_640, :medium_500, :small, :thumb, :small_square]
|
31
|
-
# end
|
32
|
-
#
|
33
|
-
# end
|
34
|
-
#
|
35
|
-
# class Client
|
36
|
-
#
|
37
|
-
# def initialize(key, secret, token, args={})
|
38
|
-
# @overwrite = args[:overwrite] || false
|
39
|
-
# @verbose = args[:verbose] || false
|
40
|
-
#
|
41
|
-
# FlickRawOptions['timeout'] = args[:timeout] || 5
|
42
|
-
#
|
43
|
-
# require 'flickraw'
|
44
|
-
#
|
45
|
-
# FlickRaw.api_key = key
|
46
|
-
# FlickRaw.shared_secret = secret
|
47
|
-
#
|
48
|
-
# flickr.auth.checkToken(:auth_token => token)
|
49
|
-
#
|
50
|
-
# size = args[:size] || :small_square
|
51
|
-
#
|
52
|
-
# @url_for_photo = case size
|
53
|
-
# when :original
|
54
|
-
# lambda { |p| FlickRaw.url_o(p) }
|
55
|
-
# when :large
|
56
|
-
# lambda { |p| FlickRaw.url_b(p) }
|
57
|
-
# when :medium_640
|
58
|
-
# lambda { |p| FlickRaw.url_z(p) }
|
59
|
-
# when :medium_500
|
60
|
-
# lambda { |p| FlickRaw.url(p) }
|
61
|
-
# when :small
|
62
|
-
# lambda { |p| FlickRaw.url_m(p) }
|
63
|
-
# when :thumb
|
64
|
-
# lambda { |p| FlickRaw.url_t(p) }
|
65
|
-
# when :small_square
|
66
|
-
# lambda { |p| FlickRaw.url_s(p) }
|
67
|
-
# else
|
68
|
-
# raise Exception("unrecognized size: #{size}")
|
69
|
-
# end
|
70
|
-
# end
|
71
|
-
#
|
72
|
-
# def get_photoset(pset_id)
|
73
|
-
# flickr.photosets.getInfo(:photoset_id => pset_id)
|
74
|
-
# end
|
75
|
-
#
|
76
|
-
# def each_photoset
|
77
|
-
# flickr.photosets.getList.each do |pset|
|
78
|
-
# yield pset
|
79
|
-
# end
|
80
|
-
# end
|
81
|
-
#
|
82
|
-
# def download_photoset(photoset, output_dir)
|
83
|
-
# dirname = Squarepusher.normalize(photoset.title)
|
84
|
-
# set_dir = File.join(output_dir, dirname)
|
85
|
-
# $fileutils.mkdir_p set_dir
|
86
|
-
#
|
87
|
-
# # handles socket timeout when loading photoset info
|
88
|
-
# results = {}
|
89
|
-
# status, photoset_result = handle_error { flickr.photosets.getPhotos(:photoset_id => photoset.id, :extras => "original_format,url_o")["photo"] }
|
90
|
-
# if status == :error
|
91
|
-
# error photoset_result
|
92
|
-
# results[status] = 1
|
93
|
-
# return results
|
94
|
-
# else
|
95
|
-
# photos = photoset_result
|
96
|
-
# end
|
97
|
-
#
|
98
|
-
# photos.each do |p|
|
99
|
-
# # puts p.inspect
|
100
|
-
#
|
101
|
-
# # TODO: use name of file in url since titles can be duplicate
|
102
|
-
# # copies string?
|
103
|
-
# name = "#{p.id}"
|
104
|
-
# if not p.title.empty?
|
105
|
-
# normalized_title = Squarepusher.normalize(p.title)
|
106
|
-
# name << "-#{normalized_title}"
|
107
|
-
# end
|
108
|
-
#
|
109
|
-
# url = @url_for_photo[p]
|
110
|
-
#
|
111
|
-
# # TODO: only add .jpg suffix if it's not in the image name already
|
112
|
-
# path = File.join(set_dir, name)
|
113
|
-
# path << ".jpg" if not path =~ /.jpg$/
|
114
|
-
#
|
115
|
-
# if not @overwrite and File.exists?(path)
|
116
|
-
# puts "#{path} exists; skipping"
|
117
|
-
# result = :exists
|
118
|
-
# else
|
119
|
-
# result = download_image(url, path)
|
120
|
-
# end
|
121
|
-
#
|
122
|
-
# if results.has_key?(result)
|
123
|
-
# results[result] = results[result] + 1
|
124
|
-
# else
|
125
|
-
# results[result] = 1
|
126
|
-
# end
|
127
|
-
# end
|
128
|
-
# results
|
129
|
-
# end
|
130
|
-
#
|
131
|
-
# private
|
132
|
-
#
|
133
|
-
# # was originally sending this to stderr, but the difference in flushing between
|
134
|
-
# # stdout and stderr was creating logging confusion
|
135
|
-
# def error(msg)
|
136
|
-
# puts "ERROR: #{msg}"
|
137
|
-
# end
|
138
|
-
#
|
139
|
-
# def download_image(url, path, args={})
|
140
|
-
# if url == UNAVAILABLE_URL
|
141
|
-
# redirects = args[:redirects]
|
142
|
-
# msg = "#{url} unavailable"
|
143
|
-
# msg << "; redirects: #{redirects}" if not redirects.nil?
|
144
|
-
# puts msg
|
145
|
-
# return :unavailable
|
146
|
-
# end
|
147
|
-
#
|
148
|
-
# result = :unknown
|
149
|
-
# uri = URI.parse(url)
|
150
|
-
# begin
|
151
|
-
# Net::HTTP.start(uri.host, uri.port) do |http|
|
152
|
-
# full_path = uri.request_uri
|
153
|
-
# response = http.get(full_path)
|
154
|
-
#
|
155
|
-
# # puts response.inspect
|
156
|
-
# case response
|
157
|
-
# when Net::HTTPError
|
158
|
-
# result = :error
|
159
|
-
# when Net::HTTPFound
|
160
|
-
# redirects = args[:redirects] || []
|
161
|
-
# redirects << url
|
162
|
-
# location = response["location"]
|
163
|
-
# if not location =~ /^http.*/
|
164
|
-
# location = "#{uri.scheme}://#{uri.host}:#{uri.port}#{location}"
|
165
|
-
# end
|
166
|
-
# result = download_image(location, path, :redirects => redirects)
|
167
|
-
# else
|
168
|
-
# puts "#{url} -> #{path}"
|
169
|
-
# if @verbose
|
170
|
-
# response.each_header do |k, v|
|
171
|
-
# puts "#{k}: #{v}"
|
172
|
-
# end
|
173
|
-
# puts
|
174
|
-
# end
|
175
|
-
#
|
176
|
-
# # detects weird 404 or 504 responses included in body but not HTTP status
|
177
|
-
# content_type = response["content-type"]
|
178
|
-
# if not (content_type =~ /text\/\w+/).nil?
|
179
|
-
# error "unexpected content type: #{content_type}"
|
180
|
-
# result = :error
|
181
|
-
# else
|
182
|
-
# open(path, 'w') do |out|
|
183
|
-
# out << response.body
|
184
|
-
# end
|
185
|
-
# result = :success
|
186
|
-
# end
|
187
|
-
# end
|
188
|
-
# end
|
189
|
-
# rescue Exception => e
|
190
|
-
# error e
|
191
|
-
# result = :error
|
192
|
-
# end
|
193
|
-
#
|
194
|
-
# return result
|
195
|
-
# end
|
196
|
-
#
|
197
|
-
# def handle_error
|
198
|
-
# raise Exception("block required") if not block_given?
|
199
|
-
# begin
|
200
|
-
# block_result = yield
|
201
|
-
# result = [:success, block_result]
|
202
|
-
# rescue
|
203
|
-
# result = [:error, $!]
|
204
|
-
# end
|
205
|
-
# return result
|
206
|
-
# end
|
207
|
-
#
|
208
|
-
# end
|
209
|
-
#
|
210
|
-
# end
|
3
|
+
require 'squarepusher/version'
|
data/lib/squarepusher/cli.rb
CHANGED
@@ -18,35 +18,13 @@ class CLI
|
|
18
18
|
exit code
|
19
19
|
end
|
20
20
|
|
21
|
-
def parse_config(path)
|
22
|
-
parsed = nil
|
23
|
-
open(path) do |stream|
|
24
|
-
parsed = YAML.load(stream)
|
25
|
-
end
|
26
|
-
if not parsed.respond_to?(:has_key?)
|
27
|
-
raise Exception.new("invalid YAML in #{path}; parsed #{parsed.inspect}")
|
28
|
-
end
|
29
|
-
puts "parsed config: #{parsed.inspect}"
|
30
|
-
required_keys = ['key', 'secret', 'token', 'token_secret']
|
31
|
-
missing_keys = []
|
32
|
-
vals = []
|
33
|
-
required_keys.each do |k|
|
34
|
-
v = parsed.fetch(k, nil)
|
35
|
-
if not v.nil?
|
36
|
-
vals << v
|
37
|
-
else
|
38
|
-
missing_keys << k
|
39
|
-
end
|
40
|
-
end
|
41
|
-
if not missing_keys.empty?
|
42
|
-
raise Exception.new("missing keys in #{path}: #{missing_keys.inspect}")
|
43
|
-
end
|
44
|
-
vals
|
45
|
-
end
|
46
|
-
|
47
21
|
def main
|
48
22
|
actions = {}
|
49
23
|
|
24
|
+
actions[:get_full_token] = lambda do |client, args|
|
25
|
+
puts "hi"
|
26
|
+
end
|
27
|
+
|
50
28
|
actions[:list_sets] = lambda do |client, args|
|
51
29
|
client.each_photoset do |pset|
|
52
30
|
puts Squarepusher.describe_photoset(pset)
|
@@ -113,7 +91,7 @@ class CLI
|
|
113
91
|
OptionParser.new do |opts|
|
114
92
|
opts.banner = "USAGE: squarepusher [options] <action:(#{action_str(actions)})> [args]"
|
115
93
|
|
116
|
-
opts.on("-c", "--config", "path to config file (defaults to #{config_path})") do |v|
|
94
|
+
opts.on("-c", "--config PATH", "path to config file (defaults to #{config_path})") do |v|
|
117
95
|
options[:config] = v
|
118
96
|
end
|
119
97
|
|
@@ -121,6 +99,10 @@ class CLI
|
|
121
99
|
options[:overwrite] = v
|
122
100
|
end
|
123
101
|
|
102
|
+
opts.on("-p", "--privacy-filter LEVEL", "privacy level of photos to download") do |v|
|
103
|
+
options[:privacy] = v
|
104
|
+
end
|
105
|
+
|
124
106
|
opts.on("-s", "--size SIZE", "size of photos to download (#{size_str()})") do |v|
|
125
107
|
options[:size] = v.to_sym
|
126
108
|
end
|
@@ -152,8 +134,8 @@ class CLI
|
|
152
134
|
puts "parsing #{config_path}"
|
153
135
|
end
|
154
136
|
|
155
|
-
key, secret, token, token_secret
|
156
|
-
client = Squarepusher::Client.
|
137
|
+
# client = Squarepusher::Client.from_config_path(key, secret, token, token_secret, options)
|
138
|
+
client = Squarepusher::Client.from_config_path(config_path, options)
|
157
139
|
end
|
158
140
|
|
159
141
|
puts "args: #{args.inspect}"
|
data/lib/squarepusher/core.rb
CHANGED
@@ -21,18 +21,113 @@ module Squarepusher
|
|
21
21
|
def normalize(name)
|
22
22
|
name.gsub(/[^a-zA-Z0-9_+\.=-]+/, '-')
|
23
23
|
end
|
24
|
+
|
25
|
+
def owner_page_url(p)
|
26
|
+
# TODO: maybe abstract this to allow ownername to be passed in as a parameter
|
27
|
+
if p.respond_to?(:owner)
|
28
|
+
owner = p.owner
|
29
|
+
if owner.respond_to?(:username)
|
30
|
+
ownername = p.owner.username
|
31
|
+
else
|
32
|
+
ownername = owner
|
33
|
+
end
|
34
|
+
else
|
35
|
+
raise Exception("photo does not contain 'owner' attribute: #{p.inspect}")
|
36
|
+
end
|
37
|
+
|
38
|
+
"http://flickr.com/photos/#{ownername}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def photo_page_url(p)
|
42
|
+
owner_page_url = Squarepusher::owner_page_url(p)
|
43
|
+
"#{owner_page_url}/#{p.id}"
|
44
|
+
end
|
24
45
|
|
25
46
|
def sizes
|
26
47
|
return [:original, :large, :medium_640, :medium_500, :small, :thumb, :small_square]
|
27
48
|
end
|
49
|
+
|
50
|
+
def url_for(photo, size)
|
51
|
+
case size
|
52
|
+
when :original
|
53
|
+
FlickRaw.url_o(photo)
|
54
|
+
when :large
|
55
|
+
FlickRaw.url_b(photo)
|
56
|
+
when :medium_640
|
57
|
+
FlickRaw.url_z(photo)
|
58
|
+
when :medium_500
|
59
|
+
FlickRaw.url(photo)
|
60
|
+
when :small
|
61
|
+
FlickRaw.url_m(photo)
|
62
|
+
when :thumb
|
63
|
+
FlickRaw.url_t(photo)
|
64
|
+
when :small_square
|
65
|
+
FlickRaw.url_s(photo)
|
66
|
+
end
|
67
|
+
end
|
28
68
|
|
29
69
|
end
|
30
70
|
|
31
71
|
class Client
|
32
72
|
|
73
|
+
class << self
|
74
|
+
|
75
|
+
def from_config_path(path, args={})
|
76
|
+
open(path) do |stream|
|
77
|
+
from_config_stream(stream, args)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def from_config_stream(stream, args={})
|
82
|
+
key, secret, token, token_secret = parse_config_stream(stream)
|
83
|
+
Squarepusher::Client.new(key, secret, token, token_secret, args)
|
84
|
+
end
|
85
|
+
|
86
|
+
def parse_config_stream(stream)
|
87
|
+
parsed = YAML.load(stream)
|
88
|
+
if not parsed.respond_to?(:has_key?)
|
89
|
+
raise Exception.new("invalid YAML in #{path}; parsed #{parsed.inspect}")
|
90
|
+
end
|
91
|
+
puts "parsed config: #{parsed.inspect}"
|
92
|
+
required_keys = ['key', 'secret', 'token', 'token_secret']
|
93
|
+
missing_keys = []
|
94
|
+
vals = []
|
95
|
+
required_keys.each do |k|
|
96
|
+
v = parsed.fetch(k, nil)
|
97
|
+
if not v.nil?
|
98
|
+
vals << v
|
99
|
+
else
|
100
|
+
missing_keys << k
|
101
|
+
end
|
102
|
+
end
|
103
|
+
if not missing_keys.empty?
|
104
|
+
raise Exception.new("missing keys in #{path}: #{missing_keys.inspect}")
|
105
|
+
end
|
106
|
+
vals
|
107
|
+
end
|
108
|
+
|
109
|
+
end # end class << self
|
110
|
+
|
111
|
+
# optional items for args:
|
112
|
+
# :overwrite - overwrite local files
|
113
|
+
# :verbose - verbose logging
|
114
|
+
# :privacy - privacy level for requests
|
115
|
+
# :event_listener - listener object that must provide "event" method
|
33
116
|
def initialize(key, secret, token, token_secret, args={})
|
34
117
|
@overwrite = args[:overwrite] || false
|
35
118
|
@verbose = args[:verbose] || false
|
119
|
+
@privacy = args[:privacy] || 5
|
120
|
+
|
121
|
+
@event_listener = args[:event_listener] || nil
|
122
|
+
|
123
|
+
if not @event_listener.nil?
|
124
|
+
if not @event_listener.respond_to?(:event)
|
125
|
+
puts "ignoring event listener #{@event_listener}; does not provide :event method"
|
126
|
+
@event_listener = nil
|
127
|
+
else
|
128
|
+
puts "using event listener #{@event_listener}"
|
129
|
+
end
|
130
|
+
end
|
36
131
|
|
37
132
|
FlickRawOptions['timeout'] = args[:timeout] || 5
|
38
133
|
|
@@ -47,6 +142,7 @@ module Squarepusher
|
|
47
142
|
|
48
143
|
size = args[:size] || :small_square
|
49
144
|
|
145
|
+
# TODO: use url_for() method
|
50
146
|
@url_for_photo = case size
|
51
147
|
when :original
|
52
148
|
lambda { |p| FlickRaw.url_o(p) }
|
@@ -66,17 +162,67 @@ module Squarepusher
|
|
66
162
|
raise Exception("unrecognized size: #{size}")
|
67
163
|
end
|
68
164
|
end
|
165
|
+
|
166
|
+
def get_photo(photo_id)
|
167
|
+
flickr.photos.getInfo(:photo_id => photo_id)
|
168
|
+
end
|
69
169
|
|
70
170
|
def get_photoset(pset_id)
|
71
171
|
flickr.photosets.getInfo(:photoset_id => pset_id)
|
72
172
|
end
|
73
173
|
|
174
|
+
def get_photos_for_set(pset_id, params = {})
|
175
|
+
params[:photoset_id] = pset_id
|
176
|
+
flickr.photosets.getPhotos(params)
|
177
|
+
end
|
178
|
+
|
74
179
|
def each_photoset
|
75
180
|
flickr.photosets.getList.each do |pset|
|
76
181
|
yield pset
|
77
182
|
end
|
78
183
|
end
|
79
184
|
|
185
|
+
def search_by_tags(user_id, tags, args={})
|
186
|
+
args[:user_id] = user_id
|
187
|
+
args[:tags] = tags
|
188
|
+
return flickr.photos.search(args)
|
189
|
+
end
|
190
|
+
|
191
|
+
def random_favorite_of_mine(args={})
|
192
|
+
# TODO: find a clean way to select a random page
|
193
|
+
# may need to allow client to pass in context object to store
|
194
|
+
# page count, which could be persisted by client to disk, cache, db, etc.
|
195
|
+
faves = flickr.favorites.getList(args)
|
196
|
+
raise Exception.new("no favorites found") if faves.size == 0
|
197
|
+
|
198
|
+
faves_hash = faves.to_hash
|
199
|
+
# puts "hash: #{faves_hash.inspect}"
|
200
|
+
photos = faves_hash["photo"]
|
201
|
+
pages = faves_hash["pages"]
|
202
|
+
|
203
|
+
fire_event(:domain => :flickr, :user => :self, :favorite_page_count => pages)
|
204
|
+
|
205
|
+
choice = photos[rand(photos.size)]
|
206
|
+
|
207
|
+
choice
|
208
|
+
end
|
209
|
+
|
210
|
+
def download_favorites(output_dir, page=1, &photo_call)
|
211
|
+
puts "page: #{page}"
|
212
|
+
count = 0
|
213
|
+
flickr.favorites.getList(:page => page, :extras => 'owner_name, original_format').each do |p|
|
214
|
+
ext = if p.respond_to?(:original_format) then p.originalformat else "jpg" end
|
215
|
+
path = "#{output_dir}/#{p.owner}-#{p.id}.#{ext}"
|
216
|
+
count += 1
|
217
|
+
next if not @overwrite and File.exists?(path)
|
218
|
+
u = Squarepusher.url_for(p, :medium_640)
|
219
|
+
download_image(u, path)
|
220
|
+
if block_given? then photo_call.call(p, u, path) end
|
221
|
+
end
|
222
|
+
puts "count: #{count}"
|
223
|
+
if count == 100 then download_favorites(output_dir, page+1, &photo_call) end
|
224
|
+
end
|
225
|
+
|
80
226
|
def download_photoset(photoset, output_dir)
|
81
227
|
dirname = Squarepusher.normalize(photoset.title)
|
82
228
|
set_dir = File.join(output_dir, dirname)
|
@@ -84,7 +230,9 @@ module Squarepusher
|
|
84
230
|
|
85
231
|
# handles socket timeout when loading photoset info
|
86
232
|
results = {}
|
87
|
-
status, photoset_result = handle_error { flickr.photosets.getPhotos(:photoset_id => photoset.id,
|
233
|
+
status, photoset_result = handle_error { flickr.photosets.getPhotos(:photoset_id => photoset.id,
|
234
|
+
:privacy_filter => @privacy,
|
235
|
+
:extras => "original_format,url_o")["photo"] }
|
88
236
|
if status == :error
|
89
237
|
error photoset_result
|
90
238
|
results[status] = 1
|
@@ -126,6 +274,10 @@ module Squarepusher
|
|
126
274
|
|
127
275
|
private
|
128
276
|
|
277
|
+
def fire_event(args={})
|
278
|
+
@event_listener.event(args) unless @event_listener.nil?
|
279
|
+
end
|
280
|
+
|
129
281
|
# was originally sending this to stderr, but the difference in flushing between
|
130
282
|
# stdout and stderr was creating logging confusion
|
131
283
|
def error(msg)
|
data/lib/squarepusher/version.rb
CHANGED
metadata
CHANGED
@@ -1,45 +1,37 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: squarepusher
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 0
|
8
|
-
- 4
|
9
|
-
version: 0.0.4
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
6
|
+
authors:
|
12
7
|
- mhawthorne
|
13
8
|
autorequire:
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2013-09-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: flickraw
|
22
|
-
|
23
|
-
|
24
|
-
none: false
|
25
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
26
17
|
- - ">="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
- 0
|
30
|
-
version: "0"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
31
20
|
type: :runtime
|
32
|
-
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
33
27
|
description:
|
34
28
|
email: mhawthorne@gmail.com
|
35
|
-
executables:
|
29
|
+
executables:
|
36
30
|
- squarepusher
|
37
31
|
extensions: []
|
38
|
-
|
39
32
|
extra_rdoc_files: []
|
40
|
-
|
41
|
-
|
42
|
-
- .gitignore
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
43
35
|
- Gemfile
|
44
36
|
- README.md
|
45
37
|
- Rakefile
|
@@ -49,37 +41,27 @@ files:
|
|
49
41
|
- lib/squarepusher/core.rb
|
50
42
|
- lib/squarepusher/version.rb
|
51
43
|
- squarepusher.gemspec
|
52
|
-
has_rdoc: true
|
53
44
|
homepage: https://github.com/mhawthorne/squarepusher
|
54
45
|
licenses: []
|
55
|
-
|
46
|
+
metadata: {}
|
56
47
|
post_install_message:
|
57
48
|
rdoc_options: []
|
58
|
-
|
59
|
-
require_paths:
|
49
|
+
require_paths:
|
60
50
|
- lib
|
61
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
-
|
63
|
-
requirements:
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
64
53
|
- - ">="
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
|
-
requirements:
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
72
58
|
- - ">="
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
- 0
|
76
|
-
version: "0"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
77
61
|
requirements: []
|
78
|
-
|
79
62
|
rubyforge_project: nowarning
|
80
|
-
rubygems_version:
|
63
|
+
rubygems_version: 2.0.3
|
81
64
|
signing_key:
|
82
|
-
specification_version:
|
65
|
+
specification_version: 4
|
83
66
|
summary: downloads photos from flickr
|
84
67
|
test_files: []
|
85
|
-
|