diff --git a/scripts/rebuild_preview.rb b/scripts/rebuild_preview.rb index 9c13a1b..fddb1a5 100644 --- a/scripts/rebuild_preview.rb +++ b/scripts/rebuild_preview.rb @@ -13,6 +13,8 @@ class Processor < Nerve::Job::Process def initialize; end + def at *args; end + def process_track track # rebuild the track's preview and peaks @@ -20,27 +22,45 @@ def process_track track prev_path = $config["export"]["directory"] + "/" + path + ".ogg" wave_path = $config["export"]["directory"] + "/" + path + ".dat" + exported_path = Object.const_get($config["export"]["mode"]).find_path(track) + # If we already have the preview, we probably - if File.exist?(prev_path) or !File.exist?(track) + if File.exist?(prev_path) or !File.exist?(exported_path) _debug "Skipping for some reason" return end - exported_path = self.find_path(track) - _debug "Generating preview" + temp = [] + + begin + + _debug "Generating preview" + + temp << Tempfile.new(['nerve', '.wav']) + temp_path = temp[0].path + temp[0].close; temp[0].unlink + + FileUtils::copy(exported_path, temp_path) + + convert(temp_path, prev_path, "ogg", "-1") - convert(exported_path, prev_path, "ogg", "-1") + raise "Conversion failed!" unless File.exists? prev_path - raise "Conversion failed!" unless File.exists? prev_path + _debug "Generating waveform" - _debug "Generating waveform" + generate_waveform(temp_path, track.length.to_f, wave_path) - generate_waveform(prev_path, options["length"], wave_path) + raise "Generating waveform failed" unless File.exists? wave_path - raise "Generating waveform failed" unless File.exists? + _debug "Done!" + + rescue - _debug "Done!" + temp.map { |t| File.unlink(t) } + raise $! + + end end