Skip to content
This repository has been archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Shhh (add --quiet commandline option)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewfallshaw committed Jul 7, 2010
1 parent 748bcff commit 6f054a5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
13 changes: 8 additions & 5 deletions change_tempo.rb
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
15 changes: 9 additions & 6 deletions 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
Expand All @@ -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|
Expand All @@ -49,6 +49,9 @@ def all_podcast_refs(playlist = self.playlist)
[]
end
end
def log(message)
puts message unless quiet
end
end

# Instance methods
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6f054a5

Please sign in to comment.