philomena/lib/philomena/scrapers.ex
2019-11-29 00:08:08 -05:00

24 lines
No EOL
518 B
Elixir

defmodule Philomena.Scrapers do
@scrapers [
Philomena.Scrapers.Deviantart,
Philomena.Scrapers.Twitter,
#Philomena.Scrapers.Tumblr, # blocked on benoitc/hackney#566
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