mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-03-31 00:37:45 +02:00
41 lines
1.1 KiB
Elixir
41 lines
1.1 KiB
Elixir
defmodule Philomena.Scrapers.Inkbunny do
|
|
@url_regex ~r|\Ahttps?://inkbunny\.net/s/([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://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"]
|
|
|
|
description = "##\s#{submission["title"]}\n#{submission["description"]}"
|
|
|
|
images =
|
|
for x <- submission["files"] do
|
|
%{
|
|
url: "#{x["file_url_full"]}",
|
|
camo_url: Camo.Image.image_url(x["file_url_screen"])
|
|
}
|
|
end
|
|
|
|
%{
|
|
source_url: url,
|
|
author_name: submission["username"],
|
|
description: description,
|
|
images: images
|
|
}
|
|
end
|
|
|
|
defp inkbunny_sid do
|
|
Application.get_env(:philomena, :inkbunny_sid)
|
|
end
|
|
end
|