Trying to add webp

This commit is contained in:
Chaska 2024-04-26 01:13:29 -05:00
parent 4dfd186c34
commit 954acefee5
3 changed files with 32 additions and 1 deletions

View file

@ -9,6 +9,7 @@ defmodule Philomena.Analyzers do
alias Philomena.Analyzers.Jpeg
alias Philomena.Analyzers.Png
alias Philomena.Analyzers.Svg
alias Philomena.Analyzers.Webp
alias Philomena.Analyzers.Webm
@doc """
@ -33,6 +34,7 @@ defmodule Philomena.Analyzers do
def analyzer("image/jpeg"), do: {:ok, Jpeg}
def analyzer("image/png"), do: {:ok, Png}
def analyzer("image/svg+xml"), do: {:ok, Svg}
def analyzer("image/webp"), do: {:ok, Webp}
def analyzer("video/webm"), do: {:ok, Webm}
def analyzer(_content_type), do: :error

View file

@ -0,0 +1,29 @@
defmodule Philomena.Analyzers.Jpeg do
def analyze(file) do
stats = stats(file)
%{
extension: "jpg",
mime_type: "image/webp",
animated?: false,
duration: stats.duration,
dimensions: stats.dimensions
}
end
defp stats(file) do
case System.cmd("mediastat", [file]) do
{output, 0} ->
[_size, _frames, width, height, num, den] =
output
|> String.trim()
|> String.split(" ")
|> Enum.map(&String.to_integer/1)
%{dimensions: {width, height}, duration: num / den}
_ ->
%{dimensions: {0, 0}, duration: 0.0}
end
end
end

View file

@ -23,7 +23,7 @@ defmodule Philomena.Scrapers.Pixiv do
end
images = for x <- images do
pre = x["url_small"] || x["url_ss"]
pre = x["url_small"] || x["url_s"]
{:ok, %Tesla.Env{status: 200, body: body, headers: headers}}
= Philomena.Http.get(pre, [{"Referer", "https://pixiv.net/"}])