mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 12:37:58 +01:00
40 lines
945 B
Elixir
40 lines
945 B
Elixir
defmodule PhilomenaProxy.Scrapers.Raw do
|
|
@moduledoc false
|
|
|
|
alias PhilomenaProxy.Scrapers.Scraper
|
|
alias PhilomenaProxy.Scrapers
|
|
|
|
@behaviour Scraper
|
|
|
|
@mime_types ["image/gif", "image/jpeg", "image/png", "image/svg", "image/svg+xml", "video/webm"]
|
|
|
|
@spec can_handle?(URI.t(), String.t()) :: boolean()
|
|
def can_handle?(_uri, url) do
|
|
PhilomenaProxy.Http.head(url)
|
|
|> case do
|
|
{:ok, %Tesla.Env{status: 200, headers: headers}} ->
|
|
headers
|
|
|> Enum.any?(fn {k, v} ->
|
|
String.downcase(k) == "content-type" and String.downcase(v) in @mime_types
|
|
end)
|
|
|
|
_ ->
|
|
false
|
|
end
|
|
end
|
|
|
|
@spec scrape(URI.t(), Scrapers.url()) :: Scrapers.scrape_result()
|
|
def scrape(_uri, url) do
|
|
%{
|
|
source_url: url,
|
|
author_name: "",
|
|
description: "",
|
|
images: [
|
|
%{
|
|
url: url,
|
|
camo_url: PhilomenaProxy.Camo.image_url(url)
|
|
}
|
|
]
|
|
}
|
|
end
|
|
end
|