picasaweb-backup 0.1.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 +17 -0
- data/Gemfile +2 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/bin/picasaweb-backup +78 -0
- data/lib/picasaweb-backup.rb +72 -0
- data/lib/picasaweb-backup/version.rb +5 -0
- data/picasaweb-backup.gemspec +20 -0
- metadata +57 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Leonard Ehrenfried
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Picasaweb::Backup
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'picasaweb-backup'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install picasaweb-backup
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'optparse'
|
4
|
+
require 'picasaweb-backup'
|
5
|
+
|
6
|
+
data = {}
|
7
|
+
usage = %{picasaweb-backup v.#{Picasaweb::Backup::VERSION}}
|
8
|
+
|
9
|
+
OptionParser.new('Backing up your Picasaweb photos') do |opt|
|
10
|
+
opt.version = '2'
|
11
|
+
opt.on('--dir DIR') do |dir|
|
12
|
+
data[:dir] = dir
|
13
|
+
end
|
14
|
+
begin
|
15
|
+
opt.parse!(ARGV)
|
16
|
+
rescue
|
17
|
+
puts usage
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
begin
|
22
|
+
account = File.open("account.yml", 'r') { |f| YAML.load f }
|
23
|
+
verify_account account
|
24
|
+
client = picasa_client account["username"], account["password"]
|
25
|
+
albums = picasa_albums client
|
26
|
+
dir_name = "Albums"
|
27
|
+
|
28
|
+
if !File.directory? dir_name
|
29
|
+
Dir.mkdir dir_name
|
30
|
+
end
|
31
|
+
|
32
|
+
Dir.chdir dir_name
|
33
|
+
|
34
|
+
albums.each do |album|
|
35
|
+
|
36
|
+
if !File.directory? album[:title]
|
37
|
+
Dir.mkdir album[:title]
|
38
|
+
puts "Creating directory for album '#{album[:title]}'"
|
39
|
+
end
|
40
|
+
|
41
|
+
Dir.chdir album[:title] do
|
42
|
+
puts "Checking for new files in '#{album[:title]}'"
|
43
|
+
photos = nil
|
44
|
+
until photos
|
45
|
+
begin
|
46
|
+
photos = picasa_photos client, album
|
47
|
+
rescue GData::Client::ServerError
|
48
|
+
"Server error, retrying\n"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
downloaded_photos = 0
|
53
|
+
photos.each do |photo|
|
54
|
+
if !File.exists? photo[:title]
|
55
|
+
puts " ==> #{photo[:title]}"
|
56
|
+
response = nil
|
57
|
+
until response
|
58
|
+
begin
|
59
|
+
response = client.get photo[:url]
|
60
|
+
rescue GData::Client::ServerError
|
61
|
+
"Server error, retrying\n"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
File.open(photo[:title], 'w') { |f| f.write response.body }
|
66
|
+
downloaded_photos += 1
|
67
|
+
end
|
68
|
+
end
|
69
|
+
if downloaded_photos == 0
|
70
|
+
puts "==> no new photos found"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
rescue => e
|
75
|
+
puts e.message
|
76
|
+
puts usage
|
77
|
+
end
|
78
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Backs up all the photos from Google Picasa Web Albums.
|
2
|
+
#
|
3
|
+
# The script downloads the original version of the photos, and is not limited to
|
4
|
+
# 1600x1200 thumbnails.
|
5
|
+
#
|
6
|
+
# Author:: Victor Costan
|
7
|
+
# Copyright:: Copyright (C) 2010 Victor Costan
|
8
|
+
# License:: MIT
|
9
|
+
|
10
|
+
require "picasaweb-backup/version"
|
11
|
+
require 'yaml'
|
12
|
+
require 'rubygems'
|
13
|
+
require 'gdata'
|
14
|
+
|
15
|
+
module Picasaweb
|
16
|
+
module Backup
|
17
|
+
# Your code goes here...
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def verify_account account
|
22
|
+
if account["username"].nil?
|
23
|
+
raise "Please add your username to account.yml"
|
24
|
+
elsif account["password"].nil?
|
25
|
+
raise "Please add your password to account.yml"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# config_path should point to a yaml file that looks like this:
|
30
|
+
# username: costan
|
31
|
+
# password: "secret"
|
32
|
+
def picasa_client(username, password)
|
33
|
+
client = GData::Client::Photos.new
|
34
|
+
client.clientlogin(username, password)
|
35
|
+
client
|
36
|
+
end
|
37
|
+
|
38
|
+
# Retrieves all albums for a user.
|
39
|
+
def picasa_albums(client, user = nil)
|
40
|
+
uri = "http://picasaweb.google.com/data/feed/api/user/#{user || 'default'}"
|
41
|
+
feed = client.get(uri).to_xml
|
42
|
+
albums = []
|
43
|
+
feed.elements.each('entry') do |entry|
|
44
|
+
next unless entry.elements['gphoto:id']
|
45
|
+
albums << { :id => entry.elements['gphoto:id'].text,
|
46
|
+
:user => entry.elements['gphoto:user'].text,
|
47
|
+
:title => entry.elements['title'].text }
|
48
|
+
end
|
49
|
+
albums
|
50
|
+
end
|
51
|
+
|
52
|
+
# Retrieves all photos from an album.
|
53
|
+
def picasa_photos(client, album)
|
54
|
+
uri = "http://picasaweb.google.com/data/feed/api/user/" +
|
55
|
+
"#{album[:user] || 'default'}/albumid/#{album[:id]}?kind=photo&imgmax=d"
|
56
|
+
|
57
|
+
feed = client.get(uri).to_xml
|
58
|
+
photos = []
|
59
|
+
feed.elements.each('entry') do |entry|
|
60
|
+
next unless entry.elements['gphoto:id']
|
61
|
+
next unless entry.elements['media:group']
|
62
|
+
photo = { :id => entry.elements['gphoto:id'].text,
|
63
|
+
:album_id => entry.elements['gphoto:albumid'].text,
|
64
|
+
:title => entry.elements['title'].text }
|
65
|
+
entry.elements['media:group'].elements.each('media:content') do |content|
|
66
|
+
photo[:url] = content.attribute('url').value
|
67
|
+
end
|
68
|
+
photos << photo
|
69
|
+
end
|
70
|
+
photos
|
71
|
+
end
|
72
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/picasaweb-backup/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Leonard Ehrenfried"]
|
6
|
+
gem.email = ['leonard.ehrenfried@web.de']
|
7
|
+
gem.summary = "Picasa Web Albums backup tool"
|
8
|
+
gem.description = %{Backup all your photos from Google's Picasa Web Albums service,
|
9
|
+
can be run repeatedly on the same folder and only downloads new files.}
|
10
|
+
|
11
|
+
gem.homepage = 'http://github.com/lenniboy/picasaweb-backup'
|
12
|
+
|
13
|
+
|
14
|
+
gem.files = `git ls-files`.split($\)
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
17
|
+
gem.name = "picasaweb-backup"
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.version = Picasaweb::Backup::VERSION
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: picasaweb-backup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Leonard Ehrenfried
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-02 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: ! "Backup all your photos from Google's Picasa Web Albums service, \n
|
15
|
+
\ can be run repeatedly on the same folder and only downloads new files."
|
16
|
+
email:
|
17
|
+
- leonard.ehrenfried@web.de
|
18
|
+
executables:
|
19
|
+
- picasaweb-backup
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- .gitignore
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- LICENSE
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- bin/picasaweb-backup
|
30
|
+
- lib/picasaweb-backup.rb
|
31
|
+
- lib/picasaweb-backup/version.rb
|
32
|
+
- picasaweb-backup.gemspec
|
33
|
+
homepage: http://github.com/lenniboy/picasaweb-backup
|
34
|
+
licenses: []
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
requirements: []
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.8.24
|
54
|
+
signing_key:
|
55
|
+
specification_version: 3
|
56
|
+
summary: Picasa Web Albums backup tool
|
57
|
+
test_files: []
|