Module: BatchAudioConvert

Includes:
AudioUtils, FileUtils
Defined in:
lib/batch_audio_convert/version.rb,
lib/batch_audio_convert.rb

Overview

BatchAudioConvert

Copyright © 2013-2015 L.Briais under MIT license opensource.org/licenses/MIT

Constant Summary collapse

VERSION =
'0.2.0'

Constants included from AudioUtils

AudioUtils::FLAC_DEC_CMD, AudioUtils::MP3_ENC_CMD, AudioUtils::OGG_ENC_CMD, AudioUtils::TAGS

Instance Method Summary collapse

Methods included from AudioUtils

#flac_to_mp3, #flac_to_ogg

Methods included from FileUtils

#analyze_file, #copy, #is_directory_to_process?, #is_image?, #populate_list_of_files_from_directory, #populate_list_of_files_from_file, #replace_folder_in_destination!, #should_process_file?, #verify_destination_folder

Instance Method Details

#build_file_listObject

Determine files to process



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/batch_audio_convert.rb', line 20

def build_file_list
  puts_and_logs 'Finding files...'
  file_list = []
  config[:source].each do |entry|
    if File.directory?(entry)
      populate_list_of_files_from_directory(file_list, entry) 
      next
    end
    if File.file?(entry)
      populate_list_of_files_from_file(file_list, entry) 
      next
    end
    logger.warn "\"#{entry}\" is neither a directory nor a regular file. Ignored..."
  end
  logger.debug(file_list)
  file_list
end

#process_files(file_list) ⇒ Object

Generate destination directory



39
40
41
42
43
44
45
# File 'lib/batch_audio_convert.rb', line 39

def process_files(file_list)
  puts_and_logs 'Processing files...'
  file_list.each do |file|
    analysis_result = analyze_file file
    self.send analysis_result[:method_name], file, analysis_result[:destination_file]
  end
end

#run_command(cmd) ⇒ Object

Runs an external command



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/batch_audio_convert.rb', line 49

def run_command(cmd)
  if config[:simulate]
    puts_and_logs " - Simulate running \"#{cmd}\""
    return
  end
  if config[:debug]
    if config[:verbose]
      puts_and_logs " - Running \"#{cmd}\""
    else
      logger.debug " - Running \"#{cmd}\""
    end
    system cmd
    return
  end
  puts_and_logs " - Running \"#{cmd}\"" if config[:verbose]
  system(cmd + ' > /dev/null 2>&1')

end