Add TBIB.org support.

This commit is contained in:
evazion
2022-11-09 16:49:20 -06:00
parent 5b4856273f
commit 0bad53e6ac
3 changed files with 86 additions and 4 deletions

View File

@@ -1,11 +1,11 @@
# frozen_string_literal: true
# This covers both Gelbooru and Safebooru.
# This covers all Gelbooru-based sites.
class Source::URL::Gelbooru < Source::URL
attr_reader :post_id, :md5, :image_type, :full_image_url
def self.match?(url)
url.domain.in?(%w[safebooru.org gelbooru.com])
url.domain.in?(%w[gelbooru.com safebooru.org tbib.org])
end
def parse
@@ -14,16 +14,19 @@ class Source::URL::Gelbooru < Source::URL
# https://gelbooru.com/index.php?page=post&s=view&id=7798045
# https://www.gelbooru.com/index.php?page=post&s=view&id=7798045
# https://safebooru.org/index.php?page=post&s=view&id=4196948
# https://tbib.org/index.php?page=post&s=view&id=11509934
in _, "index.php" if params[:page] == "post" && params[:s] == "view" && params[:id].present?
@post_id = params[:id].to_i
# https://gelbooru.com/index.php?page=post&s=list&md5=99d9977d6c3aa185083a2da22bd8acfb
# https://safebooru.org/index.php?page=post&s=list&md5=99d9977d6c3aa185083a2da22bd8acfb
# https://tbib.org/index.php?page=post&s=list&md5=99d9977d6c3aa185083a2da22bd8acfb
in _, "index.php" if params[:page] == "post" && params[:s] == "list" && params[:md5].present?
@md5 = params[:md5]
# https://gelbooru.com/index.php?page=dapi&s=post&q=index&id=7798045&json=1
# https://safebooru.org/index.php?page=dapi&s=post&q=index&id=4196948&json=1
# https://tbib.org/index.php?page=dapi&s=post&q=index&id=11387341&json=1
in _, "index.php" if params[:page] == "dapi" && params[:q] == "index" && params[:id].present?
@post_id = params[:id].to_i
@@ -48,11 +51,15 @@ class Source::URL::Gelbooru < Source::URL
@image_type = image_type
@full_image_url = url.to_s if image_type == "images"
# Safebooru uses an unknown 40-byte hash for most image URLs.
# Safebooru and TBIB use an unknown 40-byte hash for most image URLs.
# https://safebooru.org//images/4016/d2f50befcdc304cbd9030f2d0832029f5fe8cccc.png
# https://safebooru.org//samples/4016/sample_ffc6c5705d31422ddbaa7478deb560c985d2ee71.jpg?4196970
# https://safebooru.org/thumbnails/4016/thumbnail_8d0664867c59acb3103bccd9a9a5562a193eadcd.jpg?4196980
in "safebooru.org", ("images" | "samples" | "thumbnails") => image_type, /\A\d+\z/ => directory, /\A(?:sample_|thumbnail_)?(\h{40})\.\w+\z/
#
# https://tbib.org//images/10754/afadcf830778bd1c9bf94899ace2c889d6bf2903.png
# https://tbib.org//samples/10754/sample_afadcf830778bd1c9bf94899ace2c889d6bf2903.jpg?11509246
# https://tbib.org/thumbnails/10754/thumbnail_afadcf830778bd1c9bf94899ace2c889d6bf2903.jpg?11509246
in ("safebooru.org" | "tbib.org"), ("images" | "samples" | "thumbnails") => image_type, /\A\d+\z/ => directory, /\A(?:sample_|thumbnail_)?(\h{40})\.\w+\z/
@hash = $1
@post_id = query if query&.match?(/\A\d+\z/)
@image_type = image_type
@@ -78,11 +85,13 @@ class Source::URL::Gelbooru < Source::URL
def api_url
# https://gelbooru.com//index.php?page=dapi&s=post&q=index&tags=id:7903922
# https://safebooru.org/index.php?page=dapi&s=post&q=index&tags=id:4197087
# https://tbib.org/index.php?page=dapi&s=post&q=index&tags=id:11509246
if post_id.present?
# "https://#{domain}/index.php?page=dapi&s=post&q=index&id=#{post_id}&json=1"
"https://#{domain}/index.php?page=dapi&s=post&q=index&tags=id:#{post_id}"
# https://gelbooru.com//index.php?page=dapi&s=post&q=index&tags=md5:338078144fe77c9e5f35dbb585e749ec
# https://safebooru.org/index.php?page=dapi&s=post&q=index&tags=md5:8c1fe66ff46d03725caa30135ad70e7e
# https://tbib.org/index.php?page=dapi&s=post&q=index&tags=md5:8c1fe66ff46d03725caa30135ad70e7e
elsif md5.present?
"https://#{domain}/index.php?page=dapi&s=post&q=index&tags=md5:#{md5}"
end

View File

@@ -442,6 +442,7 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest
should_upload_successfully("https://gelbooru.com/index.php?page=post&s=view&id=7798121")
should_upload_successfully("https://safebooru.org/index.php?page=post&s=view&id=4189916")
should_upload_successfully("https://tbib.org/index.php?page=post&s=view&id=11480218")
should_upload_successfully("http://lohas.nicoseiga.jp/o/910aecf08e542285862954017f8a33a8c32a8aec/1433298801/4937663")
should_upload_successfully("http://seiga.nicovideo.jp/seiga/im4937663")

View File

@@ -186,5 +186,77 @@ module Sources
)
end
end
context "TBIB:" do
# source: https://i.pximg.net/img-original/img/2021/10/24/09/53/44/93646177_p0.jpg
context "A https://tbib.org/images/$dir/$hash.jpg?$post_id URL without a referer" do
strategy_should_work(
"https://tbib.org//images/10725/febe33d5f6d46e21c073289bb9884d4e0630761c.jpg?11480218",
image_urls: ["https://tbib.org//images/10725/febe33d5f6d46e21c073289bb9884d4e0630761c.jpg?11480218"],
artist_name: "チー之介",
profile_url: "https://www.pixiv.net/users/57673194",
tags: %w[1girl ^^^ animal_ears black_bow black_bowtie black_gloves black_hair black_hairband black_skirt black_wings blue_flower blue_rose bow bowtie brooch center_frills changing_room cheesecake_(artist) collared_shirt commentary dated demon_wings fangs flower flying_sweatdrops frilled_hairband frilled_sleeves frills frown gloves hair_flower hair_ornament hair_over_one_eye hairband halloween halloween_costume high-waist_skirt highres horse_ears horse_girl indoors jack-o'-lantern_ornament jewelry lace-trimmed_gloves lace_trim long_hair looking_at_viewer make_up_in_halloween!_(umamusume) official_alternate_costume open_mouth orange_bow puffy_short_sleeves puffy_sleeves rice_shower_(make_up_vampire!)_(umamusume) rice_shower_(umamusume) rose shirt short_sleeves skirt skirt_bow solo spider_web_print standing star_ornament twitter_username umamusume purple_eyes white_shirt wings rating:q ウマ娘 ライスシャワー ハロウィンイラスト 二次創作 ウマ娘プリティーダービー ライスシャワー(ウマ娘) 更衣室 Make_up_Vampire! ドラキュライス 困り顔],
artist_commentary_title: "ハロウィンライス",
artist_commentary_desc: "更衣室でハロウィン衣装に着替えたあと「がおーっ!」のポーズを鏡の前で密かに練習してたら、見つかっちゃってあわてるライスシャワーを描きました。",
download_size: 771_175,
)
end
# source: https://i.pximg.net/img-original/img/2021/10/24/09/53/44/93646177_p0.jpg
context "A https://tbib.org/images/$dir/$hash.jpg URL without a referer" do
strategy_should_work(
"https://tbib.org//images/10725/febe33d5f6d46e21c073289bb9884d4e0630761c.jpg",
image_urls: ["https://tbib.org//images/10725/febe33d5f6d46e21c073289bb9884d4e0630761c.jpg"],
artist_name: nil,
profile_url: nil,
tags: [],
artist_commentary_title: nil,
artist_commentary_desc: nil,
)
end
# source: https://i.pximg.net/img-original/img/2021/10/24/09/53/44/93646177_p0.jpg
context "A https://tbib.org/images/$dir/$hash.jpg URL with a referer" do
strategy_should_work(
"https://tbib.org//images/10725/febe33d5f6d46e21c073289bb9884d4e0630761c.jpg",
referer: "https://tbib.org/index.php?page=post&s=view&id=11480218",
image_urls: ["https://tbib.org//images/10725/febe33d5f6d46e21c073289bb9884d4e0630761c.jpg"],
artist_name: "チー之介",
profile_url: "https://www.pixiv.net/users/57673194",
tags: %w[1girl ^^^ animal_ears black_bow black_bowtie black_gloves black_hair black_hairband black_skirt black_wings blue_flower blue_rose bow bowtie brooch center_frills changing_room cheesecake_(artist) collared_shirt commentary dated demon_wings fangs flower flying_sweatdrops frilled_hairband frilled_sleeves frills frown gloves hair_flower hair_ornament hair_over_one_eye hairband halloween halloween_costume high-waist_skirt highres horse_ears horse_girl indoors jack-o'-lantern_ornament jewelry lace-trimmed_gloves lace_trim long_hair looking_at_viewer make_up_in_halloween!_(umamusume) official_alternate_costume open_mouth orange_bow puffy_short_sleeves puffy_sleeves rice_shower_(make_up_vampire!)_(umamusume) rice_shower_(umamusume) rose shirt short_sleeves skirt skirt_bow solo spider_web_print standing star_ornament twitter_username umamusume purple_eyes white_shirt wings rating:q ウマ娘 ライスシャワー ハロウィンイラスト 二次創作 ウマ娘プリティーダービー ライスシャワー(ウマ娘) 更衣室 Make_up_Vampire! ドラキュライス 困り顔],
artist_commentary_title: "ハロウィンライス",
artist_commentary_desc: "更衣室でハロウィン衣装に着替えたあと「がおーっ!」のポーズを鏡の前で密かに練習してたら、見つかっちゃってあわてるライスシャワーを描きました。",
download_size: 771_175,
)
end
# source: https://i.pximg.net/img-original/img/2021/10/24/09/53/44/93646177_p0.jpg
context "A https://tbib.org/index.php?page=post&s=view&id=$post_id URL" do
strategy_should_work(
"https://tbib.org/index.php?page=post&s=view&id=11480218",
image_urls: ["https://tbib.org/images/10725/febe33d5f6d46e21c073289bb9884d4e0630761c.jpg"],
artist_name: "チー之介",
profile_url: "https://www.pixiv.net/users/57673194",
tags: %w[1girl ^^^ animal_ears black_bow black_bowtie black_gloves black_hair black_hairband black_skirt black_wings blue_flower blue_rose bow bowtie brooch center_frills changing_room cheesecake_(artist) collared_shirt commentary dated demon_wings fangs flower flying_sweatdrops frilled_hairband frilled_sleeves frills frown gloves hair_flower hair_ornament hair_over_one_eye hairband halloween halloween_costume high-waist_skirt highres horse_ears horse_girl indoors jack-o'-lantern_ornament jewelry lace-trimmed_gloves lace_trim long_hair looking_at_viewer make_up_in_halloween!_(umamusume) official_alternate_costume open_mouth orange_bow puffy_short_sleeves puffy_sleeves rice_shower_(make_up_vampire!)_(umamusume) rice_shower_(umamusume) rose shirt short_sleeves skirt skirt_bow solo spider_web_print standing star_ornament twitter_username umamusume purple_eyes white_shirt wings rating:q ウマ娘 ライスシャワー ハロウィンイラスト 二次創作 ウマ娘プリティーダービー ライスシャワー(ウマ娘) 更衣室 Make_up_Vampire! ドラキュライス 困り顔],
artist_commentary_title: "ハロウィンライス",
artist_commentary_desc: "更衣室でハロウィン衣装に着替えたあと「がおーっ!」のポーズを鏡の前で密かに練習してたら、見つかっちゃってあわてるライスシャワーを描きました。",
download_size: 771_175,
)
end
# source: https://i.pximg.net/img-original/img/2021/10/24/09/53/44/93646177_p0.jpg
context "A https://tbib.org/index.php?page=post&s=list&md5=$md5 URL" do
strategy_should_work(
"https://tbib.org/index.php?page=post&s=list&md5=8ca0f76e014175f11085d64932d980a5",
image_urls: ["https://tbib.org/images/10725/febe33d5f6d46e21c073289bb9884d4e0630761c.jpg"],
artist_name: "チー之介",
profile_url: "https://www.pixiv.net/users/57673194",
tags: %w[1girl ^^^ animal_ears black_bow black_bowtie black_gloves black_hair black_hairband black_skirt black_wings blue_flower blue_rose bow bowtie brooch center_frills changing_room cheesecake_(artist) collared_shirt commentary dated demon_wings fangs flower flying_sweatdrops frilled_hairband frilled_sleeves frills frown gloves hair_flower hair_ornament hair_over_one_eye hairband halloween halloween_costume high-waist_skirt highres horse_ears horse_girl indoors jack-o'-lantern_ornament jewelry lace-trimmed_gloves lace_trim long_hair looking_at_viewer make_up_in_halloween!_(umamusume) official_alternate_costume open_mouth orange_bow puffy_short_sleeves puffy_sleeves purple_eyes rice_shower_(make_up_vampire!)_(umamusume) rice_shower_(umamusume) rose shirt short_sleeves skirt skirt_bow solo spider_web_print standing star_ornament twitter_username umamusume white_shirt wings rating:q ウマ娘 ライスシャワー ハロウィンイラスト 二次創作 ウマ娘プリティーダービー ライスシャワー(ウマ娘) 更衣室 Make_up_Vampire! ドラキュライス 困り顔],
artist_commentary_title: "ハロウィンライス",
artist_commentary_desc: "更衣室でハロウィン衣装に着替えたあと「がおーっ!」のポーズを鏡の前で密かに練習してたら、見つかっちゃってあわてるライスシャワーを描きました。",
download_size: 771_175,
)
end
end
end
end