refactored sources
This commit is contained in:
@@ -2,6 +2,7 @@ module Sources
|
|||||||
module Strategies
|
module Strategies
|
||||||
class Base
|
class Base
|
||||||
attr_reader :url
|
attr_reader :url
|
||||||
|
attr_reader :artist_name, :profile_url, :image_url, :tags
|
||||||
|
|
||||||
def self.url_match?(url)
|
def self.url_match?(url)
|
||||||
false
|
false
|
||||||
@@ -11,6 +12,7 @@ module Sources
|
|||||||
@url = url
|
@url = url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# No remote calls are made until this method is called.
|
||||||
def get
|
def get
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
end
|
||||||
@@ -19,26 +21,6 @@ module Sources
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
end
|
end
|
||||||
|
|
||||||
def artist_name
|
|
||||||
raise NotImplementedError
|
|
||||||
end
|
|
||||||
|
|
||||||
def tags
|
|
||||||
raise NotImplementedError
|
|
||||||
end
|
|
||||||
|
|
||||||
def profile_url
|
|
||||||
raise NotImplementedError
|
|
||||||
end
|
|
||||||
|
|
||||||
def image_url
|
|
||||||
raise NotImplementedError
|
|
||||||
end
|
|
||||||
|
|
||||||
def artist_alias
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def unique_id
|
def unique_id
|
||||||
artist_name
|
artist_name
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
module Sources
|
module Sources
|
||||||
module Strategies
|
module Strategies
|
||||||
class NicoSeiga < Base
|
class NicoSeiga < Base
|
||||||
attr_reader :artist_name, :profile_url, :image_url, :tags
|
|
||||||
|
|
||||||
def self.url_match?(url)
|
def self.url_match?(url)
|
||||||
url =~ /^https?:\/\/(?:\w+\.)?nico(?:seiga|video)\.jp/
|
url =~ /^https?:\/\/(?:\w+\.)?nico(?:seiga|video)\.jp/
|
||||||
end
|
end
|
||||||
@@ -11,25 +9,21 @@ module Sources
|
|||||||
"Nico Seiga"
|
"Nico Seiga"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def unique_id
|
||||||
|
profile_url =~ /\/illust\/(\d+)/
|
||||||
|
"nicoseiga" + $1
|
||||||
|
end
|
||||||
|
|
||||||
def get
|
def get
|
||||||
url = URI.parse(normalized_url).request_uri
|
agent.get(URI.parse(url).request_uri) do |page|
|
||||||
agent.get(url) do |page|
|
|
||||||
@artist_name, @profile_url = get_profile_from_page(page)
|
@artist_name, @profile_url = get_profile_from_page(page)
|
||||||
@image_url = get_image_url_from_page(page)
|
@image_url = get_image_url_from_page(page)
|
||||||
@tags = get_tags_from_page(page)
|
@tags = get_tags_from_page(page)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalized_url
|
|
||||||
url
|
|
||||||
end
|
|
||||||
|
|
||||||
def unique_id
|
|
||||||
profile_url =~ /\/illust\/(\d+)/
|
|
||||||
"nicoseiga" + $1
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def get_profile_from_page(page)
|
def get_profile_from_page(page)
|
||||||
links = page.search("div.illust_user_name a")
|
links = page.search("div.illust_user_name a")
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
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)
|
def self.url_match?(url)
|
||||||
url =~ /^https?:\/\/(?:\w+\.)?pixa\.cc/
|
url =~ /^https?:\/\/(?:\w+\.)?pixa\.cc/
|
||||||
end
|
end
|
||||||
@@ -12,8 +10,8 @@ module Sources
|
|||||||
end
|
end
|
||||||
|
|
||||||
def unique_id
|
def unique_id
|
||||||
image_url =~ /\/img\/([^\/]+)/
|
profile_url =~ /\/show\/([^\/]+)/
|
||||||
$1
|
"pixa" + $1
|
||||||
end
|
end
|
||||||
|
|
||||||
def get
|
def get
|
||||||
@@ -25,6 +23,7 @@ module Sources
|
|||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def get_profile_from_page(page)
|
def get_profile_from_page(page)
|
||||||
links = page.search("p.profile_name a")
|
links = page.search("p.profile_name a")
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
module Sources
|
module Sources
|
||||||
module Strategies
|
module Strategies
|
||||||
class Pixiv < Base
|
class Pixiv < Base
|
||||||
attr_reader :artist_name, :profile_url, :image_url, :tags
|
|
||||||
|
|
||||||
def self.url_match?(url)
|
def self.url_match?(url)
|
||||||
url =~ /^https?:\/\/(?:\w+\.)?pixiv\.net/
|
url =~ /^https?:\/\/(?:\w+\.)?pixiv\.net/
|
||||||
end
|
end
|
||||||
@@ -17,8 +15,7 @@ module Sources
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get
|
def get
|
||||||
url = URI.parse(normalized_url).request_uri
|
agent.get(URI.parse(normalized_url).request_uri) do |page|
|
||||||
agent.get(url) do |page|
|
|
||||||
@artist_name, @profile_url = get_profile_from_page(page)
|
@artist_name, @profile_url = get_profile_from_page(page)
|
||||||
@image_url = get_image_url_from_page(page)
|
@image_url = get_image_url_from_page(page)
|
||||||
@tags = get_tags_from_page(page)
|
@tags = get_tags_from_page(page)
|
||||||
@@ -26,7 +23,7 @@ module Sources
|
|||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def get_profile_from_page(page)
|
def get_profile_from_page(page)
|
||||||
links = page.search("div.front-subContent a").find_all do |node|
|
links = page.search("div.front-subContent a").find_all do |node|
|
||||||
node["href"] =~ /member\.php/
|
node["href"] =~ /member\.php/
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
module Sources
|
module Sources
|
||||||
module Strategies
|
module Strategies
|
||||||
class Tinami < Base
|
class Tinami < Base
|
||||||
attr_reader :artist_name, :profile_url, :image_url, :tags
|
|
||||||
|
|
||||||
def self.url_match?(url)
|
def self.url_match?(url)
|
||||||
url =~ /^https?:\/\/(?:\w+\.)?tinami\.com/
|
url =~ /^https?:\/\/(?:\w+\.)?tinami\.com/
|
||||||
end
|
end
|
||||||
@@ -11,26 +9,19 @@ module Sources
|
|||||||
"Tinami"
|
"Tinami"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def unique_id
|
||||||
|
profile_url =~ /\/profile\/(\d+)/
|
||||||
|
"tinami" + $1
|
||||||
|
end
|
||||||
|
|
||||||
def get
|
def get
|
||||||
url = URI.parse(normalized_url).request_uri
|
agent.get(URI.parse(url).request_uri) do |page|
|
||||||
agent.get(url) do |page|
|
|
||||||
@artist_name, @profile_url = get_profile_from_page(page)
|
@artist_name, @profile_url = get_profile_from_page(page)
|
||||||
@image_url = get_image_url_from_page(page)
|
@image_url = get_image_url_from_page(page)
|
||||||
@tags = get_tags_from_page(page)
|
@tags = get_tags_from_page(page)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalized_url
|
|
||||||
# http://localhost:3000/uploads/new?url=http%3A%2F%2Fwww.tinami.com%2Fview%2F308872
|
|
||||||
# http://img.tinami.com/illust2/img/259/4e82154d61e74.jpg
|
|
||||||
url
|
|
||||||
end
|
|
||||||
|
|
||||||
def unique_id
|
|
||||||
profile_url =~ /\/profile\/(\d+)/
|
|
||||||
"tinami" + $1
|
|
||||||
end
|
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def get_profile_from_page(page)
|
def get_profile_from_page(page)
|
||||||
links = page.search("div.prof a")
|
links = page.search("div.prof a")
|
||||||
|
|||||||
Reference in New Issue
Block a user