forked from e621ng/e621ng
added tinami support
This commit is contained in:
parent
006ddf5625
commit
dc31e74809
1
Gemfile
1
Gemfile
@ -33,4 +33,5 @@ gem 'rmagick', :require => "RMagick"
|
||||
|
||||
group :development do
|
||||
gem 'pry'
|
||||
gem 'awesome_print'
|
||||
end
|
||||
|
@ -54,6 +54,7 @@ GEM
|
||||
activesupport (3.1.0)
|
||||
multi_json (~> 1.0)
|
||||
arel (2.2.1)
|
||||
awesome_print (0.4.0)
|
||||
bcrypt-ruby (3.0.1)
|
||||
builder (3.0.0)
|
||||
chronic (0.6.4)
|
||||
@ -172,6 +173,7 @@ PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
awesome_print
|
||||
delayed_job
|
||||
factory_girl
|
||||
ffaker!
|
||||
|
@ -1,7 +1,7 @@
|
||||
module Sources
|
||||
module Strategies
|
||||
class Base
|
||||
attr_reader :url, :agent
|
||||
attr_reader :url
|
||||
|
||||
def self.url_match?(url)
|
||||
false
|
||||
@ -9,7 +9,6 @@ module Sources
|
||||
|
||||
def initialize(url)
|
||||
@url = url
|
||||
@agent = create_agent
|
||||
end
|
||||
|
||||
def get
|
||||
@ -49,7 +48,7 @@ module Sources
|
||||
end
|
||||
|
||||
protected
|
||||
def create_agent
|
||||
def agent
|
||||
raise NotImplementedError
|
||||
end
|
||||
end
|
||||
|
@ -81,18 +81,20 @@ module Sources
|
||||
end
|
||||
end
|
||||
|
||||
def create_agent
|
||||
mech = Mechanize.new
|
||||
def agent
|
||||
@agent ||= begin
|
||||
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
|
||||
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
|
||||
|
||||
mech
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,28 +1,87 @@
|
||||
module Sources
|
||||
module Strategies
|
||||
class Tinami < Base
|
||||
attr_reader :artist_name, :profile_url, :image_url, :tags
|
||||
|
||||
def self.url_match?(url)
|
||||
url =~ /^https?:\/\/(?:\w+\.)?tinami\.com/
|
||||
end
|
||||
|
||||
def site_name
|
||||
"Tinami"
|
||||
end
|
||||
|
||||
def artist_name
|
||||
"?"
|
||||
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
|
||||
|
||||
def profile_url
|
||||
def normalized_url
|
||||
url
|
||||
end
|
||||
|
||||
def image_url
|
||||
url
|
||||
end
|
||||
|
||||
def tags
|
||||
[]
|
||||
def unique_id
|
||||
profile_url =~ /\/profile\/(\d+)/
|
||||
"tinami" + $1
|
||||
end
|
||||
|
||||
protected
|
||||
def create_agent
|
||||
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'] = "r888888888@gmail.com"
|
||||
form['password'] = "uroobnad556"
|
||||
form["rem"] = "1"
|
||||
end.click_button
|
||||
end
|
||||
|
||||
mech
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -5,6 +5,26 @@ require 'test_helper'
|
||||
module Sources
|
||||
class SiteTest < ActiveSupport::TestCase
|
||||
context "The source site" do
|
||||
context "for tinami" do
|
||||
setup do
|
||||
@site = Sources::Site.new("http://www.tinami.com/view/308311")
|
||||
@site.get
|
||||
end
|
||||
|
||||
should "get a single post" do
|
||||
assert_equal("http://www.tinami.com/creator/profile/29399", @site.profile_url)
|
||||
assert_match(/ROM/, @site.artist_name)
|
||||
assert_equal("http://img.tinami.com/illust2/img/336/4e80b9773c084.png", @site.image_url)
|
||||
assert(@site.tags.size > 0)
|
||||
end
|
||||
|
||||
should "convert a page into a json representation" do
|
||||
assert_nothing_raised do
|
||||
@site.to_json
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "for pixiv" do
|
||||
setup do
|
||||
@site = Sources::Site.new("http://www.pixiv.net/member_illust.php?mode=medium&illust_id=9646484")
|
||||
|
Loading…
Reference in New Issue
Block a user