picasa-downloader 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.
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  *.gem
2
2
  Gemfile.lock
3
+ tmp
data/README.md CHANGED
@@ -23,6 +23,10 @@ Download all Picasa albums:
23
23
 
24
24
  `picasa-downloader all`
25
25
 
26
+ Download a particular album:
27
+
28
+ `picasa-downloader album "my album's name"`
29
+
26
30
  ## Development
27
31
 
28
32
  Run tests:
data/TODO.md CHANGED
@@ -2,6 +2,5 @@
2
2
 
3
3
  * Possibility to determine the target root directory via CLI
4
4
  * Cucumber tests for happy paths
5
- * Use median year to determine the target directory
6
5
  * Video download
7
6
  * Allow synchronising with online albums
@@ -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).each { |photo|
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
- File.open(get_temp_album_dir + photo.name, 'wb') { |file|
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
- private
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
@@ -0,0 +1,8 @@
1
+ module PicasaDownloader
2
+ class PhotoHelper
3
+ def self.median_year(photos)
4
+ years = photos.map { |photo| photo.created_date.year }
5
+ median = years[years.length / 2]
6
+ end
7
+ end
8
+ end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'picasa-downloader'
3
- s.version = '0.0.4'
3
+ s.version = '0.0.5'
4
4
  s.license = 'MIT'
5
5
  s.summary = 'Download your Google Picasa photo albums'
6
6
  s.description =
@@ -1,6 +1,4 @@
1
- require 'vcr'
2
1
  require 'test_helper'
3
- require_relative '../lib/picasa-downloader'
4
2
 
5
3
  module PicasaDownloader
6
4
  describe AlbumPersister do
@@ -1,6 +1,4 @@
1
- require 'vcr'
2
- require_relative 'test_helper'
3
- require_relative '../lib/picasa-downloader'
1
+ require 'test_helper'
4
2
 
5
3
  module PicasaDownloader
6
4
  describe Client do
@@ -1,5 +1,4 @@
1
1
  require 'test_helper'
2
- require_relative '../lib/picasa-downloader'
3
2
 
4
3
  module PicasaDownloader
5
4
  describe EnvCredentials do
@@ -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
@@ -1,4 +1,6 @@
1
+ require 'vcr'
1
2
  require 'require_relative'
3
+ require_relative '../lib/picasa-downloader'
2
4
 
3
5
  VCR.configure do |config|
4
6
  config.cassette_library_dir = "fixtures/cassettes"
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
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-22 00:00:00.000000000 Z
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