From 3f92d6cce34f00cff5c273b14a5c5191d631a131 Mon Sep 17 00:00:00 2001 From: neodarz Date: Mon, 27 Feb 2017 11:35:54 +0100 Subject: Add the detection of the file duration --- mix.exs | 5 +++-- web/controllers/audio_file_api_controller.ex | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mix.exs b/mix.exs index 4e83937..7723483 100644 --- a/mix.exs +++ b/mix.exs @@ -19,7 +19,7 @@ defmodule TheTranscriberBackend.Mixfile do def application do [mod: {TheTranscriberBackend, []}, applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext, - :phoenix_ecto, :postgrex]] + :phoenix_ecto, :postgrex, :ffmpex]] end # Specifies which paths to compile per environment. @@ -38,7 +38,8 @@ defmodule TheTranscriberBackend.Mixfile do {:phoenix_live_reload, "~> 1.0", only: :dev}, {:gettext, "~> 0.11"}, {:cowboy, "~> 1.0"}, - {:ja_serializer, "~> 0.11.2"}] + {:ja_serializer, "~> 0.11.2"}, + {:ffmpex, "~> 0.4.0"}] end # Aliases are shortcuts or tasks specific to the current project. diff --git a/web/controllers/audio_file_api_controller.ex b/web/controllers/audio_file_api_controller.ex index afc23ac..5bafbf1 100644 --- a/web/controllers/audio_file_api_controller.ex +++ b/web/controllers/audio_file_api_controller.ex @@ -15,11 +15,12 @@ defmodule TheTranscriberBackend.AudioFileAPIController do changeset = AudioFile.changeset(%AudioFile{}, %{audio_path: upload.filename, audio_name: audio_name, - audio_duration: audio_duration}) + audio_duration: "#{FFprobe.duration(upload.path)}"}) case Repo.insert(changeset) do {:ok, audio_file_api} -> File.cp(upload.path, "#{path}#{audio_file_api.id}_#{upload.filename}") + conn |> put_status(:created) |> put_resp_header("location", audio_file_api_path(conn, :show, audio_file_api)) -- cgit v1.2.1