Fix #5354: Add bookmarklet support for picdig.net.
This commit is contained in:
@@ -141,6 +141,7 @@ module ArtistFinder
|
|||||||
"poipiku.com", # https://poipiku.com/1776623/
|
"poipiku.com", # https://poipiku.com/1776623/
|
||||||
"pomf.tv", # https://pomf.tv/oozutsucannon
|
"pomf.tv", # https://pomf.tv/oozutsucannon
|
||||||
"pomf.tv/stream", # https://pomf.tv/stream/Kukseleg
|
"pomf.tv/stream", # https://pomf.tv/stream/Kukseleg
|
||||||
|
"picdig.net", # https://picdig.net/kenny8686/portfolio
|
||||||
"plala.or.jp", # http://www7.plala.or.jp/reirei
|
"plala.or.jp", # http://www7.plala.or.jp/reirei
|
||||||
"plurk.com", # http://www.plurk.com/a1amorea1a1
|
"plurk.com", # http://www.plurk.com/a1amorea1a1
|
||||||
"pornhub.com", # https://www.pornhub.com/model/mizzpeachy
|
"pornhub.com", # https://www.pornhub.com/model/mizzpeachy
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ module Source
|
|||||||
Source::Extractor::Bilibili,
|
Source::Extractor::Bilibili,
|
||||||
Source::Extractor::Rule34DotUs,
|
Source::Extractor::Rule34DotUs,
|
||||||
Source::Extractor::FourChan,
|
Source::Extractor::FourChan,
|
||||||
|
Source::Extractor::Picdig,
|
||||||
]
|
]
|
||||||
|
|
||||||
# Should return true if the extractor is configured correctly. Return false
|
# Should return true if the extractor is configured correctly. Return false
|
||||||
|
|||||||
83
app/logical/source/extractor/picdig.rb
Normal file
83
app/logical/source/extractor/picdig.rb
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# @see https://picdig.net/
|
||||||
|
# @see Source::URL::Picdig
|
||||||
|
module Source
|
||||||
|
class Extractor
|
||||||
|
class Picdig < Source::Extractor
|
||||||
|
def match?
|
||||||
|
Source::URL::Picdig === parsed_url
|
||||||
|
end
|
||||||
|
|
||||||
|
def image_urls
|
||||||
|
if parsed_url.image_url?
|
||||||
|
[parsed_url.to_s]
|
||||||
|
else
|
||||||
|
image_urls_from_commentary
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def image_urls_from_commentary
|
||||||
|
html = Nokogiri::HTML5.fragment(artist_commentary_desc)
|
||||||
|
html.css("img").map { |img| img[:src] }
|
||||||
|
end
|
||||||
|
|
||||||
|
def page_url
|
||||||
|
parsed_url.page_url || parsed_referer&.page_url
|
||||||
|
end
|
||||||
|
|
||||||
|
def profile_url
|
||||||
|
parsed_url.profile_url || parsed_referer&.profile_url
|
||||||
|
end
|
||||||
|
|
||||||
|
def profile_urls
|
||||||
|
[
|
||||||
|
api_response.dig(:user, :homepage_url),
|
||||||
|
api_response.dig(:user, :twitter_url),
|
||||||
|
api_response.dig(:user, :instagram_url),
|
||||||
|
api_response.dig(:user, :facebook_url),
|
||||||
|
api_response.dig(:user, :youtube_url),
|
||||||
|
].compact_blank
|
||||||
|
end
|
||||||
|
|
||||||
|
def tag_name
|
||||||
|
username
|
||||||
|
end
|
||||||
|
|
||||||
|
def artist_name
|
||||||
|
api_response.dig(:user, :name)
|
||||||
|
end
|
||||||
|
|
||||||
|
def artist_commentary_title
|
||||||
|
api_response[:title]
|
||||||
|
end
|
||||||
|
|
||||||
|
def artist_commentary_desc
|
||||||
|
api_response[:content]
|
||||||
|
end
|
||||||
|
|
||||||
|
def tags
|
||||||
|
api_response[:project_tags].to_a.map do |tag|
|
||||||
|
[tag[:name], "https://picdig.net/projects?search_tag=#{Danbooru::URL.escape(tag[:name])}"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def username
|
||||||
|
parsed_url.username || parsed_referer&.username
|
||||||
|
end
|
||||||
|
|
||||||
|
def api_url
|
||||||
|
parsed_url.api_page_url || parsed_referer&.api_page_url
|
||||||
|
end
|
||||||
|
|
||||||
|
memoize def api_response
|
||||||
|
return {} if api_url.blank?
|
||||||
|
|
||||||
|
response = http.cache(1.minute).get(api_url)
|
||||||
|
return {} unless response.status == 200
|
||||||
|
|
||||||
|
response.parse.with_indifferent_access.dig(:data, :project)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -62,6 +62,7 @@ module Source
|
|||||||
Source::URL::Bilibili,
|
Source::URL::Bilibili,
|
||||||
Source::URL::Rule34DotUs,
|
Source::URL::Rule34DotUs,
|
||||||
Source::URL::FourChan,
|
Source::URL::FourChan,
|
||||||
|
Source::URL::Picdig,
|
||||||
]
|
]
|
||||||
|
|
||||||
# Parse a URL into a subclass of Source::URL, or raise an exception if the URL is not a valid HTTP or HTTPS URL.
|
# Parse a URL into a subclass of Source::URL, or raise an exception if the URL is not a valid HTTP or HTTPS URL.
|
||||||
|
|||||||
61
app/logical/source/url/picdig.rb
Normal file
61
app/logical/source/url/picdig.rb
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# @see https://picdig.net/
|
||||||
|
# @see Source::Extractor::Picdig
|
||||||
|
class Source::URL::Picdig < Source::URL
|
||||||
|
RESERVED_NAMES = %w[api articles images my privacy-policy projects terms]
|
||||||
|
|
||||||
|
attr_reader :username, :account_id, :user_id, :project_id, :image_id
|
||||||
|
|
||||||
|
def self.match?(url)
|
||||||
|
url.domain == "picdig.net"
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse
|
||||||
|
case [domain, *path_segments]
|
||||||
|
|
||||||
|
# full: https://picdig.net/images/98a85315-ade6-42c7-b54a-a1ab7dc0c7da/54e476f5-f956-497d-b689-0db7e745907d/2021/12/b35f9c35-a37f-47b0-a5b6-e639a4535ce3.jpg (page: https://picdig.net/supercanoyan/projects/71c55605-3eca-4660-991c-ee24b9a7b684)
|
||||||
|
# thumb: https://picdig.net/images/98a85315-ade6-42c7-b54a-a1ab7dc0c7da/54e476f5-f956-497d-b689-0db7e745907d/2021/12/63fffa1f-2862-4aa6-80dc-b5a73d91ab43.png
|
||||||
|
in _, "images", /^[0-9a-f-]{36}$/ => account_id, /^[0-9a-f-]{36}$/ => user_id, /^\d{4}$/ => year, /^\d{2}$/ => month, /^([0-9a-f-]{36})\.\w+/
|
||||||
|
@account_id = account_id
|
||||||
|
@user_id = user_id
|
||||||
|
@image_id = $1
|
||||||
|
|
||||||
|
# avatar: https://picdig.net/images/98a85315-ade6-42c7-b54a-a1ab7dc0c7da/2021/12/9fadd3f4-c131-4f26-bce5-26c9d5bd4927.jpg
|
||||||
|
in _, "images", /^[0-9a-f-]{36}$/ => account_id, /^\d{4}$/ => year, /^\d{2}$/ => month, /^([0-9a-f-]{36})\.\w+/
|
||||||
|
@account_id = account_id
|
||||||
|
@image_id = $1
|
||||||
|
|
||||||
|
# https://picdig.net/supercanoyan/projects/71c55605-3eca-4660-991c-ee24b9a7b684
|
||||||
|
in _, username, "projects", /^[0-9a-f-]{36}$/ => project_id
|
||||||
|
@username = username
|
||||||
|
@project_id = project_id
|
||||||
|
|
||||||
|
# https://picdig.net/supercanoyan/portfolio
|
||||||
|
# https://picdig.net/supercanoyan/profile
|
||||||
|
# https://picdig.net/supercanoyan/collections
|
||||||
|
# https://picdig.net/supercanoyan/articles
|
||||||
|
in _, username, *rest unless username in RESERVED_NAMES
|
||||||
|
@username = username
|
||||||
|
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def image_url?
|
||||||
|
image_id.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def page_url
|
||||||
|
"https://picdig.net/#{username}/projects/#{project_id}" if username.present? && project_id.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def profile_url
|
||||||
|
"https://picdig.net/#{username}/portfolio" if username.present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def api_page_url
|
||||||
|
"https://picdig.net/api/users/#{username}/projects/#{project_id}" if username.present? && project_id.present?
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -603,6 +603,8 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
should_upload_successfully("http://www.tinami.com/view/1087268")
|
should_upload_successfully("http://www.tinami.com/view/1087268")
|
||||||
|
|
||||||
should_upload_successfully("https://booth.pximg.net/4ee2c0d9-41fa-4a0e-a30f-1bc9e15d4e5b/i/2586180/331b7c5f-7614-4772-aae2-cb979ad44a6b.png")
|
should_upload_successfully("https://booth.pximg.net/4ee2c0d9-41fa-4a0e-a30f-1bc9e15d4e5b/i/2586180/331b7c5f-7614-4772-aae2-cb979ad44a6b.png")
|
||||||
|
|
||||||
|
should_upload_successfully("https://picdig.net/apricot/projects/9d96c3f2-f92f-4472-856a-93779bb43527")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
92
test/unit/sources/picdig_test.rb
Normal file
92
test/unit/sources/picdig_test.rb
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
module Sources
|
||||||
|
class PicdigTest < ActiveSupport::TestCase
|
||||||
|
context "Picdig:" do
|
||||||
|
context "A Picdig project URL" do
|
||||||
|
strategy_should_work(
|
||||||
|
"https://picdig.net/ema/projects/9d99151f-6d3e-4084-9cc0-082d386122ca",
|
||||||
|
image_urls: %w[
|
||||||
|
https://picdig.net/images/e2fc48ae-7391-44a3-993a-ce093f797510/45057c9b-2709-4c1f-b00c-d9b44898db98/2021/11/42163c7d-16cb-4665-867e-f62b8133359d.png
|
||||||
|
https://picdig.net/images/e2fc48ae-7391-44a3-993a-ce093f797510/45057c9b-2709-4c1f-b00c-d9b44898db98/2021/11/7954f986-e471-4d41-9d06-16a1a695b42d.png
|
||||||
|
https://picdig.net/images/e2fc48ae-7391-44a3-993a-ce093f797510/45057c9b-2709-4c1f-b00c-d9b44898db98/2021/11/f921c899-b5f5-410b-8b4b-8287047f6b80.png
|
||||||
|
],
|
||||||
|
profile_url: "https://picdig.net/ema/portfolio",
|
||||||
|
profile_urls: %w[
|
||||||
|
https://twitter.com/Ema_azure
|
||||||
|
https://www.pixiv.net/users/41875383
|
||||||
|
],
|
||||||
|
page_url: "https://picdig.net/ema/projects/9d99151f-6d3e-4084-9cc0-082d386122ca",
|
||||||
|
artist_name: "絵馬",
|
||||||
|
tag_name: "ema",
|
||||||
|
other_names: ["絵馬", "ema"],
|
||||||
|
artist_commentary_title: "「わたしの季節」",
|
||||||
|
dtext_artist_commentary_desc: "「わたしの季節」このイラストのコンセプトや構図・配色についてご紹介!イラストコンセプト:''わたしの''秋イラストテーマは秋。秋のキャラクターイラストを思い浮かべるとき多くの人は秋の景色の中にいるキャラクターを連想すると思います。しかしこのイラストは 秋の中にいるわたし ではなく、「わたしの季節こそが秋なんだ!」そんなメッセージを込めて描いています。あくまで主役はキャラクター。だからこそキャラクターに自然と目線が向かうように構図や配色を考えました。日々勉強中ではありますが、大枠をこんな感じで考えて描いたイラストです(^^)本ページはここまで!お目通しありがとうございましたー・ー・ー・ー・ー・ー・ー・ー・ー・ー・ー・ー・ー・ー・ー水色の絵馬キャラクターイラストのお仕事をメインに募集中です。稚拙ではありますが背景付きのイラストも描いております。TwitterやPixivにも多くのイラストを成長の記録として掲載していますので気になる方はぜひご覧下さいね",
|
||||||
|
tags: [
|
||||||
|
%w[かわいい https://picdig.net/projects?search_tag=かわいい],
|
||||||
|
%w[キャラクターイラスト https://picdig.net/projects?search_tag=キャラクターイラスト],
|
||||||
|
%w[キャラクターデザイン https://picdig.net/projects?search_tag=キャラクターデザイン],
|
||||||
|
%w[一枚絵 https://picdig.net/projects?search_tag=一枚絵],
|
||||||
|
%w[女の子 https://picdig.net/projects?search_tag=女の子],
|
||||||
|
%w[秋 https://picdig.net/projects?search_tag=秋],
|
||||||
|
],
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "A Picdig image URL with a referer" do
|
||||||
|
strategy_should_work(
|
||||||
|
"https://picdig.net/images/e2fc48ae-7391-44a3-993a-ce093f797510/45057c9b-2709-4c1f-b00c-d9b44898db98/2021/11/42163c7d-16cb-4665-867e-f62b8133359d.png",
|
||||||
|
referer: "https://picdig.net/ema/projects/9d99151f-6d3e-4084-9cc0-082d386122ca",
|
||||||
|
image_urls: %w[
|
||||||
|
https://picdig.net/images/e2fc48ae-7391-44a3-993a-ce093f797510/45057c9b-2709-4c1f-b00c-d9b44898db98/2021/11/42163c7d-16cb-4665-867e-f62b8133359d.png
|
||||||
|
],
|
||||||
|
profile_url: "https://picdig.net/ema/portfolio",
|
||||||
|
profile_urls: %w[
|
||||||
|
https://twitter.com/Ema_azure
|
||||||
|
https://www.pixiv.net/users/41875383
|
||||||
|
],
|
||||||
|
page_url: "https://picdig.net/ema/projects/9d99151f-6d3e-4084-9cc0-082d386122ca",
|
||||||
|
artist_name: "絵馬",
|
||||||
|
tag_name: "ema",
|
||||||
|
other_names: ["絵馬", "ema"],
|
||||||
|
artist_commentary_title: "「わたしの季節」",
|
||||||
|
dtext_artist_commentary_desc: "「わたしの季節」このイラストのコンセプトや構図・配色についてご紹介!イラストコンセプト:''わたしの''秋イラストテーマは秋。秋のキャラクターイラストを思い浮かべるとき多くの人は秋の景色の中にいるキャラクターを連想すると思います。しかしこのイラストは 秋の中にいるわたし ではなく、「わたしの季節こそが秋なんだ!」そんなメッセージを込めて描いています。あくまで主役はキャラクター。だからこそキャラクターに自然と目線が向かうように構図や配色を考えました。日々勉強中ではありますが、大枠をこんな感じで考えて描いたイラストです(^^)本ページはここまで!お目通しありがとうございましたー・ー・ー・ー・ー・ー・ー・ー・ー・ー・ー・ー・ー・ー・ー水色の絵馬キャラクターイラストのお仕事をメインに募集中です。稚拙ではありますが背景付きのイラストも描いております。TwitterやPixivにも多くのイラストを成長の記録として掲載していますので気になる方はぜひご覧下さいね",
|
||||||
|
tags: [
|
||||||
|
%w[かわいい https://picdig.net/projects?search_tag=かわいい],
|
||||||
|
%w[キャラクターイラスト https://picdig.net/projects?search_tag=キャラクターイラスト],
|
||||||
|
%w[キャラクターデザイン https://picdig.net/projects?search_tag=キャラクターデザイン],
|
||||||
|
%w[一枚絵 https://picdig.net/projects?search_tag=一枚絵],
|
||||||
|
%w[女の子 https://picdig.net/projects?search_tag=女の子],
|
||||||
|
%w[秋 https://picdig.net/projects?search_tag=秋],
|
||||||
|
],
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "A Picdig image URL without a referer" do
|
||||||
|
strategy_should_work(
|
||||||
|
"https://picdig.net/images/e2fc48ae-7391-44a3-993a-ce093f797510/45057c9b-2709-4c1f-b00c-d9b44898db98/2021/11/42163c7d-16cb-4665-867e-f62b8133359d.png",
|
||||||
|
image_urls: %w[
|
||||||
|
https://picdig.net/images/e2fc48ae-7391-44a3-993a-ce093f797510/45057c9b-2709-4c1f-b00c-d9b44898db98/2021/11/42163c7d-16cb-4665-867e-f62b8133359d.png
|
||||||
|
],
|
||||||
|
profile_url: nil,
|
||||||
|
profile_urls: [],
|
||||||
|
page_url: nil,
|
||||||
|
artist_name: nil,
|
||||||
|
tag_name: nil,
|
||||||
|
other_names: [],
|
||||||
|
artist_commentary_title: nil,
|
||||||
|
artist_commentary_desc: nil,
|
||||||
|
tags: []
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "Parse Picdig URLs correctly" do
|
||||||
|
assert(Source::URL.image_url?("https://picdig.net/images/e2fc48ae-7391-44a3-993a-ce093f797510/45057c9b-2709-4c1f-b00c-d9b44898db98/2021/11/7954f986-e471-4d41-9d06-16a1a695b42d.png"))
|
||||||
|
assert(Source::URL.image_url?("https://picdig.net/images/e2fc48ae-7391-44a3-993a-ce093f797510/2022/01/141e8e69-d9cd-46ab-9b9b-62fd8a0d6e7e.png"))
|
||||||
|
assert(Source::URL.image_url?("https://picdig.net/images/e2fc48ae-7391-44a3-993a-ce093f797510/45057c9b-2709-4c1f-b00c-d9b44898db98/2022/04/365f52cb-3007-401e-a762-5452d774210d.png"))
|
||||||
|
assert(Source::URL.page_url?("https://picdig.net/ema/projects/9d99151f-6d3e-4084-9cc0-082d386122ca"))
|
||||||
|
assert(Source::URL.profile_url?("https://picdig.net/ema/portfolio"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user