Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var FeedParser = require('feedparser')
- , request = require('request')
- , http = require('http')
- , fs = require('fs');;
- var download = function(url, dest) {
- var file = fs.createWriteStream(dest);
- http.get(url, function(response) {
- response.pipe(file);
- });
- };
- var imgs = [];
- var req = request('http://kitchen.screenfeed.com/feed/PrPDzFccLU2Rc9j4aGEofw?duration=15')
- , feedparser = new FeedParser();
- req.on('error', function (error) {
- // handle any request errors
- });
- req.on('response', function (res) {
- var stream = this;
- if (res.statusCode != 200) return this.emit('error', new Error('Bad status code'));
- stream.pipe(feedparser);
- });
- feedparser.on('error', function(error) {
- // always handle errors
- });
- feedparser.on('readable', function() {
- // This is where the action is!
- var stream = this
- , meta = this.meta // **NOTE** the "meta" is always available in the context of the feedparser instance
- , item;
- while (item = stream.read()) {
- imgs.push(item.image.url)
- }
- imgs.forEach(function(img, index) {
- download(img, String(index + 1) + '.jpg');
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement