Skip to content

Instantly share code, notes, and snippets.

@PrivateGER
Last active December 4, 2018 22:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PrivateGER/88c92b02146a35fafd287edfc13c7a5f to your computer and use it in GitHub Desktop.
Save PrivateGER/88c92b02146a35fafd287edfc13c7a5f to your computer and use it in GitHub Desktop.
Tumblr Downloader
const download = require('download-file');
const request = require('request');
const colors = require("colors");
const path = require("path");
const download_directory = "./download/";
const API_KEY = "";
const downloadPicture = (blogname, tagname, uuid, url) => {
if(tagname === undefined) {
tagname = "No tags";
}
var options = {
directory: download_directory,
filename: `${blogname}|${tagname}|${uuid}${path.extname(url)}`,
timeout: 900000
};
console.log("[*] ".blue + "Starting download of " + `${blogname}|${tagname}|${uuid}${path.extname(url)}` + ".");
download(url, options, function(err){
if (!err) {
console.log("[OK] ".green + "Downloaded " + `${blogname}|${tagname}|${uuid}${path.extname(url)}` + " successfully.");
} else {
console.log("[FAIL] ".red + "Downloading of " + `${blogname}|${tagname}|${uuid}${path.extname(url)}` + " failed!");
}
});
};
const parseBlog = (json) => {
json.response.posts.forEach((element) => {
if(element.type !== "photo") {
return;
}
downloadPicture(json.response.blog.name, element.tags[0], element.id, element.photos[0].original_size.url);
});
};
const getBlogContent = (identifier) => {
for(let i = 0; i < 5; i++) {
request(`https://api.tumblr.com/v2/blog/${ identifier }/posts?limit=20&offset=${ i * 20 }&api_key=${ API_KEY }`, (error, response, body) => {
let parsedData = JSON.parse(body);
parseBlog(parsedData);
});
}
};
for(let i = 0; i < process.argv.length; i++) {
if(i > 1) {
getBlogContent(process.argv[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment