-
Notifications
You must be signed in to change notification settings - Fork 4
/
upload.coffee
39 lines (30 loc) · 1.17 KB
/
upload.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
fs = require 'fs'
request = require 'request'
authKeys = JSON.parse fs.readFileSync('auth.json')
Echonest = new require('echonest').Echonest
echo = new Echonest api_key: authKeys.echonest
[_, _, path, name] = process.argv
console.log "Uploading: #{path}"
console.log "Saving as: #{name}"
console.log "Standby..."
filetype = path.match(/\.(\w+?)$/)[1]
echo.track.upload filetype: filetype, track: fs.readFileSync(path), (error, response) ->
if error
console.log error, response
else
fs.createReadStream(path).pipe fs.createWriteStream("songs/#{name}.#{filetype}")
console.log 'response:', response
setInterval ->
echo.track.profile id: response.track.id, bucket: 'audio_summary', (error, response) ->
if error
console.log error, response
process.exit()
else
console.log 'response:', response
if response.track.status is 'complete'
request response.track.audio_summary.analysis_url, (err, res, body) ->
body = JSON.stringify(JSON.parse(body), null, 2)
fs.writeFileSync "songs/#{name}.json", body
console.log 'Done!'
process.exit()
, 1000