multistockphoto 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,4 @@
1
1
  require 'net/ftp'
2
- require 'grep'
3
- include Grep
4
2
 
5
3
  class Dreamstime < GenericSite
6
4
 
@@ -12,17 +10,21 @@ class Dreamstime < GenericSite
12
10
  FTP_HOST = 'upload.dreamstime.com'
13
11
  SITENAME = 'dreamstime'
14
12
  # Ftp Adresse: upload.dreamstime.com
15
- #Benutzername (Benutzer ID): 772816
16
- #Kennwort: das selbe wie Ihr Dreamstime Kontokennwort
13
+ #Benutzername (Benutzer ID): 772816
14
+ #Kennwort: das selbe wie Ihr Dreamstime Kontokennwort
17
15
 
18
16
  def initialize(name)
19
17
  super
20
18
  @config = load_config
21
- @user = @config[:dreamstime][:user]
22
- @password = @config[:dreamstime][:password]
23
- @ftp_user = @config[:dreamstime][:ftp_user]
24
- @ftp_password = @config[:dreamstime][:ftp_password]
25
- @total_per_day = @config[:dreamstime][:total_per_day]
19
+ begin
20
+ @user = @config[:dreamstime][:user]
21
+ @password = @config[:dreamstime][:password]
22
+ @ftp_user = @config[:dreamstime][:ftp_user]
23
+ @ftp_password = @config[:dreamstime][:ftp_password]
24
+ @total_per_day = @config[:dreamstime][:total_per_day]
25
+ rescue
26
+ puts 'cannot read configuration entries of '+SITENAME
27
+ end
26
28
  end
27
29
 
28
30
  def transfer(photo, dont_send=nil, dont_log=nil)
@@ -41,8 +43,7 @@ class Dreamstime < GenericSite
41
43
  end
42
44
  print "#{SITENAME}:#{photo.filename} ... "
43
45
  $stdout.flush
44
- g = grep(SENDLIST, /#{SITENAME}\t#{photo.filename}/)
45
- if g.size > 0
46
+ if already_sent_site?(photo,SITENAME)
46
47
  puts "already sent"
47
48
  return :duplicate
48
49
  end
@@ -58,15 +59,15 @@ class Dreamstime < GenericSite
58
59
  ftp.login(@ftp_user,@ftp_password)
59
60
  files=ftp.list('*')
60
61
  if photo.portrait?
61
- p photo.rotated_filename
62
+ #p photo.rotated_filename
62
63
  res = ftp.putbinaryfile(photo.rotated_filename)
63
64
  else
64
65
  res = ftp.putbinaryfile(photo.filename)
65
66
  end
66
67
  files =ftp.list('*')
67
- p files
68
+ #p files
68
69
  ftp.close
69
- rescue Errno::EPIPE
70
+ rescue Errno::EPIPE,Net::FTPTempError
70
71
  raise UploadException
71
72
  end
72
73
  end
@@ -96,6 +97,24 @@ class Dreamstime < GenericSite
96
97
  false
97
98
  end
98
99
 
100
+ # Site akzeptiert diese Extension
101
+ def self.accept?(ext)
102
+ ext = ext.downcase
103
+ if ext[0,1] == '.'
104
+ ext = ext[1..-1]
105
+ end
106
+ case ext
107
+ when 'jpg','jpeg'
108
+ return true
109
+ else
110
+ return false
111
+ end
112
+ end
113
+
114
+ def accept?(ext)
115
+ Dreamstime.accept?(ext)
116
+ end
117
+
99
118
  private
100
119
 
101
120
  def site_can_handle_keywords?
@@ -1,6 +1,4 @@
1
1
  require 'net/ftp'
2
- require 'grep'
3
- include Grep
4
2
 
5
3
  class Fotolia < GenericSite
6
4
 
@@ -15,11 +13,15 @@ class Fotolia < GenericSite
15
13
  def initialize(name)
16
14
  super
17
15
  @config = load_config
18
- @user = @config[:fotolia][:user]
19
- @password = @config[:fotolia][:password]
20
- @ftp_user = @config[:fotolia][:ftp_user]
21
- @ftp_password = @config[:fotolia][:ftp_password]
22
- @total_per_day = @config[:fotolia][:total_per_day]
16
+ begin
17
+ @user = @config[:fotolia][:user]
18
+ @password = @config[:fotolia][:password]
19
+ @ftp_user = @config[:fotolia][:ftp_user]
20
+ @ftp_password = @config[:fotolia][:ftp_password]
21
+ @total_per_day = @config[:fotolia][:total_per_day]
22
+ rescue
23
+ puts 'cannot read configuration entries of '+SITENAME
24
+ end
23
25
  end
24
26
 
25
27
  def transfer(photo, dont_send=nil, dont_log=nil)
@@ -38,8 +40,7 @@ class Fotolia < GenericSite
38
40
  end
39
41
  print "#{SITENAME}:#{photo.filename} ... "
40
42
  $stdout.flush
41
- g = grep(SENDLIST, /#{SITENAME}\t#{photo.filename}/)
42
- if g.size > 0
43
+ if already_sent_site?(photo,SITENAME)
43
44
  puts "already sent"
44
45
  return :duplicate
45
46
  end
@@ -63,7 +64,7 @@ class Fotolia < GenericSite
63
64
  files =ftp.list('*')
64
65
  #p files
65
66
  ftp.close
66
- rescue Errno::EPIPE
67
+ rescue Errno::EPIPE, Net::FTPTempError
67
68
  raise UploadException
68
69
  end
69
70
  end
@@ -93,6 +94,24 @@ class Fotolia < GenericSite
93
94
  false
94
95
  end
95
96
 
97
+ # Site akzeptiert diese Extension
98
+ def self.accept?(ext)
99
+ ext = ext.downcase
100
+ if ext[0,1] == '.'
101
+ ext = ext[1..-1]
102
+ end
103
+ case ext
104
+ when 'jpg','jpeg' #TODO: pruefen
105
+ return true
106
+ else
107
+ return false
108
+ end
109
+ end
110
+
111
+ def accept?(ext)
112
+ Fotolia.accept?(ext)
113
+ end
114
+
96
115
  private
97
116
 
98
117
  def site_can_handle_keywords?
@@ -1,7 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'mechanize'
3
- require 'grep'
4
- include Grep
5
3
 
6
4
  class Photocase < GenericSite
7
5
  SITENAME = 'photocase'
@@ -12,14 +10,19 @@ class Photocase < GenericSite
12
10
 
13
11
  def initialize(name)
14
12
  super
15
- if ENV['MSP_CONFIG']
16
- @config = YAML.load_file(ENV['MSP_CONFIG'])
17
- else
18
- @config = YAML.load_file("config.yaml")
13
+ # if ENV['MSP_CONFIG']
14
+ # @config = YAML.load_file(ENV['MSP_CONFIG'])
15
+ # else
16
+ # @config = YAML.load_file("config.yaml")
17
+ # end
18
+ @config = load_config
19
+ begin
20
+ @user = @config[:photocase][:user]
21
+ @password = @config[:photocase][:password]
22
+ @total_per_day = @config[:photocase][:total_per_day]
23
+ rescue
24
+ puts 'cannot read configuration entries of '+SITENAME
19
25
  end
20
- @user = @config[:photocase][:user]
21
- @password = @config[:photocase][:password]
22
- @total_per_day = @config[:photocase][:total_per_day]
23
26
  end
24
27
 
25
28
  def transfer(photo,dont_send=false,dont_log=false)
@@ -37,8 +40,7 @@ class Photocase < GenericSite
37
40
  end
38
41
  print "#{SITENAME}:#{photo.filename} ... "
39
42
  $stdout.flush
40
- g = grep(SENDLIST, /#{SITENAME}\t#{photo.filename}/)
41
- if g.size > 0
43
+ if already_sent_site?(photo,SITENAME)
42
44
  puts 'already sent'
43
45
  return :duplicate
44
46
  end
@@ -50,6 +52,7 @@ class Photocase < GenericSite
50
52
  end
51
53
 
52
54
  if ! dont_send
55
+ begin
53
56
  agent = WWW::Mechanize.new
54
57
  agent.user_agent_alias = 'Linux Mozilla'
55
58
  page = agent.get 'http://www.photocase.de/en/login.asp'
@@ -97,7 +100,11 @@ class Photocase < GenericSite
97
100
  raise "too many errors"
98
101
  end
99
102
  end
100
- else
103
+ rescue Net::HTTPInternalServerError, WWW::Mechanize::ResponseCodeError
104
+ # Net::HTTPInternalServerError (WWW::Mechanize::ResponseCodeError)
105
+ raise UploadException
106
+ end # rescue
107
+ else
101
108
  puts "OK"
102
109
  end
103
110
  #'Your photo was uploaded successfully.'
@@ -119,7 +126,7 @@ class Photocase < GenericSite
119
126
  return sent_today_site(site)
120
127
  end
121
128
 
122
- # wurde dieses Photo schon gesendet?
129
+ # wurde dieses Photo schon gesendet?
123
130
  def already_sent?(photo)
124
131
  already_sent_site?(photo,SITENAME)
125
132
  #
@@ -138,6 +145,24 @@ class Photocase < GenericSite
138
145
  false
139
146
  end
140
147
 
148
+ # Site akzeptiert diese Extension
149
+ def self.accept?(ext)
150
+ ext = ext.downcase
151
+ if ext[0,1] == '.'
152
+ ext = ext[1..-1]
153
+ end
154
+ case ext
155
+ when 'jpg','jpeg' #TODO: pruefen
156
+ return true
157
+ else
158
+ return false
159
+ end
160
+ end
161
+
162
+ def accept?(ext)
163
+ Photocase.accept?(ext)
164
+ end
165
+
141
166
  private
142
167
 
143
168
  def site_can_handle_keywords?
@@ -1,7 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'mechanize'
3
- require 'grep'
4
- include Grep
5
3
 
6
4
  class Zoonar < GenericSite
7
5
  SITENAME = 'zoonar'
@@ -12,14 +10,19 @@ class Zoonar < GenericSite
12
10
 
13
11
  def initialize(name)
14
12
  super
15
- if ENV['MSP_CONFIG']
16
- @config = YAML.load_file(ENV['MSP_CONFIG'])
17
- else
18
- @config = YAML.load_file("config.yaml")
13
+ # if ENV['MSP_CONFIG']
14
+ # @config = YAML.load_file(ENV['MSP_CONFIG'])
15
+ # else
16
+ # @config = YAML.load_file("config.yaml")
17
+ # end
18
+ @config = load_config
19
+ begin
20
+ @user = @config[:zoonar][:user]
21
+ @password = @config[:zoonar][:password]
22
+ @total_per_day = @config[:zoonar][:total_per_day]
23
+ rescue
24
+ puts 'cannot read configuration entries of '+SITENAME
19
25
  end
20
- @user = @config[:zoonar][:user]
21
- @password = @config[:zoonar][:password]
22
- @total_per_day = @config[:zoonar][:total_per_day]
23
26
  end
24
27
 
25
28
  # TODO: Bild gedreht senden, falls Hochformat
@@ -37,12 +40,12 @@ class Zoonar < GenericSite
37
40
  end
38
41
  print "#{SITENAME}:#{photo.filename} ... "
39
42
  $stdout.flush
40
- g = grep(SENDLIST, /#{SITENAME}\t#{photo.filename}/)
41
- if g.size > 0
43
+
44
+ if already_sent_site?(photo,SITENAME)
42
45
  puts 'already sent'
43
46
  return :duplicate
44
47
  end
45
- if photo.portrait? and ! Zoonar.can_handle_orientation?
48
+ if photo.portrait? and ! Zoonar.can_handle_orientation?
46
49
  photo.drehen
47
50
  end
48
51
 
@@ -53,11 +56,11 @@ class Zoonar < GenericSite
53
56
  unless dont_send
54
57
  agent = WWW::Mechanize.new
55
58
  agent.user_agent_alias = 'Linux Mozilla'
56
- begin
57
- page = agent.get 'http://www.zoonar.de'
58
- rescue WWW::Mechanize::ResponseCodeError
59
- raise UploadException
60
- end
59
+ begin
60
+ page = agent.get 'http://www.zoonar.de'
61
+ rescue WWW::Mechanize::ResponseCodeError
62
+ raise UploadException
63
+ end
61
64
  form = page.forms[1] #TODO: besser nach Name
62
65
  form['loginForm[Username]'] = @config[:zoonar][:user]
63
66
  form['loginForm[Password]'] = @config[:zoonar][:password]
@@ -129,11 +132,29 @@ Falls wir das Bild ablehnen sollten, werden Sie eine Benachrichtigung per E-Mail
129
132
  already_sent_site?(photo,SITENAME)
130
133
  end
131
134
 
132
- # can site handle orientation?
135
+ # can site handle orientation?
133
136
  def self.can_handle_orientation?
134
137
  false
135
138
  end
136
139
 
140
+ # Site akzeptiert diese Extension
141
+ def self.accept?(ext)
142
+ ext = ext.downcase
143
+ if ext[0,1] == '.'
144
+ ext = ext[1..-1]
145
+ end
146
+ case ext
147
+ when 'jpg','jpeg' # TODO: pruefen
148
+ return true
149
+ else
150
+ return false
151
+ end
152
+ end
153
+
154
+ def accept?(ext)
155
+ Zoonar.accept?(ext)
156
+ end
157
+
137
158
  private
138
159
 
139
160
  def site_can_handle_keywords?
@@ -1,8 +1,8 @@
1
1
  module Multistockphoto #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 7
5
- TINY = 1
4
+ MINOR = 8
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -16,6 +16,7 @@ require 'multistockphoto/site_zoonar'
16
16
  #require 'multistockphoto/site_aldi'
17
17
  require 'multistockphoto/site_photocase'
18
18
  require 'multistockphoto/site_dreamstime'
19
+ require 'multistockphoto/site_bigstockphoto'
19
20
 
20
21
 
21
22
  require 'multistockphoto/upload_exception'
@@ -28,6 +28,10 @@ class TestMultistockphoto < Test::Unit::TestCase
28
28
  ENV['DREAMSTIME_PASSWORD'] = 'mageheim'
29
29
  ENV['DREAMSTIME_FTP_USER'] = 'martha12345'
30
30
  ENV['DREAMSTIME_FTP_PASSWORD'] = 'ftpgeheimmartha'
31
+ ENV['BIGSTOCKPHOTO_USER'] = 'dennis'
32
+ ENV['BIGSTOCKPHOTO_PASSWORD'] = 'dennisgeheim'
33
+ ENV['BIGSTOCKPHOTO_FTP_USER'] = 'dennis12345'
34
+ ENV['BIGSTOCKPHOTO_FTP_PASSWORD'] = 'ftpgeheimdennis'
31
35
  @fotolia_user = ENV['FOTOLIA_USER']
32
36
  @fotolia_password = ENV['FOTOLIA_PASSWORD']
33
37
  @fotolia_ftp_user = ENV['FOTOLIA_FTP_USER']
@@ -42,6 +46,10 @@ class TestMultistockphoto < Test::Unit::TestCase
42
46
  @dreamstime_password = ENV['DREAMSTIME_PASSWORD']
43
47
  @dreamstime_ftp_user = ENV['DREAMSTIME_FTP_USER']
44
48
  @dreamstime_ftp_password = ENV['DREAMSTIME_FTP_PASSWORD']
49
+ @bigstockphoto_user = ENV['BIGSTOCKPHOTO_USER']
50
+ @bigstockphoto_password = ENV['BIGSTOCKPHOTO_PASSWORD']
51
+ @bigstockphoto_ftp_user = ENV['BIGSTOCKPHOTO_FTP_USER']
52
+ @bigstockphoto_ftp_password = ENV['BIGSTOCKPHOTO_FTP_PASSWORD']
45
53
  ENV['MSP_CONFIG'] = nil
46
54
  end
47
55
 
@@ -86,7 +94,7 @@ Options:
86
94
  end
87
95
 
88
96
  def test_bin_version
89
- expected = "multistockphoto 0.6.2\n"
97
+ expected = "multistockphoto 0.7.1\n"
90
98
  result = `#{BIN}multistockphoto -v`
91
99
  assert_equal expected, result
92
100
  result = `#{BIN}multistockphoto --version`
@@ -196,6 +204,18 @@ Options:
196
204
  assert_equal @dreamstime_ftp_password, dreamstime.ftp_password
197
205
  end
198
206
 
207
+ def test_config_params_bigstockphoto
208
+ bigstockphoto = Bigstockphoto.new("Bigstockphoto Site")
209
+ assert bigstockphoto.user
210
+ assert bigstockphoto.password
211
+ assert bigstockphoto.ftp_user
212
+ assert bigstockphoto.ftp_password
213
+ assert_equal @bigstockphoto_user, bigstockphoto.user
214
+ assert_equal @bigstockphoto_password, bigstockphoto.password
215
+ assert_equal @bigstockphoto_ftp_user, bigstockphoto.ftp_user
216
+ assert_equal @bigstockphoto_ftp_password, bigstockphoto.ftp_password
217
+ end
218
+
199
219
  def test_grep
200
220
  file = "test/testgrep.dat"
201
221
  content = "zoonar\tIMG1.jpg\n"+
@@ -245,34 +265,42 @@ Options:
245
265
  end # after
246
266
  end
247
267
 
248
- def test_dreamstime_object
249
- # angemeldet.
250
- # Ftp Adresse: upload.dreamstime.com
251
- #Benutzername (Benutzer ID): 772816
252
- #Kennwort: das selbe wie Ihr Dreamstime Kontokennwort
253
- dreamstime = Dreamstime.new("Dreamstime Site")
254
- assert_kind_of Dreamstime, dreamstime
255
- end
256
-
257
- after Date.new(2008,6,20) do
268
+ def test_dreamstime_object
269
+ # angemeldet.
270
+ dreamstime = Dreamstime.new("Dreamstime Site")
271
+ assert_kind_of Dreamstime, dreamstime
272
+ end
273
+
274
+ def test_bigstockphoto_object
275
+ # http://www.bigstockphoto.com/
276
+ # We accept JPG, EPS, AI, PSD, PDF and PNG file formats.
277
+ # All art or images MUST be created by you alone, no exceptions.
278
+ #Step ONE: Upload your model releases in Release Manager>> if needed... then FTP upload your images - no folders - separate files only. Use this FTP information to log into your BigStockPhoto FTP account:
279
+
280
+ # host: bigstockphoto.com
281
+ # username: your BSP username
282
+ # password: your BSP password
283
+
284
+ #Step TWO: After upload, go to your Uploaded Images Queue to add your keywords, assign releases, titles, descriptions, categories etc. before pushing them to final BigStockPhoto Approval Queue. Also see the new FTP Status Log if needed to check upload status of images.
285
+ bigstockphoto = Bigstockphoto.new("Bigstockphoto Site")
286
+ assert_kind_of Bigstockphoto, bigstockphoto
287
+ end
288
+
289
+ after Date.new(2008,6,30) do
258
290
  def test_shutterstock_object
259
291
  shutterstock = Shutterstock.new("Shutterstock Site")
260
292
  assert_kind_of Shutterstock, shutterstock
261
293
  end
262
294
  def test_istockphoto_object
263
- # angemeldet, aber man muß noch vorstellungsbilder hochladen
295
+ # angemeldet, aber man muß noch vorstellungsbilder hochladen
264
296
  istockphoto = Istockphoto.new("Istockphoto Site")
265
297
  assert_kind_of Istockphoto, istockphoto
266
298
  end
267
299
  def test_stockxpert_object
268
- # angemeldet, aber man muss noch vorstellungsbilder hochladen
300
+ # angemeldet, aber man muss noch vorstellungsbilder hochladen
269
301
  stockxpert = Stockxpert.new("Stockxpert Site")
270
302
  assert_kind_of Stockxpert, stockxpert
271
303
  end
272
- def test_bigstockphoto_object
273
- bigstockphoto = Bigstockphoto.new("Bigstockphoto Site")
274
- assert_kind_of Bigstockphoto, bigstockphoto
275
- end
276
304
  def test_Einszweidreirf_object
277
305
  einszweidreirf = Einszweidreirf.new("123rf Site")
278
306
  assert_kind_of Einszweidreirf, einszweidreirf
@@ -468,6 +496,11 @@ Options:
468
496
  site = Dreamstime.new('dreamstime')
469
497
  site.password = password
470
498
  assert_equal password, site.password
499
+
500
+ password = rand(1_000_000).to_s
501
+ site = Bigstockphoto.new('bigstockphoto')
502
+ site.password = password
503
+ assert_equal password, site.password
471
504
  end
472
505
 
473
506
  def test_password_equals
@@ -490,6 +523,11 @@ Options:
490
523
  site = Dreamstime.new('dreamstime')
491
524
  site.password = password
492
525
  assert_equal password, site.password
526
+
527
+ password = rand(1_000_000).to_s
528
+ site = Bigstockphoto.new('dreamstime')
529
+ site.password = password
530
+ assert_equal password, site.password
493
531
  end
494
532
 
495
533
  after Date.new(2008,7,15) do
@@ -609,7 +647,8 @@ photocase:upload/3.gif ... OK
609
647
 
610
648
  def test_active_sites
611
649
  sender = Sender.new("Thomas")
612
- assert_equal [:fotolia, :zoonar, :photocase, :dreamstime], sender.active_sites
650
+ assert_equal [:fotolia, :zoonar, :photocase, :dreamstime, :bigstockphoto],
651
+ sender.active_sites
613
652
  end
614
653
 
615
654
  def test_upload_dir
@@ -667,5 +706,46 @@ photocase:upload/3.gif ... OK
667
706
  assert ! sender.sent_to?("upload/IMG_9999.JPG", :fotolia)
668
707
  end
669
708
 
709
+ def test_accepted_fileformats
710
+ #site = Bigstockphoto.new("bigstockphoto")
711
+ #We accept JPG, EPS, AI, PSD, PDF and PNG file formats.
712
+ assert Bigstockphoto.accept?("JPG")
713
+ assert Bigstockphoto.accept?("JPEG")
714
+ assert Bigstockphoto.accept?("EPS")
715
+ assert Bigstockphoto.accept?("AI")
716
+ assert Bigstockphoto.accept?("PSD")
717
+ assert Bigstockphoto.accept?("PDF")
718
+ assert Bigstockphoto.accept?("PNG")
719
+ assert ! Bigstockphoto.accept?("lalala")
720
+
721
+ assert Bigstockphoto.accept?(".JPG")
722
+ assert Bigstockphoto.accept?(".JPEG")
723
+ assert Bigstockphoto.accept?(".EPS")
724
+ assert Bigstockphoto.accept?(".AI")
725
+ assert Bigstockphoto.accept?(".PSD")
726
+ assert Bigstockphoto.accept?(".PDF")
727
+ assert Bigstockphoto.accept?(".PNG")
728
+ assert ! Bigstockphoto.accept?(".lalala")
729
+
730
+ assert Bigstockphoto.accept?("jpg")
731
+ assert Bigstockphoto.accept?("Jpeg")
732
+ assert Bigstockphoto.accept?("eps")
733
+ assert Bigstockphoto.accept?("ai")
734
+ assert Bigstockphoto.accept?("psd")
735
+ assert Bigstockphoto.accept?("pdf")
736
+ assert Bigstockphoto.accept?("Png")
737
+ assert ! Bigstockphoto.accept?("Lalala")
738
+
739
+
740
+
741
+
742
+ end
743
+
744
+ def test_translated_iptc_file_keywords
745
+ expected = 'Berlin,gwb,flower,bee'
746
+ photo = Photo.new(File.join('test','IMG_3602.JPG'))
747
+ photo.set_keywords(:de,:en)
748
+ assert_equal expected, photo.file_keywords
749
+ end
670
750
  end
671
751