diff --git a/change_tempo.rb b/change_tempo.rb index d17b3b9..19605de 100755 --- a/change_tempo.rb +++ b/change_tempo.rb @@ -2,7 +2,7 @@ %w[rubygems appscript tempfile].each {|l| require l } gem 'activesupport', '2.3.8' -require 'activesupport' +require 'active_support' file = __FILE__ file = File.expand_path(File.readlink(file), File.dirname(file)) while File.symlink?(file) @@ -19,9 +19,12 @@ opts.separator "updates them." opts.separator "" opts.separator "Specific options:" - opts.on("-s", "--speedup TEMPO", Integer, "Increase tempo by TEMPO (as a percentage)") do |c| + opts.on("-s", "--speedup TEMPO", Integer, "Increase tempo by TEMPO (as a percentage).") do |c| Podcast.speedup = c end + opts.on("-q", "--quiet", "Do not log messages to standard output.") do |c| + Podcast.quiet = true + end opts.on_tail("-h", "--help", "Show this message") do puts opts exit @@ -39,9 +42,9 @@ end $stderr.puts Podcast.problems.inspect unless Podcast.problems.empty? rescue OptionParser::InvalidOption => e - puts e.message - puts - puts opts + $stderr.puts e.message + $stderr.puts + $stderr.puts opts exit end end diff --git a/lib/podcast.rb b/lib/podcast.rb index 4b58224..a37e09c 100644 --- a/lib/podcast.rb +++ b/lib/podcast.rb @@ -1,7 +1,7 @@ class Podcast cattr_reader :problems - cattr_accessor :speedup, :playlist, :file + cattr_accessor :speedup, :playlist, :file, :quiet @@problems = [] self.speedup ||= 25 @@ -26,12 +26,12 @@ def playlist_count def process(job) if File.exist?(job) - puts "Shifting file:#{job} with speedup:#{Podcast.speedup}..." + log "Shifting file:#{job} with speedup:#{Podcast.speedup}..." PodcastFromMp3.new(job).change_tempo else - puts "Running with playlist:#{Podcast.playlist} (#{Podcast.playlist_count} mp3s) and speedup:#{Podcast.speedup}..." - puts " (speedup #{Podcast.speedup} means moving the audio to #{Podcast.speedup + 100}% of it's normal speed)" + log "Running with playlist:#{Podcast.playlist} (#{Podcast.playlist_count} mp3s) and speedup:#{Podcast.speedup}..." + log " (speedup #{Podcast.speedup} means moving the audio to #{Podcast.speedup + 100}% of it's normal speed)" Podcast.playlist = job Podcast.all_slow_podcasts.each do |p| @@ -49,6 +49,9 @@ def all_podcast_refs(playlist = self.playlist) [] end end + def log(message) + puts message unless quiet + end end # Instance methods @@ -166,8 +169,8 @@ def unescape_filename(filename) filename.gsub(/\\/,'') end def cmd(command_string) - puts command_string - puts `#{command_string}` + log command_string + log `#{command_string}` exitstatus = $?.exitstatus raise(RuntimeError, $?) unless exitstatus == 0 end