* Removed Pixa/Tinami sources

* Upgraded to Rails 3.2.3
* Fixed tests
This commit is contained in:
albert
2012-06-01 19:22:58 -04:00
parent 105cba5963
commit 17881068e1
124 changed files with 1063 additions and 1214 deletions

View File

@@ -2,7 +2,7 @@ module Downloads
module Strategies
class Base
def self.strategies
[Pixiv, Tinami, Pixa]
[Pixiv]
end
def rewrite(url, headers)

View File

@@ -1,19 +0,0 @@
module Downloads
module Strategies
class Pixa < Base
def rewrite(url, headers)
if url =~ /https?:\/\/(?:\w+\.)?pixa\.cc/
url, headers = rewrite_headers(url, headers)
end
return [url, headers]
end
protected
def rewrite_headers(url, headers)
headers["Referer"] = "http://www.pixa.cc"
return [url, headers]
end
end
end
end

View File

@@ -1,19 +0,0 @@
module Downloads
module Strategies
class Tinami < Base
def rewrite(url, headers)
if url =~ /https?:\/\/(?:\w+\.)?tinami\.com/
url, headers = rewrite_headers(url, headers)
end
return [url, headers]
end
protected
def rewrite_headers(url, headers)
headers["Referer"] = "http://www.tinami.com/view"
return [url, headers]
end
end
end
end

View File

@@ -4,7 +4,7 @@ module Sources
delegate :get, :site_name, :artist_name, :profile_url, :image_url, :tags, :artist_record, :unique_id, :to => :strategy
def self.strategies
[Strategies::NicoSeiga, Strategies::Pixa, Strategies::Pixiv, Strategies::Tinami]
[Strategies::NicoSeiga, Strategies::Pixiv]
end
def initialize(url)

View File

@@ -1,83 +0,0 @@
module Sources
module Strategies
class Pixa < Base
def self.url_match?(url)
url =~ /^https?:\/\/(?:\w+\.)?pixa\.cc/
end
def site_name
"Pixa"
end
def unique_id
profile_url =~ /\/show\/([^\/]+)/
"pixa" + $1
end
def get
agent.get(URI.parse(normalized_url).request_uri) do |page|
@artist_name, @profile_url = get_profile_from_page(page)
@image_url = get_image_url_from_page(page)
@tags = get_tags_from_page(page)
end
end
protected
def normalized_url
if url =~ /show_original/
url.sub(/show_original/, "show")
else
url
end
end
def get_profile_from_page(page)
links = page.search("p.profile_name a")
if links.any?
profile_url = "http://www.pixa.cc" + links[0]["href"]
artist_name = links[0].text
return [artist_name, profile_url]
else
return []
end
end
def get_image_url_from_page(page)
img = page.search("img.illust_image").first
if img
img.attr("src")
else
nil
end
end
def get_tags_from_page(page)
links = page.search("div#tag_list a")
if links.any?
links.map do |node|
[node.inner_text, "http://www.pixa.cc" + node.attr("href")]
end
else
[]
end
end
def agent
@agent ||= begin
mech = Mechanize.new
mech.get("http://www.pixa.cc") do |page|
page.form_with(:action => "/session") do |form|
form['email'] = Danbooru.config.pixa_login
form['password'] = Danbooru.config.pixa_password
end.click_button
end
mech
end
end
end
end
end

View File

@@ -1,81 +0,0 @@
module Sources
module Strategies
class Tinami < Base
def self.url_match?(url)
url =~ /^https?:\/\/(?:\w+\.)?tinami\.com/
end
def site_name
"Tinami"
end
def unique_id
profile_url =~ /\/profile\/(\d+)/
"tinami" + $1
end
def get
agent.get(URI.parse(url).request_uri) do |page|
@artist_name, @profile_url = get_profile_from_page(page)
@image_url = get_image_url_from_page(page)
@tags = get_tags_from_page(page)
end
end
protected
def get_profile_from_page(page)
links = page.search("div.prof a")
if links.any?
profile_url = "http://www.tinami.com" + links[0]["href"]
else
profile_url = nil
end
links = page.search("div.prof p a strong")
if links.any?
artist_name = links[0].text
else
artist_name = nil
end
return [artist_name, profile_url].compact
end
def get_image_url_from_page(page)
img = page.search("img.captify[rel=caption]").first
if img
img.attr("src")
else
nil
end
end
def get_tags_from_page(page)
links = page.search("div.tag a")
links.map do |node|
[node.text, "http://www.tinami.com" + node.attr("href")]
end
end
def agent
@agent ||= begin
mech = Mechanize.new
mech.get("http://www.tinami.com/login") do |page|
page.form_with do |form|
form["action_login"] = "true"
form['username'] = Danbooru.config.tinami_login
form['password'] = Danbooru.config.tinami_password
form["rem"] = "1"
end.click_button
end
mech
end
end
end
end
end

View File

@@ -1,5 +1,5 @@
class TagAlias < ActiveRecord::Base
before_save :clear_all_cache
after_save :clear_all_cache
after_save :update_cache
after_destroy :clear_all_cache
before_validation :initialize_creator, :on => :create
@@ -62,17 +62,14 @@ class TagAlias < ActiveRecord::Base
end
def clear_all_cache
clear_cache
clear_remote_cache
Danbooru.config.all_server_hosts.each do |host|
delay.clear_cache(host)
end
end
def clear_cache
Cache.delete("ta:#{Cache.sanitize(antecedent_name)}")
end
def clear_remote_cache
Danbooru.config.other_server_hosts.each do |server|
Net::HTTP.delete(URI.parse("http://#{server}/tag_aliases/#{id}/cache"))
def clear_cache(host = Socket.gethostname)
if host == Socket.gethostname
Cache.delete("ta:#{Cache.sanitize(antecedent_name)}")
end
end