Adding e6ai.net

This commit is contained in:
Chaska 2024-05-04 02:59:21 -05:00
parent d02a0e808b
commit c4f4d1762c
4 changed files with 64 additions and 0 deletions

View file

@ -27,6 +27,8 @@ config :philomena,
inkbunny_sid: System.fetch_env!("INKBUNNY_SID"),
e621_user: System.fetch_env!("E621_USER"),
e621_apikey: System.fetch_env!("E621_APIKEY"),
e6ai_user: System.fetch_env!("E6AI_USER"),
e6ai_apikey: System.fetch_env!("E6AI_APIKEY"),
otp_secret_key: System.fetch_env!("OTP_SECRET_KEY"),
image_url_root: System.fetch_env!("IMAGE_URL_ROOT"),
badge_url_root: System.fetch_env!("BADGE_URL_ROOT"),

View file

@ -19,6 +19,8 @@ services:
- INKBUNNY_SID=4X88ktV7jxywp65Ng40ez1qTJd
- E621_USER=hexerade
- E621_APIKEY=merpmarp
- E6AI_USER=hexerade
- E6AI_APIKEY=merpmarp
- OTP_SECRET_KEY=Wn7O/8DD+qxL0X4X7bvT90wOkVGcA90bIHww4twR03Ci//zq7PnMw8ypqyyT/b/C
- ADVERT_FILE_ROOT=adverts
- AVATAR_FILE_ROOT=avatars

View file

@ -10,6 +10,7 @@ defmodule Philomena.Scrapers do
Philomena.Scrapers.Pixiv,
Philomena.Scrapers.Derpibooru,
Philomena.Scrapers.Furbooru,
Philomena.Scrapers.E6ai,
Philomena.Scrapers.Raw
]

View file

@ -0,0 +1,59 @@
defmodule Philomena.Scrapers.E6ai do
@url_regex ~r/\A(https\:\/\/e621\.net\/posts\/([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
[_, url, submission_id] = Regex.run(@url_regex, url, capture: :all)
api_url =
"https://e6ai.net/posts/#{submission_id}.json?login=#{e6ai_user()}&api_key=#{e6ai_apikey()}"
{:ok, %Tesla.Env{status: 200, body: body}} = Philomena.Http.get(api_url)
json = Jason.decode!(body)
submission = json["post"]
tags = submission["tags"]["general"] ++ submission["tags"]["species"]
tags =
for x <- tags do
String.replace(x, "_", " ")
end
rating =
case submission["rating"] do
"s" -> "safe"
"q" -> "suggestive"
"e" -> "explicit"
_ -> nil
end
tags = if is_nil(rating), do: tags, else: [rating | tags]
%{
source_url: url,
authors: submission["tags"]["director"],
tags: tags,
sources: submission["sources"],
description: submission["description"],
images: [
%{
url: "#{submission["file"]["url"]}",
camo_url: Camo.Image.image_url(submission["file"]["url"])
}
]
}
end
defp e621_user do
Application.get_env(:philomena, :e6ai_user)
end
defp e621_apikey do
Application.get_env(:philomena, :e6ai_apikey)
end
end