fotki-export 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,14 @@
1
+ == Fotki Export -- Tool to download picture from Fotki.com
2
+
3
+ == Installing Fotki Export
4
+ $ gem install fotki-export
5
+
6
+ == Usage
7
+
8
+ fotki-export -u <fotki username> -p <fotki password> -d </path/to/save/photos> -b [firefox|chrome|ie]
9
+ -u, --user USER username
10
+ -p, --pass PASSWORD password
11
+ -d, --dir DIR directory
12
+ -b --browser BROWSER (firefox|chrome|ie) browser
13
+
14
+ fotki-export -u fotki_user -p fotki_password -d /tmp/fotki -b firefox
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rake/rdoctask'
4
+ begin
5
+ require 'bundler'
6
+ rescue LoadError
7
+ puts 'Bundler not available. Install it with: [sudo] gem install bundler'
8
+ end
9
+ begin
10
+ require 'jeweler'
11
+ rescue LoadError
12
+ puts 'Jeweler not available. Install it with: [sudo] gem install jeweler'
13
+ end
14
+
15
+ task :default => :gemspec
16
+
17
+ Jeweler::Tasks.new do |gemspec|
18
+ gemspec.name = 'fotki-export'
19
+ gemspec.summary = 'Fotki.com photo export tool.'
20
+ gemspec.description = 'Simple command line to to download all your photos from Fotki.com'
21
+ gemspec.email = 'gene.drabkin@gmail.com'
22
+ gemspec.homepage = 'https://github.com/cloocher/fotki-exporter'
23
+ gemspec.authors = ['Gene Drabkin']
24
+ gemspec.files = FileList['fotki-export.gemspec', 'Rakefile', 'README', 'VERSION', 'lib/**/*', 'bin/**/*']
25
+ gemspec.add_dependency 'watir-webdriver', '>= 0.2.2'
26
+ gemspec.executables = ['fotki-export']
27
+ gemspec.requirements = ['none']
28
+ gemspec.bindir = 'bin'
29
+ gemspec.add_bundler_dependencies
30
+ end
31
+
32
+ desc 'Release gem'
33
+ task :'release:gem' do
34
+ %x(
35
+ rake gemspec
36
+ rake build
37
+ rake install
38
+ git add .
39
+ )
40
+ puts 'Commit message:'
41
+ message = STDIN.gets
42
+
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ''
44
+
45
+ %x(
46
+ git commit -m '#{message}'
47
+ git push origin master
48
+ gem push pkg/fotki-export-#{version}.gem
49
+ )
50
+ end
51
+
52
+ Rake::RDocTask.new do |rdoc|
53
+ version = File.exist?('VERSION') ? File.read('VERSION') : ''
54
+ rdoc.rdoc_dir = 'rdoc'
55
+ rdoc.title = "fotki-export #{version}"
56
+ rdoc.rdoc_files.include('README*')
57
+ rdoc.rdoc_files.include('lib/**/*.rb')
58
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright 2011 Gene Drabkin
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ $:.unshift(File::join(File::dirname(File::dirname(__FILE__)), 'lib'))
18
+
19
+ require 'rubygems'
20
+ require 'optparse'
21
+ require 'fotki'
22
+
23
+ username = password = directory = nil
24
+ browser = 'firefox'
25
+
26
+ opts = OptionParser.new do |opts|
27
+ opts.banner = 'Usage: fotki-export -u <fotki username> -p <fotki password> -d </path/to/save/photos> -b [firefox|chrome|ie]'
28
+ opts.on('-u', '--user USER', 'username') {|u| username = u}
29
+ opts.on('-p', '--pass PASSWORD', 'password') {|p| password = p}
30
+ opts.on('-d', '--dir DIR', 'directory') {|d| directory = d}
31
+ opts.on('-b', '--browser BROWSER (firefox|chrome|ie)', 'browser') {|b| browser = b}
32
+ end
33
+
34
+ opts.parse!(ARGV)
35
+
36
+ unless username and password and directory
37
+ puts opts
38
+ exit 1
39
+ end
40
+
41
+ Fotki.new(username, password, directory, browser.to_sym).export
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{fotki-export}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Gene Drabkin"]
12
+ s.date = %q{2011-04-30}
13
+ s.description = %q{Simple command line to to download all your photos from Fotki.com}
14
+ s.email = %q{gene.drabkin@gmail.com}
15
+ s.executables = ["fotki-export"]
16
+ s.extra_rdoc_files = [
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "Rakefile",
21
+ "VERSION",
22
+ "bin/fotki-export",
23
+ "fotki-export.gemspec",
24
+ "lib/fotki.rb"
25
+ ]
26
+ s.homepage = %q{https://github.com/cloocher/fotki-exporter}
27
+ s.require_paths = ["lib"]
28
+ s.requirements = ["none"]
29
+ s.rubygems_version = %q{1.7.2}
30
+ s.summary = %q{Fotki.com photo export tool.}
31
+
32
+ if s.respond_to? :specification_version then
33
+ s.specification_version = 3
34
+
35
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
36
+ s.add_runtime_dependency(%q<watir-webdriver>, [">= 0"])
37
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
38
+ s.add_development_dependency(%q<gemcutter>, [">= 0"])
39
+ s.add_runtime_dependency(%q<watir-webdriver>, [">= 0.2.2"])
40
+ s.add_runtime_dependency(%q<watir-webdriver>, [">= 0"])
41
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
42
+ s.add_development_dependency(%q<gemcutter>, [">= 0"])
43
+ else
44
+ s.add_dependency(%q<watir-webdriver>, [">= 0"])
45
+ s.add_dependency(%q<jeweler>, [">= 0"])
46
+ s.add_dependency(%q<gemcutter>, [">= 0"])
47
+ s.add_dependency(%q<watir-webdriver>, [">= 0.2.2"])
48
+ s.add_dependency(%q<watir-webdriver>, [">= 0"])
49
+ s.add_dependency(%q<jeweler>, [">= 0"])
50
+ s.add_dependency(%q<gemcutter>, [">= 0"])
51
+ end
52
+ else
53
+ s.add_dependency(%q<watir-webdriver>, [">= 0"])
54
+ s.add_dependency(%q<jeweler>, [">= 0"])
55
+ s.add_dependency(%q<gemcutter>, [">= 0"])
56
+ s.add_dependency(%q<watir-webdriver>, [">= 0.2.2"])
57
+ s.add_dependency(%q<watir-webdriver>, [">= 0"])
58
+ s.add_dependency(%q<jeweler>, [">= 0"])
59
+ s.add_dependency(%q<gemcutter>, [">= 0"])
60
+ end
61
+ end
62
+
@@ -0,0 +1,106 @@
1
+ # Copyright 2011 Gene Drabkin
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+
14
+ require 'watir-webdriver'
15
+ require 'open-uri'
16
+
17
+ class Fotki
18
+
19
+ def initialize(username, password, directory, browser = :firefox)
20
+ @username, @password, @directory, @browser = username, password, directory, browser
21
+ @client = Watir::Browser.new(@browser)
22
+ end
23
+
24
+ def export
25
+ @client.goto('http://fotki.com')
26
+
27
+ # logout if logged in
28
+ logout_link = @client.link(:title, 'Logout...')
29
+ logout_link.click if logout_link.exists?
30
+
31
+ # login
32
+ puts 'logging in'
33
+ @client.goto('http://login.fotki.com/')
34
+ @client.text_field(:name, 'login').set(@username)
35
+ @client.text_field(:name, 'password').set(@password)
36
+ @client.button(:value, 'Login').click
37
+
38
+ photo_count = 0
39
+ puts 'opening all albums'
40
+ @client.goto('http://public.fotki.com/Lenocheka/')
41
+ puts 'going through every album folder'
42
+ folder_links = @client.div(:id, 'dtree').links
43
+ folder_links.each do |folder_link|
44
+ # only open folders with photos
45
+ if folder_link.href.downcase.match(/my-pic\/\w+\//i)
46
+ puts "opening folder #{folder_link.text}"
47
+ @client.goto(folder_link.href)
48
+ picture_folder_url = @client.url
49
+
50
+ puts 'going through every album'
51
+ albums_div = @client.div(:id, 'albums_loop')
52
+ album_index = 1
53
+ # loop through all albums
54
+ loop do
55
+ album_link = albums_div.link(:class => 'title', :index => album_index)
56
+ # stop when no more albums left
57
+ break unless album_link.exists?
58
+ album_name = album_link.text.gsub(/\//, ' - ')
59
+ puts "album ##{album_index} \"#{album_name}\""
60
+ album_link.click
61
+
62
+ dir_path = "#{@directory}/#{album_name}"
63
+ # skip albums that have been downloaded already
64
+ unless File.exists?(dir_path)
65
+ puts 'loading first photo in album'
66
+ first_link = @client.link(:xpath, "//div[@class='thumbnails']//a/img/..")
67
+ first_link.click
68
+
69
+ puts 'downloading all photos within album'
70
+ # loop through all photos within album
71
+ loop do
72
+ download_link = @client.link(:xpath, "//li[@class='single']/a[contains(@href, 'http://images')]")
73
+ if download_link.exists?
74
+ photo_url = download_link.href
75
+ photo_name = photo_url.split(/\//).last
76
+
77
+ `mkdir -p "#{dir_path}"`
78
+ file_path = "#{dir_path}/#{photo_name}"
79
+ # download photo
80
+ unless File.exist?(file_path)
81
+ photo_count += 1
82
+ puts "[#{photo_count}] downloading photo #{photo_name}"
83
+ File.open(file_path, 'w') do |output|
84
+ open(photo_url) do |input|
85
+ output << input.read
86
+ end
87
+ end
88
+ end
89
+ end
90
+
91
+ count_link = @client.link(:id, 'btn_thumbs')
92
+ counts = count_link.spans.last.text.split(/\//).map { |e| e.to_i }
93
+ # go to next photo unless on the last one
94
+ break if counts.first == counts.last
95
+ photo_nav_div = @client.div(:id, 'photo_navig')
96
+ photo_nav_div.link(:text, 'Next').click
97
+ end
98
+ end
99
+
100
+ album_index += 1
101
+ @client.goto(picture_folder_url)
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fotki-export
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Gene Drabkin
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-30 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ name: watir-webdriver
31
+ prerelease: false
32
+ type: :runtime
33
+ requirement: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ hash: 3
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ name: jeweler
45
+ prerelease: false
46
+ type: :development
47
+ requirement: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ version_requirements: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ name: gemcutter
59
+ prerelease: false
60
+ type: :development
61
+ requirement: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ version_requirements: &id004 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 19
69
+ segments:
70
+ - 0
71
+ - 2
72
+ - 2
73
+ version: 0.2.2
74
+ name: watir-webdriver
75
+ prerelease: false
76
+ type: :runtime
77
+ requirement: *id004
78
+ - !ruby/object:Gem::Dependency
79
+ version_requirements: &id005 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ name: watir-webdriver
89
+ prerelease: false
90
+ type: :runtime
91
+ requirement: *id005
92
+ - !ruby/object:Gem::Dependency
93
+ version_requirements: &id006 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ name: jeweler
103
+ prerelease: false
104
+ type: :development
105
+ requirement: *id006
106
+ - !ruby/object:Gem::Dependency
107
+ version_requirements: &id007 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 3
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ name: gemcutter
117
+ prerelease: false
118
+ type: :development
119
+ requirement: *id007
120
+ description: Simple command line to to download all your photos from Fotki.com
121
+ email: gene.drabkin@gmail.com
122
+ executables:
123
+ - fotki-export
124
+ extensions: []
125
+
126
+ extra_rdoc_files:
127
+ - README.rdoc
128
+ files:
129
+ - Rakefile
130
+ - VERSION
131
+ - bin/fotki-export
132
+ - fotki-export.gemspec
133
+ - lib/fotki.rb
134
+ - README.rdoc
135
+ homepage: https://github.com/cloocher/fotki-exporter
136
+ licenses: []
137
+
138
+ post_install_message:
139
+ rdoc_options: []
140
+
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ hash: 3
149
+ segments:
150
+ - 0
151
+ version: "0"
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ hash: 3
158
+ segments:
159
+ - 0
160
+ version: "0"
161
+ requirements:
162
+ - none
163
+ rubyforge_project:
164
+ rubygems_version: 1.7.2
165
+ signing_key:
166
+ specification_version: 3
167
+ summary: Fotki.com photo export tool.
168
+ test_files: []
169
+