Class: AudioDicer::Runner
- Inherits:
-
Object
- Object
- AudioDicer::Runner
- Defined in:
- lib/audio_dicer/runner.rb
Instance Attribute Summary collapse
-
#ctx ⇒ Object
readonly
Returns the value of attribute ctx.
Class Method Summary collapse
Instance Method Summary collapse
-
#expand_relative_file(*args) ⇒ Object
kind of lame but w/e.
-
#initialize(ctx) ⇒ Runner
constructor
A new instance of Runner.
- #run ⇒ Object
Constructor Details
#initialize(ctx) ⇒ Runner
Returns a new instance of Runner.
5 6 7 |
# File 'lib/audio_dicer/runner.rb', line 5 def initialize(ctx) @ctx = ctx end |
Instance Attribute Details
#ctx ⇒ Object (readonly)
Returns the value of attribute ctx.
3 4 5 |
# File 'lib/audio_dicer/runner.rb', line 3 def ctx @ctx end |
Class Method Details
.bin_available?(name) ⇒ Boolean
9 10 |
# File 'lib/audio_dicer/runner.rb', line 9 def self.bin_available?(name) end |
Instance Method Details
#expand_relative_file(*args) ⇒ Object
kind of lame but w/e
13 14 15 |
# File 'lib/audio_dicer/runner.rb', line 13 def (*args) AudioDicer.(*args) end |
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/audio_dicer/runner.rb', line 17 def run src_opts = ctx. # First convert the video to a wav puts '[*] Extracting audio' system "mplayer -really-quiet -vc null -vo null -nocorrect-pts -ao pcm:waveheader #{ src_opts[:source]}" abort '[!] mplayer failed' unless File.exist?(('audiodump.wav')) # Now convert that to one big mp3 puts '[*] Convert WAV to MP3' system "lame -h -b #{src_opts[:bitrate] || 192} audiodump.wav audiodump.mp3" abort '[!] lame failed' unless File.exist?(('audiodump.mp3')) # Now split that mp3 using out data ctx.albums.each do |album| opts = album. puts "[*] Spliting #{album.tracks.size} tracks" # TODO allow stop to be optional (even splits) # TODO allow last track to use EOF album.tracks.each.with_index do |track, index| start, stop = track[:time].map { |t| t.sub ':', '.' } = "@a=#{opts[:artist].inspect},@b=#{opts[:name].inspect},@t=#{track[:title].inspect}" system "mp3splt -Qf -g [#{}] -o '#{index+1} @a - @t' audiodump.mp3 #{start} #{stop}" end end # Now cleanup puts '[*] Complete!' rescue SystemExit => e # Always clean up potental trash File.unlink(*%w[wav mp3].map { |ext| "audiodump.#{ext}" }) rescue nil raise e # raise to exit end |