mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-03-28 06:17:46 +01:00
Adding Furbooru
This commit is contained in:
parent
65d8a8c9fd
commit
9af9334213
2 changed files with 31 additions and 0 deletions
|
@ -9,6 +9,7 @@ defmodule Philomena.Scrapers do
|
|||
Philomena.Scrapers.Furaffinity,
|
||||
Philomena.Scrapers.Pixiv,
|
||||
Philomena.Scrapers.Derpibooru,
|
||||
Philomena.Scrapers.Furbooru,
|
||||
Philomena.Scrapers.Raw
|
||||
]
|
||||
|
||||
|
|
30
lib/philomena/scrapers/furbooru.ex
Normal file
30
lib/philomena/scrapers/furbooru.ex
Normal file
|
@ -0,0 +1,30 @@
|
|||
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_url"],
|
||||
description: submission["description"],
|
||||
images: [%{
|
||||
url: "#{submission["representations"]["full"]}",
|
||||
camo_url: Camo.Image.image_url(submission["representations"]["medium"])
|
||||
}]
|
||||
}
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue