denis-flickrget 0.0.2

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Denis Barushev
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ == flickrget
2
+
3
+ A gem that provides...
data/Rakefile ADDED
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rubygems/specification'
4
+ require 'date'
5
+ require 'spec/rake/spectask'
6
+
7
+ GEM = "flickrget"
8
+ GEM_VERSION = "0.0.2"
9
+ AUTHOR = "Denis Barushev"
10
+ EMAIL = "barushev@gmail.com"
11
+ HOMEPAGE = "http://github.com/denis/flickrget"
12
+ SUMMARY = "A gem that provides a simple command line tool for downloading photos from Flickr"
13
+
14
+ spec = Gem::Specification.new do |s|
15
+ s.name = GEM
16
+ s.version = GEM_VERSION
17
+ s.platform = Gem::Platform::RUBY
18
+ s.has_rdoc = true
19
+ s.extra_rdoc_files = ["README.rdoc", "LICENSE", 'TODO']
20
+ s.summary = SUMMARY
21
+ s.description = s.summary
22
+ s.author = AUTHOR
23
+ s.email = EMAIL
24
+ s.homepage = HOMEPAGE
25
+
26
+ # Uncomment this to add a dependency
27
+ # s.add_dependency "foo"
28
+
29
+ s.require_path = 'lib'
30
+ s.autorequire = GEM
31
+ s.files = %w(LICENSE README.rdoc Rakefile TODO) + Dir.glob("{bin,lib,spec}/**/*")
32
+
33
+ s.executables = ["flickrget"]
34
+ end
35
+
36
+ task :default => :spec
37
+
38
+ desc "Run specs"
39
+ Spec::Rake::SpecTask.new do |t|
40
+ t.spec_files = FileList['spec/**/*_spec.rb']
41
+ t.spec_opts = %w(-fs --color)
42
+ end
43
+
44
+
45
+ Rake::GemPackageTask.new(spec) do |pkg|
46
+ pkg.gem_spec = spec
47
+ end
48
+
49
+ desc "install the gem locally"
50
+ task :install => [:package] do
51
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
52
+ end
53
+
54
+ desc "create a gemspec file"
55
+ task :make_spec do
56
+ File.open("#{GEM}.gemspec", "w") do |file|
57
+ file.puts spec.to_ruby
58
+ end
59
+ end
data/TODO ADDED
@@ -0,0 +1,4 @@
1
+ TODO:
2
+ [x] Fix LICENSE with your name
3
+ [x] Fix Rakefile with your name and contact info
4
+ [x] Add your code to lib/flickrget.rb
data/bin/flickrget ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created on 2008-9-26.
4
+ # Copyright (c) 2008. All rights reserved.
5
+
6
+ begin
7
+ require 'rubygems'
8
+ rescue LoadError
9
+ # no rubygems to load, so we fail silently
10
+ end
11
+
12
+ require 'optparse'
13
+ require 'flickrget'
14
+
15
+ OPTIONS = {
16
+ :type => 'people'
17
+ }
18
+
19
+ AVALIABLE_TYPES = %w(people photosets favorites)
20
+
21
+ parser = OptionParser.new do |opts|
22
+ opts.banner = <<-BANNER
23
+ Download photos from Flickr
24
+
25
+ Usage: #{File.basename($0)} [options] id ...
26
+
27
+ Options are:
28
+ BANNER
29
+
30
+ opts.separator ""
31
+
32
+ opts.on('-p', '--people', 'Public photos for the given people (default)') { OPTIONS[:type] = 'people' }
33
+ opts.on('-s', '--photosets', 'Photos in the given sets') { OPTIONS[:type] = 'photosets' }
34
+ opts.on('-f', '--favorites', 'Favorite public photos for the given users') { OPTIONS[:type] = 'favorites' }
35
+
36
+ opts.on('-h', '--help', 'Show this help message') { puts opts; exit }
37
+
38
+ opts.parse!(ARGV)
39
+
40
+ if ARGV.size < 1
41
+ puts opts; exit
42
+ end
43
+ end
44
+
45
+ Flickrget.download_all(OPTIONS[:type], ARGV)
data/lib/flickrget.rb ADDED
@@ -0,0 +1,65 @@
1
+ require 'hpricot'
2
+ require 'open-uri'
3
+
4
+ class Flickrget
5
+ def self.download_all(type, ids)
6
+ ids.each do |id|
7
+ self.new(type, id).download
8
+ end
9
+ end
10
+
11
+ def initialize(type, id)
12
+ case type
13
+ # Get public photos for the given user
14
+ when 'people'
15
+ @url = "flickr.people.getPublicPhotos&user_id=#{id}"
16
+ @path = '/rsp/photos'
17
+
18
+ # Get photos in the given set
19
+ when 'photosets'
20
+ @url = "flickr.photosets.getPhotos&photoset_id=#{id}"
21
+ @path = '/rsp/photoset'
22
+
23
+ # Get favorite public photos for the given user
24
+ when 'favorites'
25
+ @url = "flickr.favorites.getPublicList&user_id=#{id}"
26
+ @path = '/rsp/photos'
27
+
28
+ else
29
+ raise
30
+ end
31
+
32
+ @url = "http://api.flickr.com/services/rest/?method=#{@url}&extras=original_format&api_key=1b6d69170a6a5ab2fa502a32c870fd2f"
33
+ end
34
+
35
+ def download
36
+ photos = photos_urls.each do |url|
37
+ open(url.split('/').last, 'w').write(open(url).read)
38
+ STDOUT.print(".")
39
+ STDOUT.flush
40
+ end
41
+ puts "\n#{photos.size} photo(s) saved\n"
42
+ end
43
+
44
+ private
45
+
46
+ def photos_urls
47
+ result, page, pages = [], 1, 1
48
+
49
+ while page <= pages do
50
+ doc = Hpricot(open("#{@url}&page=#{page}"))
51
+
52
+ doc.search("#{@path}/photo").each do |p|
53
+ result << "http://farm#{p['farm']}.static.flickr.com/#{p['server']}/#{p['id']}_#{p['originalsecret']}_o.#{p['originalformat']}"
54
+ end
55
+
56
+ if page == 1
57
+ pages = doc.at(@path)['pages'].to_i
58
+ end
59
+ page += 1
60
+ end
61
+
62
+ puts "#{result.size} photo(s) founded\n"
63
+ result
64
+ end
65
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "flickrget" do
4
+ it "should do nothing" do
5
+ true.should == true
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $TESTING=true
2
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: denis-flickrget
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Denis Barushev
8
+ autorequire: flickrget
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-08 00:00:00 -07:00
13
+ default_executable: flickrget
14
+ dependencies: []
15
+
16
+ description: A gem that provides a simple command line tool for downloading photos from Flickr
17
+ email: barushev@gmail.com
18
+ executables:
19
+ - flickrget
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - LICENSE
25
+ - TODO
26
+ files:
27
+ - LICENSE
28
+ - README.rdoc
29
+ - Rakefile
30
+ - TODO
31
+ - bin/flickrget
32
+ - lib/flickrget.rb
33
+ - spec/spec_helper.rb
34
+ - spec/flickrget_spec.rb
35
+ has_rdoc: true
36
+ homepage: http://github.com/denis/flickrget
37
+ post_install_message:
38
+ rdoc_options: []
39
+
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ requirements: []
55
+
56
+ rubyforge_project:
57
+ rubygems_version: 1.2.0
58
+ signing_key:
59
+ specification_version: 2
60
+ summary: A gem that provides a simple command line tool for downloading photos from Flickr
61
+ test_files: []
62
+