distraction.party/lib/pleroma/web/rich_media/parser.ex
2019-01-01 23:26:40 +03:00

14 lines
393 B
Elixir

defmodule Pleroma.Web.RichMedia.Parser do
@parsers [Pleroma.Web.RichMedia.Parsers.OGP]
def parse(url) do
{:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url)
Enum.reduce_while(@parsers, %Pleroma.Web.RichMedia.Data{}, fn parser, acc ->
case parser.parse(html, acc) do
{:ok, data} -> {:halt, data}
{:error, _msg} -> {:cont, acc}
end
end)
end
end