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; \
git clone https://github.com/derpibooru/cli_intensities; \
git clone https://github.com/derpibooru/mediatools; \
(cd cli_intensities && make install); \
(cd mediatools && make install); \
(cd cli_intensities; make install); \
(cd mediatools; make install); \
mix local.hex --force; \
mix local.rebar --force

View file

@ -1,71 +1,29 @@
defmodule Philomena.Analyzers.Gif do
def analyze(file) do
animated? = animated?(file)
duration = duration(animated?, file)
stats = stats(file)
%{
extension: "gif",
mime_type: "image/gif",
animated?: animated?,
duration: duration,
dimensions: dimensions(file)
animated?: stats.animated?,
duration: stats.duration,
dimensions: stats.dimensions
}
end
defp animated?(file) do
System.cmd("identify", [file])
|> case do
defp stats(file) do
case System.cmd("mediastat", [file]) do
{output, 0} ->
len =
[_size, frames, width, height, num, den] =
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.split(" ")
|> 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

View file

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

View file

@ -1,54 +1,29 @@
defmodule Philomena.Analyzers.Png do
def analyze(file) do
animated? = animated?(file)
duration = duration(animated?, file)
stats = stats(file)
%{
extension: "png",
mime_type: "image/png",
animated?: animated?,
duration: duration,
dimensions: dimensions(file)
animated?: stats.animated?,
duration: stats.duration,
dimensions: stats.dimensions
}
end
defp animated?(file) do
System.cmd("ffprobe", [
"-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
defp stats(file) do
case System.cmd("mediastat", [file]) do
{output, 0} ->
[width, height] =
[_size, frames, width, height, num, den] =
output
|> String.trim()
|> String.split(" ")
|> 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

View file

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