Skip to content

Instantly share code, notes, and snippets.

@zhepa zhepa/VK album Download.js
Last active Jul 22, 2018

Embed
What would you like to do?
Скачать альбом ВКонтакте бесплатно
const fs = require('fs');
const https = require('https');
const settings = {
albumId: 123,
token: 'сосать жопу'
};
https.get(`https://api.vk.com/method/photos.get?photo_sizes=1&album_id=${settings.albumId}&access_token=${settings.token}&v=5.70`, res => {
let result = '', queue = [];
res.on('data', data => result += data);
res.on('end', () => {
result = JSON.parse(result);
for (const item of result.response.items) {
queue.push(item.sizes[item.sizes.length - 1].src);
}
downloadFile();
});
function downloadFile() {
const url = queue[0];
if (!url) {
console.log('all done');
process.exit();
}
const fileName = url.match(/[a-z_\-0-9]+\.jpg/gi);
const writeStream = fs.createWriteStream(`./downloads/${fileName}`);
https.get(url, res => {
res.pipe(writeStream);
res.on('end', () => {
queue.splice(0, 1);
console.log(`${fileName} done, ${queue.length} items left`);
downloadFile();
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.