Skip to content

Instantly share code, notes, and snippets.

@izumogeiger
Last active December 21, 2015 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save izumogeiger/6366082 to your computer and use it in GitHub Desktop.
Save izumogeiger/6366082 to your computer and use it in GitHub Desktop.
# coding:utf-8
require "pp"
require "fileutils"
require "dropbox_sdk"
if ARGV.size < 2
puts "#{File.basename(__FILE__)} title sec"
end
now = Time.now
dir = File.join(ENV["HOME"],"radio",now.strftime("%Y"),now.strftime("%m"))
FileUtils.mkdir_p(dir)
wav = File.join(dir,"#{ARGV[0]}_#{now.strftime("%Y%m%d%H%M%S")}.wav")
mp3 = File.join(dir,"#{ARGV[0]}_#{now.strftime("%Y%m%d%H%M%S")}.mp3")
args = [
'-playlist',
'http://mfile.akamai.com/129932/live/reflector:46056.asx',
'-vo',
'null',
'-ao',
"pcm:waveheader:fast:file=#{wav}"
]
pid = Process.spawn('mplayer',*args)
sleep ARGV[1].to_i
Process.kill(:SIGKILL,pid)
`lame -q 4 #{wav} #{mp3}`
FileUtils.rm(wav)
mp3base = File.basename(mp3)
remotefile = File.join("nhk-radio-2",now.strftime("%Y%m%d"),mp3base)
puts mp3
puts remotefile
access_token = "xxxxxxxxxxxxxxxxxxxxx"
client = DropboxClient.new(access_token)
puts "linked account:", client.account_info().inspect
f = open(mp3)
response = client.put_file(remotefile, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment