diff --git a/lib/philomena/scrapers.ex b/lib/philomena/scrapers.ex index fe8657f2..52fdbe5a 100644 --- a/lib/philomena/scrapers.ex +++ b/lib/philomena/scrapers.ex @@ -8,6 +8,7 @@ defmodule Philomena.Scrapers do Philomena.Scrapers.E621, Philomena.Scrapers.Furaffinity, Philomena.Scrapers.Pixiv, + Philomena.SCrapers.Derpibooru, Philomena.Scrapers.Raw ] diff --git a/lib/philomena/scrapers/derpibooru.ex b/lib/philomena/scrapers/derpibooru.ex new file mode 100644 index 00000000..9e301aa1 --- /dev/null +++ b/lib/philomena/scrapers/derpibooru.ex @@ -0,0 +1,30 @@ +defmodule Philomena.Scrapers.Inkbunny do + @url_regex ~r|\Ahttps?://derpibooru\.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://derpibooru.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 \ No newline at end of file diff --git a/lib/philomena_web/templates/error/show.html.slime b/lib/philomena_web/templates/error/show.html.slime index c0256043..601eca9e 100644 --- a/lib/philomena_web/templates/error/show.html.slime +++ b/lib/philomena_web/templates/error/show.html.slime @@ -7,7 +7,7 @@ html lang="en" title => @status - | - Philomena + | - CubFur.gay link rel="stylesheet" href=stylesheet_path(@conn, nil) link rel="stylesheet" href=dark_stylesheet_path(@conn) media="(prefers-color-scheme: dark)" link rel="icon" href="/favicon.ico" type="image/x-icon" @@ -17,7 +17,7 @@ html lang="en" .minimal__message h1.minimal__message__header i.fa.fw.favicon-home> - ' Philomena + ' CubFur.gay h3 = @short_msg p = @long_msg