Skip to content

Instantly share code, notes, and snippets.

@mkobar
Forked from mikerudolph/Rdio Proxy
Created September 29, 2015 17:18
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 mkobar/6da1aca26b117ea9a3ea to your computer and use it in GitHub Desktop.
Save mkobar/6da1aca26b117ea9a3ea to your computer and use it in GitHub Desktop.
I wanted to see how easy it was to download Rdio songs as you listen to them, turns out its just as easy as I though.
var http = require('http'),
url = require('url'),
fs = require('fs');
var port = 9000;
var httpServer = http.createServer(function(request, response) {
var parsedUrl = url.parse(request.url);
var requestData;
var requestOpts = {
headers: request.headers,
hostname: request.headers.host,
method: request.method,
path: parsedUrl.path
};
var mp3FileName = 'temp-mp3-file.mp3';
var mp3File = null;
var proxy = http.request(requestOpts, function(res) {
console.log(res);
// Check to see if this is an mp3 file
// TODO: verify its from rdio and not something random
if (parsedUrl.path.indexOf('.mp3') !== -1) {
console.log('FOUND MP3 FILE!!!');
mp3File = new Buffer('');
}
res.on('data', function(chunk) {
if (mp3File) {
mp3File = Buffer.concat([mp3File, chunk]);
}
response.write(chunk, 'binary');
});
res.on('end', function() {
if (mp3File) {
fs.writeFile('./mp3/' + mp3FileName, mp3File, function(err) {
if (err) {
return console.log('Error writing file', err);
}
console.log('FINISHED GETTING MP3 FILE');
});
mp3File = null;
}
response.end();
});
res.on('error', function(err) {
console.log('ERROR SOMEWHERE');
});
response.writeHead(res.statusCode, res.headers);
});
request.on('data', function(chunk) {
requestData = requestData + chunk;
proxy.write(chunk, 'binary');
});
request.on('end', function() {
proxy.end();
});
request.on('error', function(err) {
console.log('Error');
});
});
httpServer.listen(port, function() {
console.log('HTTP Proxy Server is listening on port: ' + port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment