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