Last active
December 4, 2018 22:37
-
-
Save PrivateGER/88c92b02146a35fafd287edfc13c7a5f to your computer and use it in GitHub Desktop.
Tumblr Downloader
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
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