#!/usr/bin/env ruby $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib') require 'rest_client' require 'mime/types' require 'tempfile' filename = ARGV[1] basename = File.basename(filename) types = MIME::Types.type_for(filename) valido = false for i in types if i.content_type.include? "wav" or i.content_type.include? "x-wav" valido = true end end t = Tempfile.new(basename) if !valido puts "convirtiendo a wav antes de subir" `ffmpeg -i "#{filename}" -vn -acodec pcm_s16le -ar 16000 -ac 1 -f wav "#{t.path}"` filename = t.path end file = File.new(ARGV[1]) puts "uploading..." begin RestClient.post('http://cluster.metaforas.cl/audios', "audio[audio_original]" => File.new(filename), :api => ARGV[0]) rescue RestClient.post('http://cluster.metaforas.cl:8000/audios', "audio[audio_original]" => File.new(filename), :api => ARGV[0]) end t.close puts "ready"