Add Rule34.xxx support.

This commit is contained in:
evazion
2022-11-10 00:39:52 -06:00
parent 0bad53e6ac
commit ec87cffe02
4 changed files with 55 additions and 3 deletions

View File

@@ -1,11 +1,14 @@
# frozen_string_literal: true
# Source extractor for Gelbooru and Safebooru.org. The commentary and artist information are pulled from the
# booru post's source, while the translated tags include both the booru tags and the source's tags.
# Source extractor for Gelbooru-based sites, including Gelbooru, Safebooru.org, TBIB.org, and Rule34.xxx. The commentary
# and artist information are pulled from the booru post's source, while the translated tags include both the booru tags
# and the source's tags.
#
# @see Source::URL::Gelbooru
# @see https://gelbooru.com/index.php?page=wiki&s=view&id=18780 (howto:api)
# @see https://safebooru.org/index.php?page=help&topic=dapi
# @see https://tbib.org/
# @see https://rule34.xxx/index.php?page=help&topic=dapi
module Source
class Extractor
class Gelbooru < Source::Extractor

View File

@@ -5,7 +5,7 @@ class Source::URL::Gelbooru < Source::URL
attr_reader :post_id, :md5, :image_type, :full_image_url
def self.match?(url)
url.domain.in?(%w[gelbooru.com safebooru.org tbib.org])
url.domain.in?(%w[gelbooru.com safebooru.org tbib.org rule34.xxx])
end
def parse
@@ -15,18 +15,21 @@ class Source::URL::Gelbooru < Source::URL
# 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
# https://rule34.xxx/index.php?page=post&s=view&id=6961597
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
# https://rule34.xxx/index.php?page=post&s=list&md5=0a8fff70045826d2b39fcde4eed17584
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
# https://rule34.xxx/index.php?page=dapi&s=post&q=index&id=6961597&json=1
in _, "index.php" if params[:page] == "dapi" && params[:q] == "index" && params[:id].present?
@post_id = params[:id].to_i
@@ -45,6 +48,8 @@ class Source::URL::Gelbooru < Source::URL
# https://safebooru.org//images/4016/64779fbfc87020ed5fd94854fe973bc0.jpeg
# https://safebooru.org//samples/4016/sample_64779fbfc87020ed5fd94854fe973bc0.jpg?4196692
# https://safebooru.org/thumbnails/4016/thumbnail_64779fbfc87020ed5fd94854fe973bc0.jpg?4196692
# https://us.rule34.xxx//images/6120/0a8fff70045826d2b39fcde4eed17584.jpeg?6961597
# https://us.rule34.xxx/thumbnails/6120/thumbnail_0a8fff70045826d2b39fcde4eed17584.jpg?6961597
in _, ("images" | "samples" | "thumbnails") => image_type, /\A\d+\z/ => directory, /\A(?:sample_|thumbnail_)?(\h{32})\.\w+\z/
@md5 = $1
@post_id = query if query&.match?(/\A\d+\z/)
@@ -86,12 +91,14 @@ class Source::URL::Gelbooru < Source::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
# https://api.rule34.xxx/index.php?page=post&s=view&id=6961597
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
# https://api.rule34.xxx//index.php?page=dapi&s=post&q=index&tags=md5:0a8fff70045826d2b39fcde4eed17584
elsif md5.present?
"https://#{domain}/index.php?page=dapi&s=post&q=index&tags=md5:#{md5}"
end

View File

@@ -443,6 +443,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("https://rule34.xxx/index.php?page=post&s=view&id=6961597")
should_upload_successfully("http://lohas.nicoseiga.jp/o/910aecf08e542285862954017f8a33a8c32a8aec/1433298801/4937663")
should_upload_successfully("http://seiga.nicovideo.jp/seiga/im4937663")

View File

@@ -258,5 +258,46 @@ module Sources
)
end
end
context "Rule34.xxx:" do
# source: https://twitter.com/marushin_0214/status/1590260107405053954
context "A https://rule34.xxx/index.php?page=post&s=view&id=$post_id URL" do
strategy_should_work(
"https://rule34.xxx/index.php?page=post&s=view&id=6961597",
image_urls: ["https://api-cdn.rule34.xxx/images/6120/0a8fff70045826d2b39fcde4eed17584.jpeg"],
artist_name: "丸新🐟MaruShin",
profile_url: "https://twitter.com/marushin_0214",
tags: %w[bangs big_breasts black_shirt bloomers blue_archive blue_eyes blue_hair blue_jacket blush breasts check_commentary commentary commentary_request cowboy_shot curvy female halo highres holding hourglass_figure huge_breasts jacket lanyard large_breasts long_hair looking_at_viewer marushin_(denwa0214) official_alternate_costume parted_lips partially_unzipped sexually_suggestive shirt short_sleeves shorts simple_background solo sweat thick_thighs thigh_gap undressing voluptuous wet wet_clothes wet_shirt white_background yuuka_(blue_archive) yuuka_(gym_uniform)_(blue_archive) rating:e],
artist_commentary_desc: "いっぱい走ったね… https://t.co/n3ic5BIONP",
download_size: 201_643,
)
end
# source: https://twitter.com/marushin_0214/status/1590260107405053954
context "A https://rule34.xxx/index.php?page=post&s=list&md5=$md5 URL" do
strategy_should_work(
"https://rule34.xxx/index.php?page=post&s=list&md5=0a8fff70045826d2b39fcde4eed17584",
image_urls: ["https://api-cdn.rule34.xxx/images/6120/0a8fff70045826d2b39fcde4eed17584.jpeg"],
artist_name: "丸新🐟MaruShin",
profile_url: "https://twitter.com/marushin_0214",
tags: %w[bangs big_breasts black_shirt bloomers blue_archive blue_eyes blue_hair blue_jacket blush breasts check_commentary commentary commentary_request cowboy_shot curvy female halo highres holding hourglass_figure huge_breasts jacket lanyard large_breasts long_hair looking_at_viewer marushin_(denwa0214) official_alternate_costume parted_lips partially_unzipped sexually_suggestive shirt short_sleeves shorts simple_background solo sweat thick_thighs thigh_gap undressing voluptuous wet wet_clothes wet_shirt white_background yuuka_(blue_archive) yuuka_(gym_uniform)_(blue_archive) rating:e],
artist_commentary_desc: "いっぱい走ったね… https://t.co/n3ic5BIONP",
download_size: 201_643,
)
end
# source: https://twitter.com/marushin_0214/status/1590260107405053954
context "A https://rule34.xxx/images/$dir/$md5.jpg URL without a referer" do
strategy_should_work(
"https://rule34.xxx//images/6120/0a8fff70045826d2b39fcde4eed17584.jpeg?6961597",
image_urls: ["https://rule34.xxx//images/6120/0a8fff70045826d2b39fcde4eed17584.jpeg?6961597"],
artist_name: "丸新🐟MaruShin",
profile_url: "https://twitter.com/marushin_0214",
tags: %w[bangs big_breasts black_shirt bloomers blue_archive blue_eyes blue_hair blue_jacket blush breasts check_commentary commentary commentary_request cowboy_shot curvy female halo highres holding hourglass_figure huge_breasts jacket lanyard large_breasts long_hair looking_at_viewer marushin_(denwa0214) official_alternate_costume parted_lips partially_unzipped sexually_suggestive shirt short_sleeves shorts simple_background solo sweat thick_thighs thigh_gap undressing voluptuous wet wet_clothes wet_shirt white_background yuuka_(blue_archive) yuuka_(gym_uniform)_(blue_archive) rating:e],
artist_commentary_desc: "いっぱい走ったね… https://t.co/n3ic5BIONP",
download_size: 201_643,
)
end
end
end
end