Skip to content

Instantly share code, notes, and snippets.

@mustafat0k
Created March 6, 2021 14:05
Show Gist options
  • Save mustafat0k/3688cb24264a4be7df1d9d3ef3f7a56d to your computer and use it in GitHub Desktop.
Save mustafat0k/3688cb24264a4be7df1d9d3ef3f7a56d to your computer and use it in GitHub Desktop.
pull all images from xml
'use strict';
const fs = require('fs');
const xml2js = require('xml2js');
const request = require('request')
const parser = xml2js.Parser();
const { v4: uuidv4 } = require('uuid');
const download = (url, path, callback) => {
request.head(url, (err, res, body) => {
request(url)
.pipe(fs.createWriteStream(path))
.on('close', callback)
})
}
fs.readFile('list.xml', 'utf-8', function (err, data) {
if (err) throw err;
parser.parseString(data, function (err, result) {
let k = result.ListBucketResult.Contents;
console.log(k.length)
let count = 0;
k.forEach(keys => {
const url = 'https://cdn.dsmcdn.com/ty77/'+keys.Key[0];
const path = `./images/${uuidv4()}.png`;
download(url, path, () => {
console.log(`${++count} ✅ Done!`)
})
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment