flickr_airlift 0.3.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,6 +1,7 @@
1
1
  *.gem
2
2
  *.rbc
3
3
  .bundle
4
+ .redcar
4
5
  .config
5
6
  .yardoc
6
7
  .rvmrc
@@ -15,4 +16,4 @@ rdoc
15
16
  spec/reports
16
17
  test/tmp
17
18
  test/version_tmp
18
- tmp
19
+ tmp
@@ -1,3 +1,3 @@
1
1
  module FlickrAirlift
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -15,14 +15,24 @@ module FlickrAirlift
15
15
 
16
16
  # Prompt
17
17
  puts "Exactly who's photos would you like to archive?:"
18
+
18
19
  scraped_user = STDIN.gets
19
- scraped_user = scraped_user.strip
20
-
21
- # Find
22
- user_id = flickr.people.findByUsername(:username => scraped_user).id
20
+ scraped_user = scraped_user.strip
21
+
22
+ begin
23
+ user_id = flickr.people.findByUsername(:username => scraped_user).id
24
+ rescue Exception => e
25
+ puts "Hmmmm - unknown user - make sure to use the user's full handle - not the one in the URL. (example: 'Fast & Bulbous' not 'fastandbulbous')"
26
+ self.download
27
+ end
28
+
29
+
23
30
  photos = flickr.photos.search(:user_id => user_id)
24
31
  photo_count = photos.total
25
32
  page_count = photos.pages
33
+
34
+ # non-pro users don't have 'Original' sizes available.
35
+ ranked_sizes = ['Original', 'Large', 'Medium']
26
36
 
27
37
  # Downloading
28
38
  puts "#{scraped_user} has #{photo_count} pictures"
@@ -33,17 +43,24 @@ module FlickrAirlift
33
43
  puts "* PAGE #{page_number} of #{page_count}"
34
44
  flickr.photos.search(:user_id => user_id, :page => page_number).each_with_index do |photo, i|
35
45
 
36
- photo_id = photo.id
37
- info = flickr.photos.getInfo(:photo_id => photo_id)
38
- photo_size_objects = flickr.photos.getSizes(:photo_id => photo_id)
39
-
40
- download_url = flickr.photos.getSizes(:photo_id => photo_id).find{|size| size.label == "Original"}.source
41
-
42
- puts "** Downloading #{i+1}: #{photo.title} from #{download_url}"
43
- File.open(File.join(scraped_user, "#{info.title}#{File.extname(download_url)}"), 'wb') do |file|
44
- file.puts Net::HTTP.get_response(URI.parse(download_url)).body
46
+ photo_id = photo.id
47
+ info = flickr.photos.getInfo(:photo_id => photo_id)
48
+ downloadable_files = flickr.photos.getSizes(:photo_id => photo_id)
49
+
50
+ ranked_sizes.each do |size_name|
51
+ if df = downloadable_files.find { |downloadable_file| downloadable_file.label == size_name }
52
+ download_url = df.source
53
+ file_to_write = File.join(scraped_user, "#{photo_id}#{File.extname(download_url)}")
54
+
55
+ if File.exists?(file_to_write)
56
+ puts "** SKIPPING #{file_to_write} because it exists"
57
+ else
58
+ puts "** Downloading #{i+1}: #{photo.title} (#{size_name}) from #{download_url}"
59
+ File.open(file_to_write, 'wb') { |file| file.puts Net::HTTP.get_response(URI.parse(download_url)).body }
60
+ end
61
+ break
62
+ end
45
63
  end
46
-
47
64
  end
48
65
  end
49
66
 
@@ -78,9 +95,17 @@ module FlickrAirlift
78
95
  FlickRaw.shared_secret = "405549bcec106815"
79
96
 
80
97
  if File.exists?(auth_file)
81
- puts "authenticating through #{auth_file}...if this fails - delete this file"
82
- data = YAML.load_file(auth_file)
83
- auth = flickr.auth.checkToken :auth_token => data["api_token"]
98
+
99
+ data = YAML.load_file(auth_file)
100
+
101
+ begin
102
+ auth = flickr.auth.checkToken :auth_token => data["api_token"]
103
+ rescue Exception => e
104
+ puts "These was a problem with the credentials in #{auth_file}"
105
+ puts "Delete the file and try again."
106
+ exit
107
+ end
108
+
84
109
  else
85
110
  frob = flickr.auth.getFrob
86
111
  auth_url = FlickRaw.auth_url :frob => frob, :perms => "write"
@@ -98,7 +123,7 @@ module FlickrAirlift
98
123
  auth = flickr.auth.getToken :frob => frob
99
124
  login = flickr.test.login
100
125
 
101
- puts auth.token
126
+ puts "Writing credentials to #{auth_file}"
102
127
  data = {}
103
128
  data["api_token"] = auth.token
104
129
  File.open(auth_file, "w"){|f| YAML.dump(data, f) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flickr_airlift
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
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: 2013-01-04 00:00:00.000000000 Z
12
+ date: 2013-01-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: launchy