audio_monster 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/audio_monster/configuration.rb +2 -1
- data/lib/audio_monster/monster.rb +52 -16
- data/lib/audio_monster/version.rb +1 -1
- data/test/monster_test.rb +51 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8ff1806c90f459f01c8c8c804be6a9924f37e91
|
4
|
+
data.tar.gz: 93fab5211b9c7c2663353071ac67916d0f5fc700
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4485524174726a344b16386d0fdfb3aca441948bd8cb5de59b3449395206329206a0b2e72b509d01b56e166cf40944fb73fdf283bf242e7f75c9208fbf1ac5e
|
7
|
+
data.tar.gz: 4c5441ac587e4bd2d76e074cf5cfc1b7ef2514e9ec3323bd986930c033d535f37acc3c0c1e30901e97903b226cc920689ce8f94274766bfe82f39952ada3a891
|
@@ -35,7 +35,7 @@ module AudioMonster
|
|
35
35
|
|
36
36
|
AES46_2002_TIME_FORMAT = '%H:%M:%S'
|
37
37
|
|
38
|
-
BINARIES_KEYS = [:file, :ffmpeg, :flac, :lame, :mpck, :mp3val, :sox, :soxi, :madplay, :twolame].freeze
|
38
|
+
BINARIES_KEYS = [:file, :ffmpeg, :ffprobe, :flac, :lame, :mpck, :mp3val, :sox, :soxi, :madplay, :twolame].freeze
|
39
39
|
|
40
40
|
VALID_OPTIONS_KEYS = ([
|
41
41
|
:logger,
|
@@ -114,6 +114,7 @@ module AudioMonster
|
|
114
114
|
self.tmp_dir = '/tmp/audio_monster'
|
115
115
|
self.file = 'file'
|
116
116
|
self.ffmpeg = 'ffmpeg'
|
117
|
+
self.ffprobe = 'ffprobe'
|
117
118
|
self.flac = 'flac'
|
118
119
|
self.lame = 'lame'
|
119
120
|
self.mpck = 'mpck'
|
@@ -11,6 +11,7 @@ require 'nu_wav'
|
|
11
11
|
require 'tempfile'
|
12
12
|
require 'mimemagic'
|
13
13
|
require 'digest/sha2'
|
14
|
+
require 'bigdecimal'
|
14
15
|
|
15
16
|
module AudioMonster
|
16
17
|
|
@@ -252,38 +253,74 @@ module AudioMonster
|
|
252
253
|
end
|
253
254
|
|
254
255
|
def info_for_audio(path)
|
256
|
+
info = audio_file_info_ffprobe(path)
|
255
257
|
{
|
256
|
-
:size
|
257
|
-
:
|
258
|
-
:
|
259
|
-
:
|
260
|
-
:
|
261
|
-
:
|
258
|
+
size: info['format']['size'].to_i,
|
259
|
+
content_type: (MimeMagic.by_path(path) || MimeMagic.by_magic(path)).to_s,
|
260
|
+
format: audio_file_format(path, info),
|
261
|
+
channel_mode: audio_file_channels(path, info) <= 1 ? 'Mono' : 'Stereo',
|
262
|
+
bit_rate: audio_file_bit_rate(path, info),
|
263
|
+
length: audio_file_duration(path, info),
|
264
|
+
sample_rate: audio_file_sample_rate(path, info)
|
262
265
|
}
|
263
266
|
end
|
264
267
|
|
265
|
-
def
|
266
|
-
|
268
|
+
def audio_file_format(path, info = nil)
|
269
|
+
info ||= audio_file_info_ffprobe(path)
|
270
|
+
f = info['format']['format_name']
|
271
|
+
if f == 'mp3'
|
272
|
+
stream = info['streams'].detect { |s| s['codec_type'] == 'audio' }
|
273
|
+
f = stream['codec_name']
|
274
|
+
end
|
275
|
+
f.downcase
|
276
|
+
end
|
277
|
+
|
278
|
+
def audio_file_duration(path, info = nil)
|
279
|
+
# audio_file_info_soxi(path, 'D').to_f
|
280
|
+
info ||= audio_file_info_ffprobe(path)
|
281
|
+
info['format']['duration'].to_f
|
267
282
|
end
|
268
283
|
|
269
|
-
def audio_file_channels(path)
|
270
|
-
|
284
|
+
def audio_file_channels(path, info = nil)
|
285
|
+
# audio_file_info_soxi(path, 'c').to_i
|
286
|
+
info ||= audio_file_info_ffprobe(path)
|
287
|
+
stream = info['streams'].detect { |s| s['codec_type'] == 'audio' }
|
288
|
+
stream['channels'].to_i
|
271
289
|
end
|
272
290
|
|
273
|
-
def audio_file_sample_rate(path)
|
274
|
-
|
291
|
+
def audio_file_sample_rate(path, info = nil)
|
292
|
+
# audio_file_info_soxi(path, 'r').to_i
|
293
|
+
info ||= audio_file_info_ffprobe(path)
|
294
|
+
stream = info['streams'].detect { |s| s['codec_type'] == 'audio' }
|
295
|
+
stream['sample_rate'].to_i
|
275
296
|
end
|
276
297
|
|
277
|
-
def audio_file_bit_rate(path)
|
278
|
-
|
298
|
+
def audio_file_bit_rate(path, info = nil)
|
299
|
+
# audio_file_info_soxi(path, 'B').to_i
|
300
|
+
info ||= audio_file_info_ffprobe(path)
|
301
|
+
stream = info['streams'].detect { |s| s['codec_type'] == 'audio' }
|
302
|
+
bit_rate = stream['bit_rate'] || info['format']['bit_rate']
|
303
|
+
(BigDecimal.new(bit_rate) / 1000).round
|
279
304
|
end
|
280
305
|
|
281
|
-
def
|
306
|
+
def audio_file_info_soxi(path, flag)
|
282
307
|
check_local_file(path)
|
283
308
|
out, err = run_command("#{bin(:soxi)} -V0 -#{flag} '#{path}'", nice: 'n', echo_return: false)
|
284
309
|
out.chomp
|
285
310
|
end
|
286
311
|
|
312
|
+
def audio_file_info_ffprobe(path)
|
313
|
+
check_local_file(path)
|
314
|
+
cmd = bin(:ffprobe) +
|
315
|
+
" -v quiet -print_format json -show_format -show_streams" +
|
316
|
+
" '#{path}'"
|
317
|
+
out, err = run_command(cmd, nice: 'n', echo_return: false)
|
318
|
+
json = out.chomp
|
319
|
+
JSON.parse(json)
|
320
|
+
end
|
321
|
+
|
322
|
+
alias audio_file_info audio_file_info_ffprobe
|
323
|
+
|
287
324
|
# valid options
|
288
325
|
# :sample_rate
|
289
326
|
# :bit_rate
|
@@ -984,6 +1021,5 @@ module AudioMonster
|
|
984
1021
|
def get_lame_channel_mode(channel_mode)
|
985
1022
|
["Stereo", "JStereo"].include?(channel_mode) ? "j" : "m"
|
986
1023
|
end
|
987
|
-
|
988
1024
|
end
|
989
1025
|
end
|
data/test/monster_test.rb
CHANGED
@@ -84,7 +84,6 @@ describe AudioMonster::Monster do
|
|
84
84
|
info[:content_type].must_equal "audio/ogg"
|
85
85
|
end
|
86
86
|
|
87
|
-
|
88
87
|
it 'should create a wav wrapped mp2' do
|
89
88
|
start_at = '2010-06-19T00:00:00-04:00'
|
90
89
|
end_at = DateTime.parse(start_at) + 6.days
|
@@ -129,4 +128,55 @@ describe AudioMonster::Monster do
|
|
129
128
|
File.basename(file.path)[0, 64].must_equal Digest::SHA256.hexdigest(base_file_name)
|
130
129
|
File.extname(file.path).must_equal '.exten'
|
131
130
|
end
|
131
|
+
|
132
|
+
describe 'test info' do
|
133
|
+
let(:audio_files) do
|
134
|
+
{
|
135
|
+
'test_short.mp2' => ['mp2', 5, 2, 48000, 256],
|
136
|
+
'test_long.mp3' => ['mp3', 48, 1, 44100, 128],
|
137
|
+
'test.ogg' => ['ogg', 12, 2, 44100, 128],
|
138
|
+
'test.flac' => ['flac', 15, 2, 44100, 246],
|
139
|
+
'test_short.wav' => ['wav', 5, 2, 48000, 1536]
|
140
|
+
}
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'can get the ffprobe info on a file' do
|
144
|
+
audio_files.keys.each do |file|
|
145
|
+
info = monster.audio_file_info_ffprobe(in_file(file))
|
146
|
+
info.wont_be_nil
|
147
|
+
info['streams'].wont_be_nil
|
148
|
+
info['format'].wont_be_nil
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'can get the format of a file' do
|
153
|
+
audio_files.keys.each do |file|
|
154
|
+
monster.audio_file_format(in_file(file)).must_equal audio_files[file][0]
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'can get the duration of a file' do
|
159
|
+
audio_files.keys.each do |file|
|
160
|
+
monster.audio_file_duration(in_file(file)).to_i.must_equal audio_files[file][1]
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'can get the number of channels for a file' do
|
165
|
+
audio_files.keys.each do |file|
|
166
|
+
monster.audio_file_channels(in_file(file)).must_equal audio_files[file][2]
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'can get the sample rate of a file' do
|
171
|
+
audio_files.keys.each do |file|
|
172
|
+
monster.audio_file_sample_rate(in_file(file)).must_equal audio_files[file][3]
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'can get the bit rate of a file' do
|
177
|
+
audio_files.keys.each do |file|
|
178
|
+
monster.audio_file_bit_rate(in_file(file)).must_equal audio_files[file][4]
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
132
182
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: audio_monster
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kuklewicz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nu_wav
|