mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-03-31 00:37:45 +02:00
32 lines
908 B
Elixir
32 lines
908 B
Elixir
defmodule Philomena.Scrapers.Furbooru do
|
|
@url_regex ~r|\Ahttps?://furbooru\.org/images/([0-9]+)|
|
|
|
|
@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: :all)
|
|
api_url = "https://furbooru.org/api/v1/json/images/#{submission_id}"
|
|
{:ok, %Tesla.Env{status: 200, body: body}} = Philomena.Http.get(api_url)
|
|
|
|
json = Jason.decode!(body)
|
|
submission = json["image"]
|
|
|
|
tags = submission["tags"]
|
|
|
|
%{
|
|
source_url: url,
|
|
tags: tags,
|
|
sources: submission["source_urls"],
|
|
description: submission["description"],
|
|
images: [
|
|
%{
|
|
url: "#{submission["representations"]["full"]}",
|
|
camo_url: Camo.Image.image_url(submission["representations"]["medium"])
|
|
}
|
|
]
|
|
}
|
|
end
|
|
end
|