flickr_airlift 0.3.5 → 0.4.0
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 +1 -0
- data/README.textile +2 -5
- data/flickr_airlift.gemspec +1 -0
- data/lib/flickr_airlift/downloader.rb +50 -0
- data/lib/flickr_airlift/version.rb +1 -1
- data/lib/flickr_airlift.rb +22 -33
- metadata +19 -2
data/.gitignore
CHANGED
data/README.textile
CHANGED
@@ -12,13 +12,11 @@ h3. Requirements
|
|
12
12
|
|
13
13
|
h1. Flickr Airlift
|
14
14
|
|
15
|
-
Flickr Airlift is a command line tool to scrape all of a user
|
16
|
-
It comes with the bin flickr_airlift
|
17
|
-
named after the user.
|
15
|
+
Flickr Airlift is a command line tool to scrape *any set* _or_ *all photos in the photostream" of a user.
|
16
|
+
It comes with the bin flickr_airlift.
|
18
17
|
|
19
18
|
h2. Usage
|
20
19
|
|
21
|
-
Relax slim...use the @flickr_airlift@ bin and let the app have its way
|
22
20
|
Here's an "example session":https://gist.github.com/0cd071320f022c06dc23
|
23
21
|
|
24
22
|
------------------------------------------------------------------------------------
|
@@ -30,7 +28,6 @@ By default they will all be public.
|
|
30
28
|
|
31
29
|
h2. Usage
|
32
30
|
|
33
|
-
Relax slim...use the @flickr_uplift@ bin and let the app have its way
|
34
31
|
Here's an "example session":https://gist.github.com/61c9b299fdbae112dc26
|
35
32
|
|
36
33
|
This product uses the Flickr API but is not endorsed or certified by Flickr.
|
data/flickr_airlift.gemspec
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module FlickrAirlift
|
4
|
+
module Downloader
|
5
|
+
|
6
|
+
def self.download(user, set = nil)
|
7
|
+
# non-pro users don't have 'Original' sizes available.
|
8
|
+
ranked_sizes = ['Original', 'Large', 'Medium']
|
9
|
+
|
10
|
+
username = user.username
|
11
|
+
path = set.nil? ? username : File.join(username, set.title)
|
12
|
+
user_id = user.id
|
13
|
+
photos = set.nil? ? flickr.photos.search(:user_id => user_id) : flickr.photosets.getPhotos(:photoset_id => set.id)
|
14
|
+
photo_count = photos.total
|
15
|
+
page_count = photos.pages
|
16
|
+
|
17
|
+
# Downloading
|
18
|
+
puts "#{username} has #{photo_count} pictures"
|
19
|
+
puts "* Creating directory: '#{path}'"
|
20
|
+
FileUtils.mkdir_p(path) unless File.directory?(path)
|
21
|
+
|
22
|
+
(1..page_count.to_i).each do |page_number|
|
23
|
+
puts "* PAGE #{page_number} of #{page_count}"
|
24
|
+
iterate_over = set.nil? ? flickr.photos.search(:user_id => user_id, :page => page_number) : photos.photo
|
25
|
+
|
26
|
+
iterate_over.each_with_index do |photo, i|
|
27
|
+
|
28
|
+
photo_id = photo.id
|
29
|
+
downloadable_files = flickr.photos.getSizes(:photo_id => photo_id)
|
30
|
+
|
31
|
+
ranked_sizes.each do |size_name|
|
32
|
+
if df = downloadable_files.find { |downloadable_file| downloadable_file.label == size_name }
|
33
|
+
download_url = df.source
|
34
|
+
file_to_write = File.join(path, "#{photo_id}#{File.extname(download_url)}")
|
35
|
+
|
36
|
+
if File.exists?(file_to_write) && File.size(file_to_write) > 0
|
37
|
+
puts "** SKIPPING #{file_to_write} because it has already been downloaded"
|
38
|
+
else
|
39
|
+
puts "** Downloading #{i+1}: #{photo.title} (#{size_name}) from #{download_url}"
|
40
|
+
File.open(file_to_write, 'wb') { |file| file.puts Net::HTTP.get_response(URI.parse(download_url)).body }
|
41
|
+
end
|
42
|
+
break
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/lib/flickr_airlift.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require "flickr_airlift/version"
|
2
|
+
require "flickr_airlift/downloader"
|
2
3
|
require 'flickraw'
|
3
4
|
require 'net/http'
|
4
5
|
require 'cgi'
|
5
6
|
require 'launchy'
|
7
|
+
require 'highline/import'
|
6
8
|
require 'yaml'
|
7
9
|
|
8
10
|
module FlickrAirlift
|
@@ -20,47 +22,34 @@ module FlickrAirlift
|
|
20
22
|
scraped_user = scraped_user.strip
|
21
23
|
|
22
24
|
begin
|
23
|
-
|
25
|
+
user = flickr.people.findByUsername(:username => scraped_user)
|
26
|
+
user_id = user.id
|
24
27
|
rescue Exception => e
|
25
28
|
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
29
|
self.download
|
27
30
|
end
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
photo_id = photo.id
|
46
|
-
downloadable_files = flickr.photos.getSizes(:photo_id => photo_id)
|
47
|
-
|
48
|
-
ranked_sizes.each do |size_name|
|
49
|
-
if df = downloadable_files.find { |downloadable_file| downloadable_file.label == size_name }
|
50
|
-
download_url = df.source
|
51
|
-
file_to_write = File.join(scraped_user, "#{photo_id}#{File.extname(download_url)}")
|
52
|
-
|
53
|
-
if File.exists?(file_to_write) && File.size(file_to_write) > 0
|
54
|
-
puts "** SKIPPING #{file_to_write} because it has already been downloaded"
|
55
|
-
else
|
56
|
-
puts "** Downloading #{i+1}: #{photo.title} (#{size_name}) from #{download_url}"
|
57
|
-
File.open(file_to_write, 'wb') { |file| file.puts Net::HTTP.get_response(URI.parse(download_url)).body }
|
58
|
-
end
|
59
|
-
break
|
60
|
-
end
|
32
|
+
# Grab sets
|
33
|
+
photo_sets = flickr.photosets.getList(:user_id => user_id).sort_by(&:title)
|
34
|
+
|
35
|
+
choose do |menu|
|
36
|
+
menu.prompt = "What do you want to download?"
|
37
|
+
|
38
|
+
menu.choice("~ Entire Photostream ~") do
|
39
|
+
FlickrAirlift::Downloader.download(user)
|
40
|
+
exit
|
41
|
+
end
|
42
|
+
|
43
|
+
photo_sets.each do |photoset|
|
44
|
+
menu.choice(photoset.title) do
|
45
|
+
FlickrAirlift::Downloader.download(user, photoset)
|
46
|
+
exit
|
61
47
|
end
|
62
48
|
end
|
49
|
+
|
50
|
+
menu.choice("Quit") { exit }
|
63
51
|
end
|
52
|
+
|
64
53
|
rescue FlickRaw::FailedResponse => e
|
65
54
|
puts e.msg
|
66
55
|
end
|
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.
|
4
|
+
version: 0.4.0
|
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-07-
|
12
|
+
date: 2013-07-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: launchy
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - '='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 0.8.4
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: highline
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - '='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.6.11
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.6.11
|
46
62
|
description: A Command-Line tool for scraping any user's original photos OR uploading
|
47
63
|
all photos from a given directory
|
48
64
|
email:
|
@@ -61,6 +77,7 @@ files:
|
|
61
77
|
- bin/flickr_uplift
|
62
78
|
- flickr_airlift.gemspec
|
63
79
|
- lib/flickr_airlift.rb
|
80
|
+
- lib/flickr_airlift/downloader.rb
|
64
81
|
- lib/flickr_airlift/version.rb
|
65
82
|
homepage: https://github.com/nodanaonlyzuul/flickr_airlift
|
66
83
|
licenses: []
|