From 263b8dc2cf95eff588ea195baf02d0c067635ad0 Mon Sep 17 00:00:00 2001 From: mp Date: Thu, 25 Nov 2021 19:50:43 +0100 Subject: [PATCH 1/2] add: audio duration --- app/uploaders/binda/audio/audio_uploader.rb | 1 + binda.gemspec | 1 + 2 files changed, 2 insertions(+) diff --git a/app/uploaders/binda/audio/audio_uploader.rb b/app/uploaders/binda/audio/audio_uploader.rb index b3a2a231..1e577dce 100644 --- a/app/uploaders/binda/audio/audio_uploader.rb +++ b/app/uploaders/binda/audio/audio_uploader.rb @@ -20,6 +20,7 @@ def register_details if file && model model.content_type = file.content_type if file.content_type model.file_size = file.size + model.duration = file.audio_properties.length end end diff --git a/binda.gemspec b/binda.gemspec index 0cb91238..60b82828 100644 --- a/binda.gemspec +++ b/binda.gemspec @@ -37,6 +37,7 @@ Gem::Specification.new do |s| s.add_dependency "kaminari", "~> 1.0" s.add_dependency "friendly_id", ">= 5.1", "< 5.4" s.add_dependency "bourbon", "4.3.4" + s.add_dependency "taglib-ruby" ">=1.1.0" # DEVELOPMENT GEMS From b18d78d149a9eb8499ef4257825af1d08815bf4b Mon Sep 17 00:00:00 2001 From: mp Date: Thu, 25 Nov 2021 19:58:54 +0100 Subject: [PATCH 2/2] add: audio duration --- app/uploaders/binda/audio/audio_uploader.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/uploaders/binda/audio/audio_uploader.rb b/app/uploaders/binda/audio/audio_uploader.rb index 1e577dce..ce73ceb8 100644 --- a/app/uploaders/binda/audio/audio_uploader.rb +++ b/app/uploaders/binda/audio/audio_uploader.rb @@ -20,7 +20,9 @@ def register_details if file && model model.content_type = file.content_type if file.content_type model.file_size = file.size - model.duration = file.audio_properties.length + TagLib::FileRef.open(file.file.path) do |file| + model.duration = file.audio_properties.length + end end end