mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 04:27:59 +01:00
24 lines
485 B
Elixir
24 lines
485 B
Elixir
defmodule Philomena.Scrapers do
|
|
@scrapers [
|
|
Philomena.Scrapers.Deviantart,
|
|
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
|