-
-
Save mustafat0k/3688cb24264a4be7df1d9d3ef3f7a56d to your computer and use it in GitHub Desktop.
pull all images from xml
This file contains hidden or 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
'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