implemented pixa source
This commit is contained in:
@@ -1,28 +1,76 @@
|
||||
module Sources
|
||||
module Strategies
|
||||
class Pixa < Base
|
||||
attr_reader :artist_name, :profile_url, :image_url, :tags
|
||||
|
||||
def self.url_match?(url)
|
||||
url =~ /^https?:\/\/(?:\w+\.)?pixa\.cc/
|
||||
end
|
||||
|
||||
def site_name
|
||||
"Pixa"
|
||||
end
|
||||
|
||||
def artist_name
|
||||
"?"
|
||||
def unique_id
|
||||
image_url =~ /\/img\/([^\/]+)/
|
||||
$1
|
||||
end
|
||||
|
||||
def profile_url
|
||||
url
|
||||
end
|
||||
|
||||
def image_url
|
||||
url
|
||||
end
|
||||
|
||||
def tags
|
||||
[]
|
||||
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 create_agent
|
||||
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
|
||||
|
||||
@@ -7,10 +7,6 @@ module Sources
|
||||
url =~ /^https?:\/\/(?:\w+\.)?pixiv\.net/
|
||||
end
|
||||
|
||||
def initialize(url)
|
||||
super
|
||||
end
|
||||
|
||||
def site_name
|
||||
"Pixiv"
|
||||
end
|
||||
|
||||
@@ -258,5 +258,13 @@ module Danbooru
|
||||
def nico_seiga_password
|
||||
nil
|
||||
end
|
||||
|
||||
def pixa_login
|
||||
nil
|
||||
end
|
||||
|
||||
def pixa_password
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user