Fix #3138: Support DeviantArt login-only works.
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
module Sources
|
module Sources
|
||||||
module Strategies
|
module Strategies
|
||||||
class DeviantArt < Base
|
class DeviantArt < Base
|
||||||
|
DEVIANTART_SESSION_CACHE_KEY = "deviantart-session"
|
||||||
|
|
||||||
def self.url_match?(url)
|
def self.url_match?(url)
|
||||||
url =~ /^https?:\/\/(?:.+?\.)?deviantart\.(?:com|net)/
|
url =~ /^https?:\/\/(?:.+?\.)?deviantart\.(?:com|net)/
|
||||||
end
|
end
|
||||||
@@ -152,16 +154,49 @@ module Sources
|
|||||||
def agent
|
def agent
|
||||||
@agent ||= begin
|
@agent ||= begin
|
||||||
mech = Mechanize.new
|
mech = Mechanize.new
|
||||||
|
auth, userinfo = session_cookies(mech)
|
||||||
|
|
||||||
# This cookie needs to be set to allow viewing of mature works
|
# This cookie needs to be set to allow viewing of mature works
|
||||||
cookie = Mechanize::Cookie.new("agegate_state", "1")
|
cookie = Mechanize::Cookie.new("agegate_state", "1")
|
||||||
cookie.domain = ".deviantart.com"
|
cookie.domain = ".deviantart.com"
|
||||||
cookie.path = "/"
|
cookie.path = "/"
|
||||||
mech.cookie_jar.add(cookie)
|
mech.cookie_jar.add(cookie)
|
||||||
|
|
||||||
|
cookie = Mechanize::Cookie.new("auth", auth)
|
||||||
|
cookie.domain = ".deviantart.com"
|
||||||
|
cookie.path = "/"
|
||||||
|
mech.cookie_jar.add(cookie)
|
||||||
|
|
||||||
|
cookie = Mechanize::Cookie.new("userinfo", userinfo)
|
||||||
|
cookie.domain = ".deviantart.com"
|
||||||
|
cookie.path = "/"
|
||||||
|
mech.cookie_jar.add(cookie)
|
||||||
|
|
||||||
mech
|
mech
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def session_cookies(mech)
|
||||||
|
Cache.get(DEVIANTART_SESSION_CACHE_KEY, 2.hours) do
|
||||||
|
page = mech.get("https://www.deviantart.com/users/login")
|
||||||
|
validate_key = page.search('input[name="validate_key"]').attribute("value").value
|
||||||
|
validate_token = page.search('input[name="validate_token"]').attribute("value").value
|
||||||
|
|
||||||
|
mech.post("https://www.deviantart.com/users/login", {
|
||||||
|
username: Danbooru.config.deviantart_login,
|
||||||
|
password: Danbooru.config.deviantart_password,
|
||||||
|
validate_key: validate_key,
|
||||||
|
validate_token: validate_token,
|
||||||
|
remember_me: 1,
|
||||||
|
})
|
||||||
|
|
||||||
|
auth = mech.cookies.find { |cookie| cookie.name == "auth" }.value
|
||||||
|
userinfo = mech.cookies.find { |cookie| cookie.name == "userinfo" }.value
|
||||||
|
mech.cookie_jar.clear
|
||||||
|
|
||||||
|
[auth, userinfo]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -359,6 +359,14 @@ module Danbooru
|
|||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def deviantart_login
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def deviantart_password
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
def enable_dimension_autotagging
|
def enable_dimension_autotagging
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ module Sources
|
|||||||
@site.get
|
@site.get
|
||||||
end
|
end
|
||||||
|
|
||||||
should_eventually "get the image url" do
|
should "get the image url" do
|
||||||
assert_equal("http://orig14.deviantart.net/cb25/f/2017/160/1/9/hidden_work_by_noizave-dbc3r29.png", @site.image_url)
|
assert_equal("http://orig14.deviantart.net/cb25/f/2017/160/1/9/hidden_work_by_noizave-dbc3r29.png", @site.image_url)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user