Update inkbunny.ex

This commit is contained in:
Chaska 2024-04-20 20:27:00 -05:00 committed by GitHub
parent 0c32bbf778
commit 3c59b51e3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,11 +1,14 @@
defmodule Philomena.Scrapers.Inkbunny do
def match_submission_id("https://inkbunny.net/s/" <> id), do: id
def match_submission_id(_), do: nil
@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_but_last)
iex(1)> Test.match_submission_id("test")
nil
iex(2)> Test.match_submission_id("https://inkbunny.net/s/123456789")
"123456789"
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)
@ -24,4 +27,4 @@ iex(2)> Test.match_submission_id("https://inkbunny.net/s/123456789")
defp inkbunny_sid do
Application.get_env(:philomena, :inkbunny_sid)
end
end
end