Class: DTAS::ReplayGain
- Inherits:
-
Object
- Object
- DTAS::ReplayGain
- Defined in:
- lib/dtas/replaygain.rb
Overview
Copyright © 2013-2014, Eric Wong <[email protected]> and all contributors License: GPLv3 or later (www.gnu.org/licenses/gpl-3.0.txt)
Represents ReplayGain metadata for a DTAS::Source cleanup/validate values to prevent malicious files from making us run arbitrary commands *_peak values are 0..inf (1.0 being full scale, but >1 is possible *_gain values are specified in dB
Constant Summary collapse
- ATTRS =
:nodoc:
%w(reference_loudness track_gain album_gain track_peak album_peak)
- ENV_ATTRS =
{}
Class Method Summary collapse
Instance Method Summary collapse
- #check_float(val) ⇒ Object
- #check_gain(val) ⇒ Object
-
#initialize(comments) ⇒ ReplayGain
constructor
A new instance of ReplayGain.
-
#to_env ⇒ Object
note: this strips the “dB” suffix, but that should be easier for apps to deal with anyways…
Constructor Details
#initialize(comments) ⇒ ReplayGain
Returns a new instance of ReplayGain.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/dtas/replaygain.rb', line 39 def initialize(comments) comments or return # the replaygain standard specifies 89.0 dB, but maybe some apps are # different... @reference_loudness = check_gain(comments["REPLAYGAIN_REFERENCE_LOUDNESS"]) @track_gain = check_gain(comments["REPLAYGAIN_TRACK_GAIN"]) @album_gain = check_gain(comments["REPLAYGAIN_ALBUM_GAIN"]) @track_peak = check_float(comments["REPLAYGAIN_TRACK_PEAK"]) @album_peak = check_float(comments["REPLAYGAIN_ALBUM_PEAK"]) end |
Class Method Details
.new(comments) ⇒ Object
52 53 54 55 |
# File 'lib/dtas/replaygain.rb', line 52 def self.new(comments) tmp = super tmp.track_gain ? tmp : nil end |
Instance Method Details
#check_float(val) ⇒ Object
22 23 24 |
# File 'lib/dtas/replaygain.rb', line 22 def check_float(val) /(\d+(?:\.\d+)?)/ =~ val ? $1 : nil end |
#check_gain(val) ⇒ Object
18 19 20 |
# File 'lib/dtas/replaygain.rb', line 18 def check_gain(val) /([+-]?\d+(?:\.\d+)?)/ =~ val ? $1 : nil end |
#to_env ⇒ Object
note: this strips the “dB” suffix, but that should be easier for apps to deal with anyways…
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dtas/replaygain.rb', line 28 def to_env rv = {} # this will cause nil to be set if some envs are missing, this causes # Process.spawn to unset the environment if it was previously set # (leaked from some other process) ENV_ATTRS.each do |env_name, attr_name| rv[env_name] = __send__(attr_name) end rv end |