mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-04-11 05:57:37 +02:00
Add InkBunny Scraper
Also some mild adjustments to adverts
This commit is contained in:
parent
1767ba65ef
commit
677dc1ef49
9 changed files with 42 additions and 10 deletions
lib
philomena
philomena_web
|
@ -35,7 +35,7 @@ defmodule Philomena.Adverts do
|
|||
|
||||
defp sfw?(image) do
|
||||
image_tags = MapSet.new(image.tags |> Enum.map(& &1.name))
|
||||
sfw_tags = MapSet.new(["safe", "suggestive"])
|
||||
sfw_tags = MapSet.new(["clean", "suggestive"])
|
||||
intersect = MapSet.intersection(image_tags, sfw_tags)
|
||||
|
||||
MapSet.size(intersect) > 0
|
||||
|
@ -43,7 +43,7 @@ defmodule Philomena.Adverts do
|
|||
|
||||
defp nsfw?(image) do
|
||||
image_tags = MapSet.new(image.tags |> Enum.map(& &1.name))
|
||||
nsfw_tags = MapSet.new(["questionable", "explicit"])
|
||||
nsfw_tags = MapSet.new(["nude only", "explicit"])
|
||||
intersect = MapSet.intersection(image_tags, nsfw_tags)
|
||||
|
||||
MapSet.size(intersect) > 0
|
||||
|
|
|
@ -62,6 +62,6 @@ defmodule Philomena.Adverts.Advert do
|
|||
|> validate_inclusion(:image_mime_type, ["image/png", "image/jpeg", "image/gif"])
|
||||
|> validate_inclusion(:image_width, 699..729)
|
||||
|> validate_inclusion(:image_height, 79..91)
|
||||
|> validate_inclusion(:image_size, 0..750_000)
|
||||
|> validate_inclusion(:image_size, 0..950_000)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -108,8 +108,8 @@ defmodule Philomena.Images.TagValidator do
|
|||
|> MapSet.new()
|
||||
end
|
||||
|
||||
defp safe_rating, do: MapSet.new(["safe"])
|
||||
defp sexual_ratings, do: MapSet.new(["suggestive", "questionable", "explicit"])
|
||||
defp safe_rating, do: MapSet.new(["clean"])
|
||||
defp sexual_ratings, do: MapSet.new(["suggestive", "nude only", "explicit"])
|
||||
defp horror_ratings, do: MapSet.new(["semi-grimdark", "grimdark"])
|
||||
defp gross_rating, do: MapSet.new(["grotesque"])
|
||||
end
|
||||
|
|
|
@ -4,6 +4,7 @@ defmodule Philomena.Scrapers do
|
|||
Philomena.Scrapers.Pillowfort,
|
||||
Philomena.Scrapers.Twitter,
|
||||
Philomena.Scrapers.Tumblr,
|
||||
Philomena.Scrapers.Inkbunny,
|
||||
Philomena.Scrapers.Raw
|
||||
]
|
||||
|
||||
|
|
27
lib/philomena/scrapers/inkbunny.ex
Normal file
27
lib/philomena/scrapers/inkbunny.ex
Normal file
|
@ -0,0 +1,27 @@
|
|||
defmodule Philomena.Scrapers.Inkbunny do
|
||||
@url_regex ~r|\Ahttps?://inkbunny.net/s/([\d]+)/?|
|
||||
|
||||
@spec can_handle?(URI.t(), String.t()) :: true | false
|
||||
def can_handle?(_uri, url) do
|
||||
String.match?(url, @url_regex)
|
||||
end
|
||||
|
||||
def scrape(_uri, url) do
|
||||
[submission_id] = Regex.run(@url_regex, url, capture: :last)
|
||||
|
||||
api_url = "https://inkbunny.net/api_submissions.php?show_description=yes&sid=#{inkbunny_sid()}&submission_ids=#{submission_id}"
|
||||
{:ok, %Tesla.Env{status: 200, body: body}} = Philomena.Http.get(api_url)
|
||||
|
||||
json = Jason.decode!(body)
|
||||
submission = json["submissions"]
|
||||
|
||||
images = submission["files"]["file_url_full"]
|
||||
|
||||
%{
|
||||
source_url: submission["url"],
|
||||
author_name: submission["username"],
|
||||
description: submission["description"],
|
||||
images: images
|
||||
}
|
||||
end
|
||||
end
|
|
@ -26,7 +26,7 @@
|
|||
= error_tag f, :avatar_mime_type
|
||||
|
||||
.field.field--inline
|
||||
= url_input f, :scraper_url, class: "input input--wide js-scraper", placeholder: "Link a deviantART page, a Tumblr post, or the image directly"
|
||||
= url_input f, :scraper_url, class: "input input--wide js-scraper", placeholder: "Link a deviantART page, a Tumblr post, An InkBunny Post, an X post, or the image directly"
|
||||
button.button.button--separate-left#js-scraper-preview(type="button" title="Fetch the image at the specified URL" data-disable-with="Fetch" disabled)
|
||||
' Fetch
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@
|
|||
= file_input f, :image, class: "input js-scraper"
|
||||
|
||||
.field.field--inline
|
||||
= url_input f, :scraper_url, class: "input input--wide js-scraper", placeholder: "Link a deviantART page, a Tumblr post, or the image directly"
|
||||
= url_input f, :scraper_url, class: "input input--wide js-scraper", placeholder: "Link a deviantART page, a Tumblr post, An InkBunny Post, an X post, or the image directly"
|
||||
button.button.button--separate-left#js-scraper-preview(type="button" title="Fetch the image at the specified URL" data-disable-with="Fetch" disabled)
|
||||
' Fetch
|
||||
|
||||
|
|
|
@ -111,8 +111,8 @@ h1 Search
|
|||
br
|
||||
br
|
||||
em<> Example:
|
||||
| to find images from DeviantArt, you would use
|
||||
code<> source_url:*deviantart.com*
|
||||
| to find images from InkBunny, you would use
|
||||
code<> source_url:*inkbunny.net*
|
||||
| .
|
||||
|
||||
#js-search-tags.hidden
|
||||
|
|
|
@ -328,7 +328,11 @@ defmodule PhilomenaWeb.ImageView do
|
|||
"fav.me"
|
||||
] ->
|
||||
"fab fa-deviantart"
|
||||
|
||||
when u in [
|
||||
"inkbunny.net",
|
||||
"*.ib.metapix.net"
|
||||
] ->
|
||||
"fa-solid fa-carrot"
|
||||
u
|
||||
when u in [
|
||||
"cdn.discordapp.com",
|
||||
|
|
Loading…
Add table
Reference in a new issue