Skip to content

Instantly share code, notes, and snippets.

@tgallant
Created June 23, 2015 07:06
Show Gist options
  • Save tgallant/a6fd1b49bdf4abd5994e to your computer and use it in GitHub Desktop.
Save tgallant/a6fd1b49bdf4abd5994e to your computer and use it in GitHub Desktop.
var fs = require('fs');
var request = require('request');
var cheerio = require('cheerio');
var saveFile = function(url) {
var file = url.split('/').pop();
request(url).pipe(fs.createWriteStream(file));
console.log('Downloading ' + file);
return true;
};
request('http://m-base.com/downloads/', function(error, response, body) {
if(!error && response.statusCode == 200) {
var $ = cheerio.load(body);
var tracks = [];
$('a').each(function(i, elem) {
var val = $(this).attr('href');
var filetype = val.substr(val.length - 3);
if(filetype === 'mp3') {
saveFile(val);
}
});
}
});
{
"name": "scdl",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "MIT",
"dependencies": {
"cheerio": "^0.19.0",
"request": "^2.58.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment