<commit_before># http://groups.google.co.jp/group/comp.lang.ruby/browse_thread/thread/e4ffdc9226489861
require 'uri'
require 'lib/mmm/wave_utils'

class ResourceController < ApplicationController
  def index
    @resources = Resource.find(:all)
  end
  
  def show
    @resource = Resource.find(params[:id])
    @items = @resource.items
  end
  
  def new
    #
  end
  
  def import
    uri = URI.parse(params[:import_url])
    http = Net::HTTP.new(uri.host, uri.port)
    # "path/to/foobar.wav" => "foobar_org.wav"
    filename_org = File.basename(uri.path, ".*") + "_org" + File.extname(uri.path)
    filename     = File.basename(uri.path)
    begin
      http.start do
        http.request_get(uri.path) do |res|
          File.open(RAILS_ROOT + "/tmp/" + filename_org, 'wb') do |f|
            f.write(res.body)
          end
        end
      end
    rescue
      flash[:notice] = "error on saving audio."
      redirect_to :back ; return
    end
    # convert filename_org => filename
    begin
      WaveUtils.wav_to_linear(RAILS_ROOT + "/tmp/" + filename_org, 
                              RAILS_ROOT + "/public/audio/" + filename)
      # WaveUtils.wav_to_linear(RAILS_ROOT + "/tmp/" + filename_org, 
      #                         RAILS_ROOT + "/tmp/" + filename)
      # a = Audiofile.new
      # a.name = filename
      # a.file = File.open(RAILS_ROOT + "/tmp/" + filename, 'rb').read
      # a.save!
    rescue
      flash[:notice] = "error on wav_to_linear."
      redirect_to :back ; return
    end
    # add to Mediaitem
    mediaitem = Mediaitem.new
    mediaitem.filepath = filename
    mediaitem.created_at = params[:import_pub_date]
    mediaitem.title = Resource.find(params[:id]).title<commit_msg>cleanup<commit_after># http://groups.google.co.jp/group/comp.lang.ruby/browse_thread/thread/e4ffdc9226489861
require 'uri'
require 'lib/mmm/wave_utils'

class ResourceController < ApplicationController
  def index
    @resources = Resource.find(:all)
  end
  
  def show
    @resource = Resource.find(params[:id])
    @items = @resource.items
  end
  
  def new
    #
  end
  
  def import
    uri = URI.parse(params[:import_url])
    http = Net::HTTP.new(uri.host, uri.port)
    # "path/to/foobar.wav" => "foobar_org.wav"
    filename_org = File.basename(uri.path, ".*") + "_org" + File.extname(uri.path)
    filename     = File.basename(uri.path)
    begin
      http.start do
        http.request_get(uri.path) do |res|
          File.open(RAILS_ROOT + "/tmp/" + filename_org, 'wb') do |f|
            f.write(res.body)
          end
        end
      end
      WaveUtils.wav_to_linear(RAILS_ROOT + "/tmp/" + filename_org, 
                              RAILS_ROOT + "/public/audio/" + filename)
      # WaveUtils.wav_to_linear(RAILS_ROOT + "/tmp/" + filename_org, 
      #                         RAILS_ROOT + "/tmp/" + filename)
      # a = Audiofile.new
      # a.name = filename
      # a.file = File.open(RAILS_ROOT + "/tmp/" + filename, 'rb').read
      # a.save!
    rescue
      flash[:notice] = "error on saving audio."
      redirect_to :back ; return
    end
    # add to Mediaitem
    mediaitem = Mediaitem.new
    mediaitem.filepath = filename
    mediaitem.created_at = params[:import_pub_date]
    mediaitem.title = Resource.find(params[:id]).title
{'fraction_non_alphanumeric': 0.12895377128953772, 'fraction_numerical': 0.006690997566909975, 'mean_word_length': 2.3255813953488373, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2633776', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1109, 'n_words': 208}