flickrage 0.1.6 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 847af86d9e43d42df3b1b988ac8a0d9bff7aff75
4
- data.tar.gz: 590ec13f794cb3a22b1d2182ddf76088e147c8c8
3
+ metadata.gz: faf81a6b4b8f404e02724e29dbc23585b3c07ad4
4
+ data.tar.gz: 4efb363c436ef90d9b814d703863266c4a5592f4
5
5
  SHA512:
6
- metadata.gz: de533e78326980bf3e4f91fd0eea9eab3c062c930c5cba58b5e856f7e856a9b0543bdb0f0779b1f1b82c6af5ab9709dbf4a0a3b37c053002be2bd6040d3a432d
7
- data.tar.gz: 5fa397e6a465cd2d82ca5c94c9d82f48edead68da0541001b2ee80cf2dce12776fa90b808e39e7496953ec3a6659242407f6df11b4e2e965e5eff023014be948
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] # 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 the file with collage.
94
- [--dict-path=/usr/share/dict/words] # Path to the 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
- -v, [--verbose], [--no-verbose] # Verbose mode.
98
- -q, [--quiet], [--no-quiet] # Quiet mode. If don't need any messages and in console.
99
- [--flickr-api-key=YOURLONGAPIKEY] # FLICKR_API_KEY. if you can't use environment.
100
- [--flickr-shared-secret=YOURLONGSHAREDSECRET] # FLICKR_SHARED_SECRET. if you can't use environment.
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
 
@@ -36,6 +36,7 @@ module Flickrage
36
36
  setting :search_timeout, 30
37
37
  setting :download_timeout, 10
38
38
 
39
+ setting :search_params, {}
39
40
  setting :grid, 2
40
41
  setting :max, 10
41
42
  setting :output
@@ -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
 
@@ -43,6 +43,10 @@ module Flickrage
43
43
  total == Flickrage.config.max
44
44
  end
45
45
 
46
+ def estimate
47
+ Flickrage.config.max - total
48
+ end
49
+
46
50
  def merge_not_founds(new_not_founds)
47
51
  @not_founds = not_founds + new_not_founds
48
52
  self
@@ -24,9 +24,8 @@ module Flickrage
24
24
  file.flock(File::LOCK_EX)
25
25
  parse_file(uri, file)
26
26
  end
27
- rescue => e
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
- "#{nsec}_" + File.basename(uri.path)
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
- attr_reader :tagged_search
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
- return unless result.respond_to?(:url_l)
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.url_l,
34
- width: result.width_l,
35
- height: result.height_l,
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
- content_type: '1',
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
- }.merge(opts)
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
- if tagged_search
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
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Flickrage
3
- VERSION = '0.1.6'
3
+ VERSION = '0.1.8'
4
4
  end
@@ -3,7 +3,7 @@ module Flickrage
3
3
  module Worker
4
4
  class Resize < Base
5
5
  MIN_IMAGE_SIZE = 100
6
- MAX_IMAGE_SIZE = 500
6
+ MAX_IMAGE_SIZE = 1000
7
7
 
8
8
  def call(image_list)
9
9
  raise Flickrage::ResizeError, 'Not enough images for resize' if image_list.downloaded&.size < 1
@@ -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: [#{keys}]")
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.new
60
+ @service ||= Service::Search
59
61
  end
60
62
 
61
63
  def finder(keywords, spin, image_list = nil)
62
- files = keywords.map do |k|
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(*files).value
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(not_founds&.size || 0, except: image_list.not_founds)
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.6
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-09 00:00:00.000000000 Z
11
+ date: 2016-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor