picasa-downloader 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +4 -0
- data/TODO.md +0 -1
- data/lib/picasa-downloader/album_persister.rb +18 -14
- data/lib/picasa-downloader/photo_helper.rb +8 -0
- data/picasa-downloader.gemspec +1 -1
- data/spec/album_persister_spec.rb +0 -2
- data/spec/client_spec.rb +1 -3
- data/spec/env_credentials_spec.rb +0 -1
- data/spec/photo_helper_spec.rb +26 -0
- data/spec/test_helper.rb +2 -0
- metadata +5 -2
data/.gitignore
CHANGED
data/README.md
CHANGED
data/TODO.md
CHANGED
@@ -8,26 +8,30 @@ module PicasaDownloader
|
|
8
8
|
|
9
9
|
def download
|
10
10
|
FileUtils.mkdir_p(get_temp_album_dir)
|
11
|
-
@client.list_photos(@album.id)
|
11
|
+
photos = @client.list_photos(@album.id)
|
12
|
+
download_and_persist_to_disk(photos)
|
13
|
+
move_to_final_dir(photos)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def download_and_persist_to_disk(photos)
|
19
|
+
def persist_to_disk(photo, photo_data)
|
20
|
+
File.open(get_temp_album_dir + photo.name, 'wb') { |file|
|
21
|
+
file.write(photo_data)
|
22
|
+
FileUtils.touch(file.path, :mtime => photo.created_date)
|
23
|
+
}
|
24
|
+
end
|
25
|
+
photos.each { |photo|
|
12
26
|
photo_data = @client.download_photo(photo)
|
13
27
|
if photo_data
|
14
|
-
|
15
|
-
file.write(photo_data)
|
16
|
-
FileUtils.touch(file.path, :mtime => photo.created_date)
|
17
|
-
}
|
28
|
+
persist_to_disk(photo, photo_data)
|
18
29
|
end
|
19
30
|
}
|
20
|
-
move_to_final_dir
|
21
31
|
end
|
22
32
|
|
23
|
-
|
24
|
-
|
25
|
-
def move_to_final_dir
|
26
|
-
file_modified_years = Dir.entries(get_temp_album_dir).map { |file|
|
27
|
-
File.new(get_temp_album_dir + file).mtime.year
|
28
|
-
}.reject { |year| year == nil }
|
29
|
-
album_min_year = file_modified_years.min
|
30
|
-
final_dir = get_final_album_dir_root(album_min_year)
|
33
|
+
def move_to_final_dir(photos)
|
34
|
+
final_dir = get_final_album_dir_root(PhotoHelper.median_year(photos))
|
31
35
|
FileUtils.mkdir_p(final_dir)
|
32
36
|
FileUtils.mv(get_temp_album_dir, final_dir)
|
33
37
|
end
|
data/picasa-downloader.gemspec
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module PicasaDownloader
|
4
|
+
describe PhotoHelper do
|
5
|
+
it "calculates median year for one photo" do
|
6
|
+
photo1 = double('photo')
|
7
|
+
photo1.stub('created_date' => Time.utc(2008, 7, 8))
|
8
|
+
PhotoHelper.median_year([photo1]).should be 2008
|
9
|
+
end
|
10
|
+
|
11
|
+
it "calculates median year for five photos" do
|
12
|
+
photo1 = double('photo')
|
13
|
+
photo1.stub('created_date' => Time.utc(2000, 7, 8))
|
14
|
+
photo2 = double('photo')
|
15
|
+
photo2.stub('created_date' => Time.utc(2003, 7, 8))
|
16
|
+
photo3 = double('photo')
|
17
|
+
photo3.stub('created_date' => Time.utc(2009, 7, 8))
|
18
|
+
photo4 = double('photo')
|
19
|
+
photo4.stub('created_date' => Time.utc(2010, 7, 8))
|
20
|
+
photo5 = double('photo')
|
21
|
+
photo5.stub('created_date' => Time.utc(2011, 7, 8))
|
22
|
+
PhotoHelper.median_year([photo1, photo2, photo3, photo4, photo5]).should
|
23
|
+
be 2009
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: picasa-downloader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: gdata_19
|
@@ -199,10 +199,12 @@ files:
|
|
199
199
|
- lib/picasa-downloader/env_credentials.rb
|
200
200
|
- lib/picasa-downloader/errors.rb
|
201
201
|
- lib/picasa-downloader/photo.rb
|
202
|
+
- lib/picasa-downloader/photo_helper.rb
|
202
203
|
- picasa-downloader.gemspec
|
203
204
|
- spec/album_persister_spec.rb
|
204
205
|
- spec/client_spec.rb
|
205
206
|
- spec/env_credentials_spec.rb
|
207
|
+
- spec/photo_helper_spec.rb
|
206
208
|
- spec/test_helper.rb
|
207
209
|
homepage: https://github.com/laurilehmijoki/picasa-downloader
|
208
210
|
licenses:
|
@@ -237,4 +239,5 @@ test_files:
|
|
237
239
|
- spec/album_persister_spec.rb
|
238
240
|
- spec/client_spec.rb
|
239
241
|
- spec/env_credentials_spec.rb
|
242
|
+
- spec/photo_helper_spec.rb
|
240
243
|
- spec/test_helper.rb
|