audio_monster 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +9 -0
- data/audio_monster.gemspec +29 -0
- data/lib/audio_monster/configuration.rb +143 -0
- data/lib/audio_monster/monster.rb +951 -0
- data/lib/audio_monster/version.rb +5 -0
- data/lib/audio_monster.rb +18 -0
- data/test/audio_monster_test.rb +20 -0
- data/test/files/test.flac +0 -0
- data/test/files/test.ogg +0 -0
- data/test/files/test_long.mp2 +0 -0
- data/test/files/test_long.mp3 +0 -0
- data/test/files/test_long.wav +0 -0
- data/test/files/test_long_2.mp2 +0 -0
- data/test/files/test_short.mp2 +0 -0
- data/test/files/test_short.wav +0 -0
- data/test/files/test_stereo.wav +0 -0
- data/test/minitest_helper.rb +24 -0
- data/test/monster_test.rb +111 -0
- metadata +177 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 194f8e7d1e38356196818c0c3ad21ff399258744
|
4
|
+
data.tar.gz: db5a0f3573ee469fb430a5dce3c8b5203e447f53
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 71f155c5aa3b23c9487041a3cc799a697a3438ae1fa7e916e1ebb7616f0e9a8f468c407b77ac35a951b71f66f7c63abc805f6865c491b3a0b1e450d409bb37c9
|
7
|
+
data.tar.gz: ac03aa9e19d1810a0d4b4b7e4e3adafe7a41ca31dbd5cdfb96d300ff2dccedd76dfcde3a3a627057dd7a2f9911e5b758f91b3921ba8fd705b83187575531edec
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Andrew Kuklewicz
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# AudioMonster
|
2
|
+
|
3
|
+
AudioMonster manipulates and transcodes audio.
|
4
|
+
It wraps a number of different command line binaries such as sox, lame, flac, twolame, and ffmpeg.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'audio_monster'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install audio_monster
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
AudioMonster can be configured to use a specific tempfile directory.
|
25
|
+
It can also be configured to use a binary directory, or you can configure each binary.
|
26
|
+
It will default to logging to STDOUT, or a logger can be configured.
|
27
|
+
|
28
|
+
For convenience, all methods can be called from the AudioMonster module.
|
29
|
+
|
30
|
+
The `monster_test.rb` contains examples of method calls.
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it ( https://github.com/[my-github-username]/audio_monster/fork )
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'audio_monster/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'audio_monster'
|
8
|
+
spec.version = AudioMonster::VERSION
|
9
|
+
spec.authors = ['Andrew Kuklewicz']
|
10
|
+
spec.email = ['andrew@beginsinwonder.com']
|
11
|
+
spec.summary = %q{audio_monster manipulates and transcodes audio}
|
12
|
+
spec.description = %q{audio_monster manipulates and transcodes audio}
|
13
|
+
spec.homepage = 'https://github.com/PRX/audio-monster'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_runtime_dependency 'nu_wav'
|
22
|
+
spec.add_runtime_dependency 'mp3info'
|
23
|
+
spec.add_runtime_dependency 'mimemagic'
|
24
|
+
spec.add_runtime_dependency 'activesupport'
|
25
|
+
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'minitest'
|
29
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'mkmf'
|
4
|
+
require 'logger'
|
5
|
+
|
6
|
+
module AudioMonster
|
7
|
+
|
8
|
+
module Configuration
|
9
|
+
|
10
|
+
# constants
|
11
|
+
FILE_SUCCESS = /\S+: (MP2|MPEG ADTS, layer II, v1), \S+ kBits, \S+ kHz, (JStereo|Stereo|Mono|2x Monaural|Dual-Ch|Monaural|JntStereo)/
|
12
|
+
MP3VAL_WARNING_RE = /WARNING/
|
13
|
+
MP3VAL_ERROR_RE = /ERROR/
|
14
|
+
MP3VAL_IGNORE_RE = /(^Done!|Non-layer-III frame encountered. See related INFO message for details.|No supported tags in the file|It seems that file is truncated or there is garbage at the end of the file|MPEG stream error, resynchronized successfully)/
|
15
|
+
MPCK_ERROR_RE = /(mpck:|errors)/
|
16
|
+
MPCK_IGNORE_RE = /errors(\s*)(CRC error|none)/
|
17
|
+
LAME_SUCCESS_RE = /0/
|
18
|
+
LAME_ERROR_RE = /fatal error/
|
19
|
+
SOX_ERROR_RE = /error:/
|
20
|
+
TWOLAME_SUCCESS_RE = /0/
|
21
|
+
|
22
|
+
# Allowable values for mp2 (MPEG1 layer II)
|
23
|
+
MP2_BITRATES = [32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384]
|
24
|
+
MP2_SAMPLE_RATES = ['32000', '44100', '48000']
|
25
|
+
TWOLAME_MODES = ['s', 'j', 'd', 'm', 'a'] # (s)tereo, (j)oint, (d)ual, (m)ono or (a)uto
|
26
|
+
|
27
|
+
# Allowable values for mp3 (MPEG1 layer III)
|
28
|
+
MP3_SAMPLE_RATES = ['32000', '44100', '48000']
|
29
|
+
MP3_BITRATES = [32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320]
|
30
|
+
LAME_MODES = ['j', 's', 'f', 'd', 'm'] # (j)oint, (s)imple stereo, (f)orce, (d)dual-mono, (m)ono
|
31
|
+
|
32
|
+
# by default, using the PRSS date format, but this is not the actual cart chunk (AES46-2002) standard
|
33
|
+
AES46_2002_DATE_FORMAT = '%Y-%m-%d'
|
34
|
+
PRSS_DATE_FORMAT = '%Y/%m/%d'
|
35
|
+
|
36
|
+
AES46_2002_TIME_FORMAT = '%H:%M:%S'
|
37
|
+
|
38
|
+
BINARIES_KEYS = [:file, :ffmpeg, :flac, :lame, :mpck, :mp3val, :sox, :soxi, :madplay, :twolame].freeze
|
39
|
+
|
40
|
+
VALID_OPTIONS_KEYS = ([
|
41
|
+
:logger,
|
42
|
+
:bin_dir,
|
43
|
+
:tmp_dir,
|
44
|
+
:debug
|
45
|
+
] + BINARIES_KEYS).freeze
|
46
|
+
|
47
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
48
|
+
|
49
|
+
def self.included(base)
|
50
|
+
|
51
|
+
def current_options
|
52
|
+
@current_options ||= {}
|
53
|
+
end
|
54
|
+
|
55
|
+
def current_options=(opts)
|
56
|
+
@current_options = opts
|
57
|
+
end
|
58
|
+
|
59
|
+
VALID_OPTIONS_KEYS.each do |key|
|
60
|
+
define_method "#{key}=" do |arg|
|
61
|
+
self.instance_variable_set("@#{key}", arg)
|
62
|
+
self.current_options.merge!({:"#{key}" => arg})
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
base.extend(ClassMethods)
|
67
|
+
end
|
68
|
+
|
69
|
+
module ClassMethods
|
70
|
+
|
71
|
+
def keys
|
72
|
+
VALID_OPTIONS_KEYS
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
def options
|
78
|
+
options = {}
|
79
|
+
VALID_OPTIONS_KEYS.each { |k| options[k] = send(k) }
|
80
|
+
options
|
81
|
+
end
|
82
|
+
|
83
|
+
def apply_configuration(opts={})
|
84
|
+
options = AudioMonster.options.merge(opts)
|
85
|
+
self.current_options = options
|
86
|
+
VALID_OPTIONS_KEYS.each do |key|
|
87
|
+
send("#{key}=", options[key])
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# Convenience method to allow for global setting of configuration options
|
92
|
+
def configure
|
93
|
+
yield self
|
94
|
+
end
|
95
|
+
|
96
|
+
def check_binaries
|
97
|
+
BINARIES_KEYS.each { |bin| find_executable(bin.to_s) }
|
98
|
+
end
|
99
|
+
|
100
|
+
# Reset configuration options to their defaults
|
101
|
+
def reset!
|
102
|
+
self.debug = ENV['DEBUG']
|
103
|
+
self.logger = Logger.new(STDOUT)
|
104
|
+
self.bin_dir = nil
|
105
|
+
self.tmp_dir = '/tmp/audio_monster'
|
106
|
+
self.file = 'file'
|
107
|
+
self.ffmpeg = 'ffmpeg'
|
108
|
+
self.flac = 'flac'
|
109
|
+
self.lame = 'lame'
|
110
|
+
self.mpck = 'mpck'
|
111
|
+
self.mp3val = 'mp3val'
|
112
|
+
self.sox = 'sox'
|
113
|
+
self.soxi = 'soxi'
|
114
|
+
self.madplay = 'madplay'
|
115
|
+
self.twolame = 'twolame'
|
116
|
+
self
|
117
|
+
end
|
118
|
+
|
119
|
+
def bin(name)
|
120
|
+
"#{bin_dir}#{name}"
|
121
|
+
end
|
122
|
+
|
123
|
+
# # detect the sox version to deal wth changes in comand line options after 14.1.0
|
124
|
+
# # http://sox.sourceforge.net/Docs/FAQ
|
125
|
+
# def configure_sox
|
126
|
+
# sox_version = `#{bin(:sox)} --version`
|
127
|
+
# version = /^.*SoX v(\d*)\.(\d*)\.(\d*)/.match(sox_version) || []
|
128
|
+
|
129
|
+
# if (version.size > 0) && (version[1].to_i < 14) || ((version[1].to_i == 14) && (version[2].to_i < 1))
|
130
|
+
# self.sox_16_bits = '-w'
|
131
|
+
# self.sox_8_bits = '-b'
|
132
|
+
# else
|
133
|
+
# self.sox_16_bits = '-b 16'
|
134
|
+
# self.sox_8_bits = '-b 8'
|
135
|
+
# end
|
136
|
+
# end
|
137
|
+
|
138
|
+
def self.extended(base)
|
139
|
+
base.reset!
|
140
|
+
base.check_binaries
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|