Skip to content

Commit

Permalink
Resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
atruskie committed Oct 29, 2012
2 parents d59d001 + cd81039 commit 0379f62
Show file tree
Hide file tree
Showing 12 changed files with 813 additions and 145 deletions.
4 changes: 2 additions & 2 deletions .idea/qubar.site.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: ruby
bundler_args: --without development
rvm:
- 1.9.3
# - 1.9.2
Expand All @@ -17,7 +18,6 @@ before_script:
script:
- ls -la
- RAILS_ENV=test bundle exec rake --trace db:migrate
- bundle exec rake --trace db:test:prepare
- bundle exec rake --trace
- RAILS_ENV=test bundle exec rake --trace
notifications:
webhooks: http://build.ecosounds.org/build
9 changes: 8 additions & 1 deletion app/controllers/media_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@ def item
# use params to get query string or parsed route parameters

# get the path for the file matching the request
@file_path = Cache::calculate_target_path(params)
file_name = Cache::cached_spectrogram_file(params)
#file_name = Cache::cached_audio_file(params)
#file_name = Cache::original_audio_file({ :id => '21EC2020-3AEA-1069-A2DD-08002B30309D', :date => '20121026', :time => '132600', :format => 'wav'})

#@file_path = Cache::possible_paths(file_name)
#@file_path = Cache::existing_paths(Cache::cached_spectrogram_storage_paths,file_name)
#@file_path = QubarSite::Application.config.media_file_config.cached_spectrogram_paths
@file_path = Cache::possible_paths(Cache::cached_spectrogram_storage_paths,file_name)

# see if the requested file exists

Expand Down
141 changes: 10 additions & 131 deletions lib/modules/audio.rb
Original file line number Diff line number Diff line change
@@ -1,145 +1,24 @@
require 'OS'

module Audio

@ffmpeg_path = if OS.windows? then "./vendor/bin/ffmpeg/windows/ffmpeg.exe" else "ffmpeg" end
@ffprobe_path = if OS.windows? then "./vendor/bin/ffmpeg/windows/ffprobe.exe" else "ffprobe" end
@sox_path = if OS.windows? then "./vendor/bin/sox/windows/sox.exe" else "sox" end
@wvunpack_path = if OS.windows? then "./vendor/bin/wavpack/windows/wvunpack.exe" else "wvunpack" end
@mp3splt_path = if OS.windows? then "./vendor/bin/mp3splt/windows/mp3splt.exe" else "mp3splt" end

@@my_logger ||= Logger.new("#{Rails.root}/log/my.log")

# public methods
public

include AudioSox, AudioMp3splt, AudioWavpack, AudioFfmpeg

# Provides information about an audio file.
def self.info(source)

info = []
error = []
sox_info source, info, error
ffprobe_info source, info, error
wvunpack_info source, info, error

info_sox source, info, error
info_ffmpeg source, info, error
info_wavpack source, info, error

# return the packaged info array
[ info, error ]
end

# Creates a new audio file from source path in target path, modified according to the
# parameters in modify_parameters
def self.modify(source, target, modify_parameters)
wvunpack(source, target, modify_parameters)
modify_wavpack(source, target, modify_parameters)
end

# private methods
private

def self.sox_info(source, info, error)
sox_arguments_info = "--info"
sox_command = "#{@sox_path} #{sox_arguments_info} \"#{source}\"" # commands to get info from audio file
sox_stdout_str, sox_stderr_str, sox_status = Open3.capture3(sox_command) # run the commands and wait for the result

if sox_status.exitstatus == 0
# sox std out contains info (separate on first colon(:))
sox_stdout_str.strip.split(/\r?\n|\r/).each { |line| info.push [ 'SOX ' + line[0,line.index(':')].strip, line[line.index(':')+1,line.length].strip ] }
# sox_stderr_str is empty
else
Rails.logger.debug "Sox info error. Return status #{sox_status.exitstatus}. Command: #{sox_command}"
error.push ['SOX ERROR',sox_stderr_str]
end
end

def self.ffprobe_info(source, info, error)
ffprobe_arguments_info = "-sexagesimal -print_format default -show_error -show_streams -show_format"
ffprobe_command = "#{@ffprobe_path} #{ffprobe_arguments_info} \"#{source}\""
ffprobe_stdout_str, ffprobe_stderr_str, ffprobe_status = Open3.capture3(ffprobe_command)

Rails.logger.debug "Ffprobe info return status #{ffprobe_status.exitstatus}. Command: #{ffprobe_command}"

if ffprobe_status.exitstatus == 0
# ffprobe std out contains info (separate on first equals(=))
# ffprobe_stderr_str contains progress info and human-formatted info
ffprobe_current_block_name = ''
ffprobe_stdout_str.strip.split(/\r?\n|\r/).each do |line|
line.strip!
if line[0] == '['
# this chomp reverse stuff is due to the lack of a proper 'trim'
ffprobe_current_block_name = line.chomp(']').reverse.chomp('[').reverse
else
current_key = line[0,line.index('=')].strip
current_value = line[line.index('=')+1,line.length].strip
info.push [ 'FFPROBE ' + ffprobe_current_block_name + ' ' + current_key, current_value ]
end
end
else
Rails.logger.debug "Ffprobe info error. Return status #{ffprobe_status.exitstatus}. Command: #{ffprobe_command}"
# ffprobe std err contains info (separate on first equals(=))
ffprobe_current_block_name = ''
ffprobe_stdout_str.strip.split(/\r?\n|\r/).each do |line|
line.strip!
if line[0] == '['
# this chomp reverse stuff is due to the lack of a proper 'trim'
ffprobe_current_block_name = line.chomp(']').reverse.chomp('[').reverse
else
current_key = line[0,line.index('=')].strip
current_value = line[line.index('=')+1,line.length].strip
error.push [ 'FFPROBE ' + ffprobe_current_block_name + ' ' + current_key, current_value ]
end
end
end
end

def self.wvunpack_info(source, info, error)
wvunpack_arguments_info = "-s"
wvunpack_command = "#{@wvunpack_path} #{wvunpack_arguments_info} \"#{source}\"" # commands to get info from audio file
wvunpack_stdout_str, wvunpack_stderr_str, wvunpack_status = Open3.capture3(wvunpack_command) # run the commands and wait for the result

Rails.logger.debug "Wavpack info return status #{wvunpack_status.exitstatus}. Command: #{wvunpack_command}"

if wvunpack_status.exitstatus == 0
# wvunpack std out contains info (separate on first colon(:))
wvunpack_stdout_str.strip.split(/\r?\n|\r/).each do |line|
line.strip!
current_key = line[0,line.index(':')].strip
current_value = line[line.index(':')+1,line.length].strip
info.push [ 'WVUNPACK ' + current_key, current_value ]
end

# wvunpack_stderr_str contains human-formatted info and errors
else
info.push [ 'WVUNPACK ERROR', wvunpack_stderr_str.strip!.split(/\r?\n|\r/).last ]
end
end

# wvunpack converts .wv files to .wav, optionally segmenting them
# target should be calculated based on modify_parameters by cache module
# modify_parameters can contain start_offset (fractions of seconds from start) and/or end_offset (fractions of seconds from start)
def self.wvunpack(source, target, modify_parameters = {})
raise ArgumentError, "Source is not a wavpack file: #{File.basename(source)}" unless source.match(/\.wv$/)
raise ArgumentError, "Target is not a wav file: : #{File.basename(target)}" unless target.match(/\.wav$/)
raise ArgumentError, "Source does not exist: #{File.basename(source)}" unless File.exists? source
raise ArgumentError, "Target exists: #{File.basename(target)}" unless !File.exists? source

# formatted time: hh:mm:ss.ss
arguments = '-t -q'
if modify_parameters.include? :start_offset
start_offset_formatted = Time.at(modify_parameters[:start_offset]).utc.strftime('%H:%M:%S.%2N')
arguments += ' --skip=#{start_offset_formatted}'
end

if modify_parameters.include? :end_offset
end_offset_formatted = Time.at(modify_parameters[:start_offset]).utc.strftime('%H:%M:%S.%2N')
arguments += ' --until=#{end_offset_formatted}'
end

wvunpack_command = "#{@wvunpack_path} #{arguments} \"#{source}\" \"#{target}\"" # commands to get info from audio file
wvunpack_stdout_str, wvunpack_stderr_str, wvunpack_status = Open3.capture3(wvunpack_command) # run the commands and wait for the result

if wvunpack_status.exitstatus == 0
raise "Wvunpack exited with an error: #{wvunpack_stderr_str}"
end
end


end
61 changes: 61 additions & 0 deletions lib/modules/audio_ffmpeg.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
module AudioFfmpeg
include OS
@ffmpeg_path = if OS.windows? then "./vendor/bin/ffmpeg/windows/ffmpeg.exe" else "ffmpeg" end
@ffprobe_path = if OS.windows? then "./vendor/bin/ffmpeg/windows/ffprobe.exe" else "ffprobe" end

# public methods
public


def self.info_ffmpeg(source)
info = []
error = []
ffprobe_arguments_info = "-sexagesimal -print_format default -show_error -show_streams -show_format"
ffprobe_command = "#{@ffprobe_path.to_s} #{ffprobe_arguments_info} \"#{source}\""
ffprobe_stdout_str, ffprobe_stderr_str, ffprobe_status = Open3.capture3(ffprobe_command)

Rails.logger.debug "Ffprobe info return status #{ffprobe_status.exitstatus}. Command: #{ffprobe_command}"

if ffprobe_status.exitstatus == 0
# ffprobe std out contains info (separate on first equals(=))
# ffprobe_stderr_str contains progress info and human-formatted info
ffprobe_current_block_name = ''
ffprobe_stdout_str.strip.split(/\r?\n|\r/).each do |line|
line.strip!
if line[0] == '['
# this chomp reverse stuff is due to the lack of a proper 'trim'
ffprobe_current_block_name = line.chomp(']').reverse.chomp('[').reverse
else
current_key = line[0,line.index('=')].strip
current_value = line[line.index('=')+1,line.length].strip
info.push [ 'FFPROBE ' + ffprobe_current_block_name + ' ' + current_key, current_value ]
end
end
else
Rails.logger.debug "Ffprobe info error. Return status #{ffprobe_status.exitstatus}. Command: #{ffprobe_command}"
# ffprobe std err contains info (separate on first equals(=))
ffprobe_current_block_name = ''
ffprobe_stdout_str.strip.split(/\r?\n|\r/).each do |line|
line.strip!
if line[0] == '['
# this chomp reverse stuff is due to the lack of a proper 'trim'
ffprobe_current_block_name = line.chomp(']').reverse.chomp('[').reverse
else
current_key = line[0,line.index('=')].strip
current_value = line[line.index('=')+1,line.length].strip
error.push [ 'FFPROBE ' + ffprobe_current_block_name + ' ' + current_key, current_value ]
end
end
end

[ info, error ]
end

def self.modify_ffmpeg(source, target, modify_parameters = {})
info = []
error = []
ffprobe_arguments_info = "-sexagesimal -print_format default -show_error -show_streams -show_format"
ffprobe_command = "#{@ffprobe_path.to_s} #{ffprobe_arguments_info} \"#{source}\""
ffprobe_stdout_str, ffprobe_stderr_str, ffprobe_status = Open3.capture3(ffprobe_command)
end
end
23 changes: 23 additions & 0 deletions lib/modules/audio_mp3splt.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module AudioMp3splt
include OS
@mp3splt_path = if OS.windows? then "./vendor/bin/mp3splt/windows/mp3splt.exe" else "mp3splt" end

# public methods
public

def self.info_mp3splt(source)
[ [], [] ]
end

# @param [file path] source
# @param [file path] target
# @param [hash] modify_parameters
def self.modify_mp3splt(source, target, modify_parameters = {})
raise ArgumentError, "Source is not a mp3 file: #{File.basename(source)}" unless source.match(/\.mp3$/)
raise ArgumentError, "Target is not a mp3 file: : #{File.basename(target)}" unless target.match(/\.mp3$/)
raise ArgumentError, "Source does not exist: #{File.basename(source)}" unless File.exists? source
raise ArgumentError, "Target exists: #{File.basename(target)}" unless !File.exists? source


end
end
46 changes: 46 additions & 0 deletions lib/modules/audio_sox.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module AudioSox
include OS
@sox_path = if OS.windows? then "./vendor/bin/sox/windows/sox.exe" else "sox" end

# public methods
public

def self.info_sox(source)
info = []
error = []

sox_arguments_info = "--info"
sox_command = "#{@sox_path.to_s} #{sox_arguments_info} \"#{source}\"" # commands to get info from audio file
sox_stdout_str, sox_stderr_str, sox_status = Open3.capture3(sox_command) # run the commands and wait for the result

if sox_status.exitstatus == 0
# sox std out contains info (separate on first colon(:))
sox_stdout_str.strip.split(/\r?\n|\r/).each { |line| info.push [ 'SOX ' + line[0,line.index(':')].strip, line[line.index(':')+1,line.length].strip ] }
# sox_stderr_str is empty
else
Rails.logger.debug "Sox info error. Return status #{sox_status.exitstatus}. Command: #{sox_command}"
error.push ['SOX ERROR',sox_stderr_str]
end

[ info, error ]
end

def self.modify_sox(source, target, modify_parameters = {})

info = []
error = []

sox_arguments_info = "--info"
sox_command = "#{@sox_path.to_s} #{sox_arguments_info} \"#{source}\"" # commands to get info from audio file
sox_stdout_str, sox_stderr_str, sox_status = Open3.capture3(sox_command) # run the commands and wait for the result

if sox_status.exitstatus == 0 && File.exists?(target)

else

end

[info, error]
end

end
Loading

0 comments on commit 0379f62

Please sign in to comment.