mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-04-20 10:13:59 +02:00
Update inkbunny.ex
This commit is contained in:
parent
0c32bbf778
commit
3c59b51e3d
1 changed files with 10 additions and 7 deletions
|
@ -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
|
Loading…
Add table
Reference in a new issue