Merge branch 'master' into skeb
This commit is contained in:
@@ -3,17 +3,17 @@ module Sources
|
||||
def self.all
|
||||
[
|
||||
Strategies::Pixiv,
|
||||
Strategies::Fanbox,
|
||||
Strategies::NicoSeiga,
|
||||
Strategies::Twitter,
|
||||
Strategies::Tumblr,
|
||||
Strategies::NicoSeiga,
|
||||
Strategies::Stash, # must come before DeviantArt
|
||||
Strategies::DeviantArt,
|
||||
Strategies::Tumblr,
|
||||
Strategies::ArtStation,
|
||||
Strategies::Nijie,
|
||||
Strategies::Mastodon,
|
||||
Strategies::Moebooru,
|
||||
Strategies::Nijie,
|
||||
Strategies::ArtStation,
|
||||
Strategies::HentaiFoundry,
|
||||
Strategies::Fanbox,
|
||||
Strategies::Mastodon,
|
||||
Strategies::Weibo,
|
||||
Strategies::Newgrounds,
|
||||
Strategies::Skeb
|
||||
@@ -21,7 +21,7 @@ module Sources
|
||||
end
|
||||
|
||||
def self.find(url, referer = nil, default: Strategies::Null)
|
||||
strategy = all.map { |strategy| strategy.new(url, referer) }.detect(&:match?)
|
||||
strategy = all.lazy.map { |s| s.new(url, referer) }.detect(&:match?)
|
||||
strategy || default&.new(url, referer)
|
||||
end
|
||||
|
||||
|
||||
@@ -64,6 +64,10 @@ module Sources
|
||||
|
||||
# XXX should go in dedicated strategies.
|
||||
case host
|
||||
when /amazon\.(com|jp|co\.jp)\z/i
|
||||
"Amazon"
|
||||
when /ask\.fm\z/i
|
||||
"Ask.fm"
|
||||
when /bcy\.net\z/i
|
||||
"BCY"
|
||||
when /booth\.pm\z/i
|
||||
@@ -72,6 +76,10 @@ module Sources
|
||||
"Circle.ms"
|
||||
when /dlsite\.(com|net)\z/i
|
||||
"DLSite"
|
||||
when /doujinshi\.mugimugi\.org\z/i, /doujinshi\.org\z/i
|
||||
"Doujinshi.org"
|
||||
when /erogamescape\.dyndns\.org\z/i
|
||||
"Erogamescape"
|
||||
when /facebook\.com\z/i
|
||||
"Facebook"
|
||||
when /fantia\.jp\z/i
|
||||
@@ -82,18 +90,42 @@ module Sources
|
||||
"Gumroad"
|
||||
when /instagram\.com\z/i
|
||||
"Instagram"
|
||||
when /ko-fi\.com\z/i
|
||||
"Ko-fi"
|
||||
when /livedoor\.(jp|com)\z/i
|
||||
"Livedoor"
|
||||
when /lofter\.com\z/i
|
||||
"Lofter"
|
||||
when /mangaupdates\.com\z/i
|
||||
"Mangaupdates"
|
||||
when /melonbooks\.co\.jp\z/i
|
||||
"Melonbooks"
|
||||
when /mihuashi\.com\z/i
|
||||
"Mihuashi"
|
||||
when /mixi\.jp\z/i
|
||||
"Mixi.jp"
|
||||
when /patreon\.com\z/i
|
||||
"Patreon"
|
||||
when /piapro\.jp\z/i
|
||||
"Piapro.jp"
|
||||
when /picarto\.tv\z/i
|
||||
"Picarto"
|
||||
when /privatter\.net\z/i
|
||||
"Privatter"
|
||||
when /sakura\.ne\.jp\z/i
|
||||
"Sakura.ne.jp"
|
||||
when /stickam\.jp\z/i
|
||||
"Stickam"
|
||||
when /skeb\.jp\z/i
|
||||
"Skeb"
|
||||
when /tinami\.com\z/i
|
||||
"Tinami"
|
||||
when /toranoana\.(jp|shop)\z/i
|
||||
"Toranoana"
|
||||
when /twitch\.tv\z/i
|
||||
"Twitch"
|
||||
when /wikipedia\.org\z/i
|
||||
"Wikipedia"
|
||||
when /youtube\.com\z/i
|
||||
"Youtube"
|
||||
else
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
module Sources::Strategies
|
||||
class Mastodon < Base
|
||||
HOST = %r{\Ahttps?://(?:www\.)?(?<domain>pawoo\.net|baraag\.net)}i
|
||||
IMAGE = %r{\Ahttps?://(?:img\.pawoo\.net|baraag\.net)/media_attachments/files/(\d+/\d+/\d+)}
|
||||
IMAGE = %r{\Ahttps?://(?:img\.pawoo\.net|baraag\.net(?:/system(?:/cache)?)?)/media_attachments/files/((?:\d+/)+\d+)}
|
||||
NAMED_PROFILE = %r{#{HOST}/@(?<artist_name>\w+)}i
|
||||
ID_PROFILE = %r{#{HOST}/web/accounts/(?<account_id>\d+)}
|
||||
|
||||
@@ -35,6 +35,7 @@ module Sources::Strategies
|
||||
def file_host
|
||||
case site_name
|
||||
when "pawoo.net" then "img.pawoo.net"
|
||||
when "baraag.net" then "baraag.net/system"
|
||||
else site_name
|
||||
end
|
||||
end
|
||||
@@ -85,7 +86,7 @@ module Sources::Strategies
|
||||
end
|
||||
|
||||
def artist_name_from_url
|
||||
url[NAMED_PROFILE, :artist_name]
|
||||
urls.map { |url| url[NAMED_PROFILE, :artist_name] }.compact.first
|
||||
end
|
||||
|
||||
def other_names
|
||||
@@ -93,7 +94,7 @@ module Sources::Strategies
|
||||
end
|
||||
|
||||
def account_id
|
||||
url[ID_PROFILE, :account_id] || api_response.account_id
|
||||
urls.map { |url| url[ID_PROFILE, :account_id] }.compact.first || api_response.account_id
|
||||
end
|
||||
|
||||
def status_id_from_url
|
||||
|
||||
@@ -212,34 +212,57 @@ module Sources
|
||||
return nil if page_url.blank? || client.blank?
|
||||
|
||||
response = client.cache(1.minute).get(page_url)
|
||||
return nil unless response.status == 200
|
||||
|
||||
response&.parse
|
||||
if response.status != 200 || response.parse.search("#login_illust").present?
|
||||
clear_cached_session_cookie!
|
||||
else
|
||||
response.parse
|
||||
end
|
||||
end
|
||||
memoize :page
|
||||
|
||||
def client
|
||||
nijie = http.timeout(60).use(retriable: { max_retries: 20 })
|
||||
|
||||
cookie = Cache.get("nijie-session-cookie", 1.week) do
|
||||
login_page = nijie.get("https://nijie.info/login.php").parse
|
||||
form = {
|
||||
email: Danbooru.config.nijie_login,
|
||||
password: Danbooru.config.nijie_password,
|
||||
url: login_page.at("input[name='url']")["value"],
|
||||
save: "on",
|
||||
ticket: ""
|
||||
}
|
||||
response = nijie.post("https://nijie.info/login_int.php", form: form)
|
||||
DanbooruLogger.info "Nijie login failed (#{url}, #{response.status})" if response.status != 200
|
||||
return nil unless response.status == 200
|
||||
|
||||
response.cookies.select { |c| c.name == "NIJIEIJIEID" }.compact.first
|
||||
end
|
||||
|
||||
nijie.cookies(NIJIEIJIEID: cookie, R18: 1)
|
||||
return nil if cached_session_cookie.nil?
|
||||
http.cookies(NIJIEIJIEID: cached_session_cookie, R18: 1)
|
||||
end
|
||||
memoize :client
|
||||
|
||||
def http
|
||||
super.timeout(60).use(retriable: { max_retries: 20 })
|
||||
end
|
||||
|
||||
def cached_session_cookie
|
||||
Cache.get("nijie-session-cookie", 60.minutes, skip_nil: true) do
|
||||
session_cookie
|
||||
end
|
||||
end
|
||||
|
||||
def clear_cached_session_cookie!
|
||||
flush_cache # clear memoized session cookie
|
||||
Cache.delete("nijie-session-cookie")
|
||||
end
|
||||
|
||||
def session_cookie
|
||||
login_page = http.get("https://nijie.info/login.php").parse
|
||||
|
||||
form = {
|
||||
email: Danbooru.config.nijie_login,
|
||||
password: Danbooru.config.nijie_password,
|
||||
url: login_page.at("input[name='url']")["value"],
|
||||
save: "on",
|
||||
ticket: ""
|
||||
}
|
||||
|
||||
response = http.post("https://nijie.info/login_int.php", form: form)
|
||||
|
||||
if response.status == 200
|
||||
response.cookies.select { |c| c.name == "NIJIEIJIEID" }.compact.first
|
||||
else
|
||||
DanbooruLogger.info "Nijie login failed (#{url}, #{response.status})"
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
memoize :client, :cached_session_cookie
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -30,6 +30,7 @@ module Sources::Strategies
|
||||
/(?<!\A)誕生祭(?:\d*)\z/,
|
||||
/(?<!\A)版もうひとつの深夜の真剣お絵描き60分一本勝負(?:_\d+)?\z/,
|
||||
/(?<!\A)版深夜の真剣お絵描き60分一本勝負(?:_\d+)?\z/,
|
||||
/(?<!\A)版深夜の真剣お絵かき60分一本勝負(?:_\d+)?\z/,
|
||||
/(?<!\A)深夜の真剣お絵描き60分一本勝負(?:_\d+)?\z/,
|
||||
/(?<!\A)版深夜のお絵描き60分一本勝負(?:_\d+)?\z/,
|
||||
/(?<!\A)版真剣お絵描き60分一本勝(?:_\d+)?\z/,
|
||||
|
||||
Reference in New Issue
Block a user