flickrage 0.1.6 → 0.1.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/README.md +19 -17
- data/lib/flickrage.rb +1 -0
- data/lib/flickrage/cli.rb +12 -1
- data/lib/flickrage/entity/image_list.rb +4 -0
- data/lib/flickrage/service/downloader.rb +2 -7
- data/lib/flickrage/service/search.rb +19 -14
- data/lib/flickrage/version.rb +1 -1
- data/lib/flickrage/worker/resize.rb +1 -1
- data/lib/flickrage/worker/search.rb +13 -11
- 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: faf81a6b4b8f404e02724e29dbc23585b3c07ad4
|
4
|
+
data.tar.gz: 4efb363c436ef90d9b814d703863266c4a5592f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc0bd1e97a4e7bc5e882bec89eda6f2cad50fcf97b9d5df4d8d3277bce6e26a08d1ae82d6d359c675a9a4c6c258ec914b1232ceed9e8862cd1887a8bc257aa02
|
7
|
+
data.tar.gz: 53e3839d0ccf7304c7fd68c9560a63e8bab1b62dabe57597f867c8e53af8de0ba85d8907bb934db155391ad31fcdcc64afa899136ad9fa6904dcc8fff05dbe05
|
data/README.md
CHANGED
@@ -81,23 +81,25 @@ Provide your own words dictionary:
|
|
81
81
|
> $ flickrage help c
|
82
82
|
|
83
83
|
Options:
|
84
|
-
-k, --keywords=some nice grapefruit
|
85
|
-
[--max=10]
|
86
|
-
|
87
|
-
|
88
|
-
[--grid=2]
|
89
|
-
[--width=120]
|
90
|
-
[--height=80]
|
91
|
-
-l, [--log=/Users/someone/.flickrage/main.log]
|
92
|
-
-o, [--output=./tmp]
|
93
|
-
[--file-name=./some.png]
|
94
|
-
[--dict-path=/usr/share/dict/words]
|
95
|
-
-c, [--cleanup], [--no-cleanup]
|
96
|
-
-t, [--tagged-search], [--no-tagged-search]
|
97
|
-
-
|
98
|
-
-
|
99
|
-
|
100
|
-
[--flickr-
|
84
|
+
-k, --keywords=some nice grapefruit
|
85
|
+
[--max=10] # Select number of files.
|
86
|
+
# Default: 10
|
87
|
+
# Possible values: 1, ..., 20
|
88
|
+
[--grid=2] # Select grid base number.
|
89
|
+
[--width=120] # Set width for resize downloaded images.
|
90
|
+
[--height=80] # Set height for resize downloaded images.
|
91
|
+
-l, [--log=/Users/someone/.flickrage/main.log] # Log file path. By default logging is disabled.
|
92
|
+
-o, [--output=./tmp] # Output directory, where all data will be stored.
|
93
|
+
[--file-name=./some.png] # Name for file with collage.
|
94
|
+
[--dict-path=/usr/share/dict/words] # Path to file with multiline words (dictionary).
|
95
|
+
-c, [--cleanup], [--no-cleanup] # Cleanup files before collage.
|
96
|
+
-t, [--tagged-search], [--no-tagged-search] # Search by tags.
|
97
|
+
-p, [--params=safe_search:moderate sort:date-posted-desc] # Set extra params for Flickr.
|
98
|
+
-v, [--verbose], [--no-verbose] # Verbose mode.
|
99
|
+
-q, [--quiet], [--no-quiet] # Quiet mode. If don't need any messages and in console.
|
100
|
+
[--flickr-api-key=YOURLONGAPIKEY] # FLICKR_API_KEY. if you can't use environment.
|
101
|
+
[--flickr-shared-secret=YOURLONGSHAREDSECRET] # FLICKR_SHARED_SECRET. if you can't use environment.
|
102
|
+
|
101
103
|
|
102
104
|
`flickrage` is a tool which loves search on the Flickr & making collages from findings.
|
103
105
|
|
data/lib/flickrage.rb
CHANGED
data/lib/flickrage/cli.rb
CHANGED
@@ -116,6 +116,11 @@ module Flickrage
|
|
116
116
|
aliases: %w(-t),
|
117
117
|
type: :boolean,
|
118
118
|
desc: 'Search by tags.'
|
119
|
+
method_option :params,
|
120
|
+
type: :hash,
|
121
|
+
aliases: %w( -p ),
|
122
|
+
banner: 'safe_search:moderate sort:date-posted-desc',
|
123
|
+
desc: 'Set extra params for Flickr.'
|
119
124
|
method_option :verbose,
|
120
125
|
type: :boolean,
|
121
126
|
aliases: %w(-v),
|
@@ -202,11 +207,17 @@ module Flickrage
|
|
202
207
|
config.width = options['width'] if options['width']
|
203
208
|
config.height = options['height'] if options['height']
|
204
209
|
|
205
|
-
config.max = options['max'] if options['max']
|
206
210
|
config.grid = options['grid'] if options['grid']
|
207
211
|
config.output = options['output']
|
208
212
|
|
209
213
|
config.tagged_search = options['tagged_search']
|
214
|
+
config.search_params = options['params'] if options['params']
|
215
|
+
|
216
|
+
config.max = options['max'] if options['max']
|
217
|
+
if config.max < 3
|
218
|
+
STDERR.puts('Minimal value of max is: 3')
|
219
|
+
config.max = 3
|
220
|
+
end
|
210
221
|
end
|
211
222
|
end
|
212
223
|
|
@@ -24,9 +24,8 @@ module Flickrage
|
|
24
24
|
file.flock(File::LOCK_EX)
|
25
25
|
parse_file(uri, file)
|
26
26
|
end
|
27
|
-
|
27
|
+
ensure
|
28
28
|
FileUtils.rm_f(path) if File.size(path).zero?
|
29
|
-
raise e
|
30
29
|
end
|
31
30
|
|
32
31
|
def parse_file(uri, file, limit = Flickrage.config.download_timeout)
|
@@ -56,16 +55,12 @@ module Flickrage
|
|
56
55
|
end
|
57
56
|
|
58
57
|
def file_name(uri)
|
59
|
-
|
58
|
+
File.basename(uri.path)
|
60
59
|
end
|
61
60
|
|
62
61
|
def check_image(image)
|
63
62
|
File.exist?(image.local_path) ? image.finish_download : image
|
64
63
|
end
|
65
|
-
|
66
|
-
def nsec
|
67
|
-
Time.now.nsec
|
68
|
-
end
|
69
64
|
end
|
70
65
|
end
|
71
66
|
end
|
@@ -4,10 +4,13 @@ module Flickrage
|
|
4
4
|
class Search
|
5
5
|
include Flickrage::Helpers::Log
|
6
6
|
|
7
|
-
|
7
|
+
FLICKR_SIZES = %w(l o c z m)
|
8
|
+
|
9
|
+
attr_reader :tagged_search, :search_params
|
8
10
|
|
9
11
|
def initialize
|
10
12
|
@tagged_search = Flickrage.config.tagged_search
|
13
|
+
@search_params = Flickrage.config.search_params
|
11
14
|
end
|
12
15
|
|
13
16
|
def run(keyword)
|
@@ -24,15 +27,16 @@ module Flickrage
|
|
24
27
|
private
|
25
28
|
|
26
29
|
def image(result, keyword)
|
27
|
-
|
30
|
+
size = get_image_size(result)
|
31
|
+
return unless size
|
28
32
|
|
29
33
|
Flickrage::Entity::Image.new(
|
30
34
|
id: result.id,
|
31
35
|
title: title(result.title),
|
32
36
|
keyword: keyword,
|
33
|
-
url: result.
|
34
|
-
width: result.
|
35
|
-
height: result.
|
37
|
+
url: result.send(:"url_#{size}"),
|
38
|
+
width: result.send(:"width_#{size}"),
|
39
|
+
height: result.send(:"height_#{size}"),
|
36
40
|
)
|
37
41
|
end
|
38
42
|
|
@@ -45,22 +49,23 @@ module Flickrage
|
|
45
49
|
text[0..50] + '...'
|
46
50
|
end
|
47
51
|
|
52
|
+
def get_image_size(result)
|
53
|
+
FLICKR_SIZES.detect { |t| result.respond_to?(:"url_#{t}") }
|
54
|
+
end
|
55
|
+
|
48
56
|
def params(opts = {})
|
49
57
|
{
|
50
|
-
|
51
|
-
extras: 'url_l',
|
58
|
+
extras: 'url_m, url_z, url_c, url_l, url_o',
|
52
59
|
sort: 'interestingness-desc',
|
53
60
|
per_page: 1,
|
54
|
-
pages: 1
|
55
|
-
|
61
|
+
pages: 1,
|
62
|
+
media: 'photos',
|
63
|
+
accuracy: 1
|
64
|
+
}.merge(opts).merge(search_params)
|
56
65
|
end
|
57
66
|
|
58
67
|
def search_query(keyword)
|
59
|
-
|
60
|
-
{tags: [keyword]}
|
61
|
-
else
|
62
|
-
{text: keyword}
|
63
|
-
end
|
68
|
+
tagged_search ? {tags: [keyword]} : {text: keyword}
|
64
69
|
end
|
65
70
|
end
|
66
71
|
end
|
data/lib/flickrage/version.rb
CHANGED
@@ -7,12 +7,14 @@ module Flickrage
|
|
7
7
|
def call
|
8
8
|
keywords = opts['keywords']&.first(Flickrage.config.max) || %w()
|
9
9
|
|
10
|
-
keywords += sample_words(Flickrage.config.max - keywords.size) if keywords.size < Flickrage.config.max
|
11
|
-
keys = keywords.join(', ')
|
12
|
-
|
13
10
|
speaker.add_padding
|
14
11
|
logger.debug('Searching process')
|
15
|
-
logger.info("Received keywords: [#{
|
12
|
+
logger.info("Received keywords: [#{keywords.join(', ')}]")
|
13
|
+
|
14
|
+
keywords += sample_words(Flickrage.config.max - keywords.size)
|
15
|
+
keys = keywords.join(', ')
|
16
|
+
|
17
|
+
logger.info("Extended keywords: [#{keys}]")
|
16
18
|
|
17
19
|
@spin = spinner(message: 'Searching ')
|
18
20
|
|
@@ -21,8 +23,8 @@ module Flickrage
|
|
21
23
|
if image_list.valid?
|
22
24
|
spin.success
|
23
25
|
else
|
24
|
-
spin.error('(nothing found)')
|
25
|
-
raise Flickrage::SearchError
|
26
|
+
spin.error('(not enough images or nothing found)')
|
27
|
+
raise Flickrage::SearchError, 'Image list is not valid'
|
26
28
|
end
|
27
29
|
|
28
30
|
speaker.add_padding
|
@@ -55,15 +57,15 @@ module Flickrage
|
|
55
57
|
end
|
56
58
|
|
57
59
|
def service
|
58
|
-
@service ||= Service::Search
|
60
|
+
@service ||= Service::Search
|
59
61
|
end
|
60
62
|
|
61
63
|
def finder(keywords, spin, image_list = nil)
|
62
|
-
|
64
|
+
images = keywords.map do |k|
|
63
65
|
Concurrent
|
64
66
|
.future(thread_pool) do
|
65
67
|
update_spin(spin, title: "Searching (keyword: #{k})")
|
66
|
-
service.run(k)
|
68
|
+
service.new.run(k)
|
67
69
|
end
|
68
70
|
.then do |r|
|
69
71
|
update_spin(spin, title: "Searching (found image ID##{r.id})") if r
|
@@ -72,7 +74,7 @@ module Flickrage
|
|
72
74
|
.rescue { |_| nil }
|
73
75
|
end
|
74
76
|
|
75
|
-
result = Concurrent.zip(*
|
77
|
+
result = Concurrent.zip(*images).value
|
76
78
|
result = result.compact.flatten if result
|
77
79
|
|
78
80
|
if image_list
|
@@ -90,7 +92,7 @@ module Flickrage
|
|
90
92
|
not_founds = keywords - success_keywords
|
91
93
|
image_list.merge_not_founds(not_founds)
|
92
94
|
|
93
|
-
keywords = sample_words_strict(
|
95
|
+
keywords = sample_words_strict(image_list.estimate, except: image_list.not_founds)
|
94
96
|
return image_list if keywords.size.zero?
|
95
97
|
|
96
98
|
finder(keywords, spin, image_list)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flickrage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Merkulov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|