Created
June 23, 2015 07:06
-
-
Save tgallant/a6fd1b49bdf4abd5994e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
}); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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