renamed artsiteproxy to sources
This commit is contained in:
18
app/logical/sources/site.rb
Normal file
18
app/logical/sources/site.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
module Sources
|
||||
class Site
|
||||
attr_reader :url, :strategy
|
||||
delegate :artist_name, :profile_url, :image_url, :tags, :to => :strategy
|
||||
|
||||
def initialize(url)
|
||||
@url = url
|
||||
|
||||
case url
|
||||
when /pixiv\.net/
|
||||
@strategy = Strategies::Pixiv.new(url)
|
||||
|
||||
else
|
||||
@strategy = Strategies::Default.new(url)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
33
app/logical/sources/strategies/base.rb
Normal file
33
app/logical/sources/strategies/base.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
module Sources
|
||||
module Strategies
|
||||
class Base
|
||||
attr_reader :url, :agent
|
||||
|
||||
def initialize(url)
|
||||
@url = url
|
||||
@agent = create_agent
|
||||
end
|
||||
|
||||
def artist_name
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def tags
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def profile_url
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
def image_url
|
||||
raise NotImplementedError
|
||||
end
|
||||
|
||||
protected
|
||||
def create_agent
|
||||
raise NotImplementedError
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
25
app/logical/sources/strategies/default.rb
Normal file
25
app/logical/sources/strategies/default.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
module Sources
|
||||
module Strategies
|
||||
class Default < Base
|
||||
def artist_name
|
||||
"?"
|
||||
end
|
||||
|
||||
def profile_url
|
||||
url
|
||||
end
|
||||
|
||||
def image_url
|
||||
url
|
||||
end
|
||||
|
||||
def tags
|
||||
[]
|
||||
end
|
||||
|
||||
protected
|
||||
def create_agent
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
25
app/logical/sources/strategies/fc2.rb
Normal file
25
app/logical/sources/strategies/fc2.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
module Sources
|
||||
module Strategies
|
||||
class Fc2 < Base
|
||||
def artist_name
|
||||
"?"
|
||||
end
|
||||
|
||||
def profile_url
|
||||
url
|
||||
end
|
||||
|
||||
def image_url
|
||||
url
|
||||
end
|
||||
|
||||
def tags
|
||||
[]
|
||||
end
|
||||
|
||||
protected
|
||||
def create_agent
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
25
app/logical/sources/strategies/nico_seiga.rb
Normal file
25
app/logical/sources/strategies/nico_seiga.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
module Sources
|
||||
module Strategies
|
||||
class NicoSeiga < Base
|
||||
def artist_name
|
||||
"?"
|
||||
end
|
||||
|
||||
def profile_url
|
||||
url
|
||||
end
|
||||
|
||||
def image_url
|
||||
url
|
||||
end
|
||||
|
||||
def tags
|
||||
[]
|
||||
end
|
||||
|
||||
protected
|
||||
def create_agent
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
25
app/logical/sources/strategies/pixa.rb
Normal file
25
app/logical/sources/strategies/pixa.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
module Sources
|
||||
module Strategies
|
||||
class Pixa < Base
|
||||
def artist_name
|
||||
"?"
|
||||
end
|
||||
|
||||
def profile_url
|
||||
url
|
||||
end
|
||||
|
||||
def image_url
|
||||
url
|
||||
end
|
||||
|
||||
def tags
|
||||
[]
|
||||
end
|
||||
|
||||
protected
|
||||
def create_agent
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
91
app/logical/sources/strategies/pixiv.rb
Normal file
91
app/logical/sources/strategies/pixiv.rb
Normal file
@@ -0,0 +1,91 @@
|
||||
module Sources
|
||||
module Strategies
|
||||
class Pixiv < Base
|
||||
attr_reader :artist_name, :profile_url, :image_url, :tags
|
||||
|
||||
def initialize(url)
|
||||
super
|
||||
get
|
||||
end
|
||||
|
||||
def is_pixiv?
|
||||
url =~ /pixiv\.net/
|
||||
end
|
||||
|
||||
def get
|
||||
url = URI.parse(normalized_url).request_uri
|
||||
agent.get(url) 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.front-subContent a").find_all do |node|
|
||||
node["href"] =~ /member\.php/
|
||||
end
|
||||
|
||||
if links.any?
|
||||
profile_url = "http://www.pixiv.net/" + links[0]["href"]
|
||||
children = links[0].children
|
||||
artist = children[0]["alt"]
|
||||
return [artist, profile_url]
|
||||
else
|
||||
return []
|
||||
end
|
||||
end
|
||||
|
||||
def get_image_url_from_page(page)
|
||||
meta = page.search("meta[property=\"og:image\"]").first
|
||||
if meta
|
||||
meta.attr("content").sub(/_m\./, ".")
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def get_tags_from_page(page)
|
||||
links = page.search("div.pedia li a").find_all do |node|
|
||||
node["href"] =~ /tags\.php/
|
||||
end
|
||||
|
||||
if links.any?
|
||||
links.map do |node|
|
||||
[node.inner_text, "http://www.pixiv.net/" + node.attr("href")]
|
||||
end
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def normalized_url
|
||||
@normalized_url ||= begin
|
||||
if url =~ /\/(\d+)(_m|_p\d+)?\.(jpg|jpeg|png|gif)/i
|
||||
"http://www.pixiv.net/member_illust.php?mode=medium&illust_id=#{$1}"
|
||||
elsif url =~ /member_illust\.php/ && url =~ /illust_id=/
|
||||
url
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def create_agent
|
||||
mech = Mechanize.new
|
||||
|
||||
mech.get("http://www.pixiv.net") do |page|
|
||||
page.form_with(:action => "/login.php") do |form|
|
||||
form['mode'] = "login"
|
||||
form['login_pixiv_id'] = "uroobnad"
|
||||
form['pass'] = "uroobnad556"
|
||||
end.click_button
|
||||
end
|
||||
|
||||
mech
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
25
app/logical/sources/strategies/tinami.rb
Normal file
25
app/logical/sources/strategies/tinami.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
module Sources
|
||||
module Strategies
|
||||
class Tinami < Base
|
||||
def artist_name
|
||||
"?"
|
||||
end
|
||||
|
||||
def profile_url
|
||||
url
|
||||
end
|
||||
|
||||
def image_url
|
||||
url
|
||||
end
|
||||
|
||||
def tags
|
||||
[]
|
||||
end
|
||||
|
||||
protected
|
||||
def create_agent
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user