Module: AudioFile
- Defined in:
- lib/bbcnet.rb
Class Method Summary collapse
-
.getDuration(file) ⇒ Object
return seconds of audio file duration.
Class Method Details
.getDuration(file) ⇒ Object
return seconds of audio file duration.
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/bbcnet.rb', line 233 def self.getDuration(file) return 0 unless File.exist?(file) case file[/\.\w+$/].downcase when ".mp3" cmd = "| exiftool -S -Duration %s" % file.shellescape when ".wma" cmd = "| exiftool -S -PlayDuration %s" % file.shellescape end msg = open(cmd) do |f| f.read end a = msg.scan(/(?:(\d+):){0,2}(\d+)/)[0] return 0 unless a i = -1 a.reverse.inject(0) do |s, d| i += 1 s + d.to_i * [ 1, 60, 3600 ][i] end end |