mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
25 lines
520 B
Elixir
25 lines
520 B
Elixir
defmodule Philomena.Scrapers do
|
|
@scrapers [
|
|
Philomena.Scrapers.Deviantart,
|
|
Philomena.Scrapers.Pillowfort,
|
|
Philomena.Scrapers.Twitter,
|
|
Philomena.Scrapers.Tumblr,
|
|
Philomena.Scrapers.Raw
|
|
]
|
|
|
|
def scrape!(url) do
|
|
uri = URI.parse(url)
|
|
|
|
@scrapers
|
|
|> Enum.find(& &1.can_handle?(uri, url))
|
|
|> wrap()
|
|
|> Enum.map(& &1.scrape(uri, url))
|
|
|> unwrap()
|
|
end
|
|
|
|
defp wrap(nil), do: []
|
|
defp wrap(res), do: [res]
|
|
|
|
defp unwrap([result]), do: result
|
|
defp unwrap(_result), do: nil
|
|
end
|