14 oktober 2013

Batch uploading music files to Echo Nest

This is in English for an international audience.

There is an interesting service celled The Echo Nest that is a music API you can do a lot of interesting things with like The Count. But if you (like me) have music that is a bit outside the mainstream there is the problem that they do not know about it. So I hacked together a simple package to upload mp3 files to their servers for analysis.

First you need
Ok, my batch coding skills are very rusty so please forgive me for this rather hackish solution.

I created the directory C:\CURLER and put curl.exe there. I also created two batch files.
One called CURLER.BAT as
@echo off
echo %1
C:\curler\curl -X POST -H "Content-Type:application/octet-stream" "http://developer.echonest.com/api/v4/track/upload?api_key=YOUR_API_KEY&filetype=mp3" --data-binary @%1
timeout /t 2
Replace YOUR_API_KEY with the API key you got from the Dev Center.
This file takes the file name of an mp3 file and uploads it to Echo Nest's servers. It does not check if they already know about it (sorry about that, I'll try to make something better later).

Well, that works, but it is a bit tedious so I made another batch file I called ALLMP3.BAT and it looks like
@echo off
FOR /R %1 %%G IN (*.mp3) do call C:\curler\curler.bat "%%G"
 It takes a directory name as parameter and loops trough that and all subdirectories of it and sends them.