update mediatools to b36a7c3

This commit is contained in:
byte[] 2020-05-16 13:48:54 -04:00
parent 7b02ccde64
commit c59fdc7252
5 changed files with 41 additions and 107 deletions

View file

@ -11,8 +11,8 @@ RUN apt-get update; \
cd /tmp; \ cd /tmp; \
git clone https://github.com/derpibooru/cli_intensities; \ git clone https://github.com/derpibooru/cli_intensities; \
git clone https://github.com/derpibooru/mediatools; \ git clone https://github.com/derpibooru/mediatools; \
(cd cli_intensities && make install); \ (cd cli_intensities; make install); \
(cd mediatools && make install); \ (cd mediatools; make install); \
mix local.hex --force; \ mix local.hex --force; \
mix local.rebar --force mix local.rebar --force

View file

@ -1,71 +1,29 @@
defmodule Philomena.Analyzers.Gif do defmodule Philomena.Analyzers.Gif do
def analyze(file) do def analyze(file) do
animated? = animated?(file) stats = stats(file)
duration = duration(animated?, file)
%{ %{
extension: "gif", extension: "gif",
mime_type: "image/gif", mime_type: "image/gif",
animated?: animated?, animated?: stats.animated?,
duration: duration, duration: stats.duration,
dimensions: dimensions(file) dimensions: stats.dimensions
} }
end end
defp animated?(file) do defp stats(file) do
System.cmd("identify", [file]) case System.cmd("mediastat", [file]) do
|> case do
{output, 0} -> {output, 0} ->
len = [_size, frames, width, height, num, den] =
output output
|> String.split("\n", parts: 2, trim: true)
|> length()
len > 1
_error ->
nil
end
end
defp duration(false, _file), do: 0.0
defp duration(true, file) do
with {output, 0} <-
System.cmd("ffprobe", [
"-i",
file,
"-show_entries",
"format=duration",
"-v",
"quiet",
"-of",
"csv=p=0"
]),
{duration, _} <- Float.parse(output) do
duration
else
_ ->
0.0
end
end
defp dimensions(file) do
System.cmd("identify", ["-format", "%W %H\n", file])
|> case do
{output, 0} ->
[width, height] =
output
|> String.split("\n", trim: true)
|> hd()
|> String.trim() |> String.trim()
|> String.split(" ") |> String.split(" ")
|> Enum.map(&String.to_integer/1) |> Enum.map(&String.to_integer/1)
{width, height} %{animated?: frames > 1, dimensions: {width, height}, duration: num / den}
_error -> _ ->
{0, 0} %{animated?: false, dimensions: {0, 0}, duration: 0.0}
end end
end end
end end

View file

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

View file

@ -1,54 +1,29 @@
defmodule Philomena.Analyzers.Png do defmodule Philomena.Analyzers.Png do
def analyze(file) do def analyze(file) do
animated? = animated?(file) stats = stats(file)
duration = duration(animated?, file)
%{ %{
extension: "png", extension: "png",
mime_type: "image/png", mime_type: "image/png",
animated?: animated?, animated?: stats.animated?,
duration: duration, duration: stats.duration,
dimensions: dimensions(file) dimensions: stats.dimensions
} }
end end
defp animated?(file) do defp stats(file) do
System.cmd("ffprobe", [ case System.cmd("mediastat", [file]) do
"-i",
file,
"-v",
"quiet",
"-show_entries",
"stream=codec_name",
"-of",
"csv=p=0"
])
|> case do
{"apng\n", 0} ->
true
_other ->
false
end
end
# No tooling available for this yet.
defp duration(_animated?, _file), do: 0.0
defp dimensions(file) do
System.cmd("identify", ["-format", "%W %H\n", file])
|> case do
{output, 0} -> {output, 0} ->
[width, height] = [_size, frames, width, height, num, den] =
output output
|> String.trim() |> String.trim()
|> String.split(" ") |> String.split(" ")
|> Enum.map(&String.to_integer/1) |> Enum.map(&String.to_integer/1)
{width, height} %{animated?: frames > 1, dimensions: {width, height}, duration: num / den}
_error -> _ ->
{0, 0} %{animated?: false, dimensions: {0, 0}, duration: 0.0}
end end
end end
end end

View file

@ -1,29 +1,29 @@
defmodule Philomena.Analyzers.Svg do defmodule Philomena.Analyzers.Svg do
def analyze(file) do def analyze(file) do
stats = stats(file)
%{ %{
extension: "svg", extension: "svg",
mime_type: "image/svg+xml", mime_type: "image/svg+xml",
animated?: false, animated?: false,
duration: 0.0, duration: 0.0,
dimensions: dimensions(file) dimensions: stats.dimensions
} }
end end
# Force use of MSVG to prevent invoking inkscape defp stats(file) do
defp dimensions(file) do case System.cmd("mediastat", [file]) do
System.cmd("identify", ["-format", "%W %H\n", "msvg:#{file}"])
|> case do
{output, 0} -> {output, 0} ->
[width, height] = [_size, _frames, width, height, _num, _den] =
output output
|> String.trim() |> String.trim()
|> String.split(" ") |> String.split(" ")
|> Enum.map(&String.to_integer/1) |> Enum.map(&String.to_integer/1)
{width, height} %{dimensions: {width, height}}
_error -> _ ->
{0, 0} %{dimensions: {0, 0}}
end end
end end
end end