Created
January 28, 2011 07:37
-
-
Save huacnlee/799961 to your computer and use it in GitHub Desktop.
Yupoo 图片备份工具
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: UTF-8 | |
# | |
# Yupoo 照片备份工具 | |
# 此工具不需要API,直接就能备份你的照片信息,下载后以图片 + 一个文本文件的方式存放 | |
# 备份包括内容: | |
# 原图,标题,说明,Tag,当然有 Exif 信息 | |
# | |
# Jason Lee <[email protected]> | |
# http://huacnlee.com | |
# 2011-01-28 | |
# | |
# 如何使用 | |
# 安装 Ruby 1.9.2 | |
# 安装 Rubygems | |
# $ sudo apt-get install ruby1.9 rubygems | |
# | |
# 然后 | |
# $ gem install nokogiri | |
# $ gem install mechanize | |
# | |
# 运行 | |
# ruby main.rb | |
# | |
require "nokogiri" | |
require "open-uri" | |
require "mechanize" | |
BASE_URL = 'http://www.yupoo.com' | |
# 你的个性域名 如: http://huacn.yupoo.com/ 就是 huacn | |
CUSTOM_LOGIN = "huacn" | |
# 你的 Yupoo 帐号 | |
USERNAME = "[email protected]" | |
# 你的 Yupoo 密码 | |
PASSWORD = "123123" | |
# 图片文件保存位置,./photos/ 就是在当前目录的 photos 里面 | |
SAVE_PATH = "./photos/" | |
# 开始年, 这个采集是根据年份分别采集的 | |
START_YEAR = 2006 | |
# 结束年 | |
END_YEAR = 2011 | |
@agent = WWW::Mechanize.new | |
@agent.set_proxy('172.28.150.20', '8080') | |
page = @agent.get("http://www.yupoo.com/account/login/") | |
form = page.forms[1] | |
form.username = USERNAME | |
form.password = PASSWORD | |
form.checkboxes[0].checked=true | |
page_home = form.submit | |
def save_photo(year,id,title,tags,description,file_url) | |
description = description.gsub(/\n/,"").gsub(/\r/,"") | |
dir = "#{SAVE_PATH}#{year}/" | |
if not File.directory?(dir) | |
Dir.mkdir(dir) | |
end | |
open("#{dir}/#{id}.jpg","w") do |f| | |
f.write(open(file_url).read) | |
end | |
open("#{dir}/#{id}.desc","w") do |f| | |
f.puts "id: #{id}" | |
f.puts "title: #{title}" | |
f.puts "tags: #{tags}" | |
f.puts "description: #{description}" | |
end | |
puts "saved.".rjust(80) | |
end | |
def get_photo(url,year) | |
puts "" | |
puts "-" * 80 | |
puts "#{url}".rjust(80) | |
originUrl = "#{url}zoom/original/" | |
doc = Nokogiri::HTML(open(url)) | |
id = url.match(/\d+/).to_s | |
puts "#{id.rjust(13)} : #{id}" | |
title = doc.css(".title-display").text.strip | |
puts "#{'Title'.rjust(13)} : #{title}" | |
tags = doc.css("#thetags ul li a.Tag").collect { |t| t.text }.join(",") | |
puts "#{'Tags'.rjust(13)} : #{tags}" | |
description = doc.css(".des-display").text.strip | |
puts "#{'Description'.rjust(13)} : #{description}" | |
doc_origin = Nokogiri::HTML(@agent.get(originUrl).body) | |
file_url = doc_origin.css("img.Photo").attr("src") | |
puts "#{'File Url'.rjust(13)} : #{file_url}" | |
save_photo(year,id,title,tags,description,file_url) | |
end | |
def get_photos(year) | |
puts "" | |
puts "=" * 80 | |
puts "=" * 80 | |
puts "#{year} - P1".rjust(80) | |
url = "http://www.yupoo.com/photos/#{CUSTOM_LOGIN}/archives/date-taken/#{year}/list/" | |
doc = Nokogiri::HTML(open(url)) | |
doc.css("#archiveList ul li a").each do |item| | |
photo_url = "#{BASE_URL}#{item.attr("href")}" | |
get_photo(photo_url,year) | |
end | |
max_page = doc.css(".pages a.end").text.to_i | |
2.upto(max_page) do |page| | |
puts "=" * 80 | |
puts "=" * 80 | |
puts "#{year} - P#{page}".rjust(80) | |
url = "http://www.yupoo.com/photos/#{CUSTOM_LOGIN}/archives/date-taken/#{year}/list/page#{page}" | |
doc = Nokogiri::HTML(open(url)) | |
doc.css("#archiveList ul li a").each do |item| | |
photo_url = "#{BASE_URL}#{item.attr("href")}" | |
get_photo(photo_url,year) | |
end | |
end | |
end | |
START_YEAR.upto(END_YEAR).each do |year| | |
get_photos(year) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
windows xp下该怎么用?