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,GACd,QAAQ,IAAI,GACZ,QAAQ,KAAK,EACjB,CAGA,QAAQ,cAAe","file":"/npm/imgur-alb@1.1.0/albget.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/imgur-alb@1.1.0/albget.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/* Node dependencies */\r\nvar request = require('request'); //For calling the url.\r\nvar fs = require('file-system'); //For saving images and creating directories.\r\n\r\n/* Imgur API client id, plz no steal */\r\nvar clientID = \"3752a956b4926c9\";\r\n\r\n/* For checking directory name */\r\nvar unallowChar = \"><:\\\"\\\\/|?*\\0\"; //List of unnallowed characters.\r\n\r\n//Get the argument count.\r\nvar args = process.argv.splice(2, 4); //Get rid of the first two elements as those aren't needed.\r\n\r\nvar customPath = args.length > 1;\r\nvar pathArg\r\n\r\nif (customPath) {\r\n    pathArg = args[1];\r\n}\r\n\r\n//Testing for usage.\r\nif (args.length < 1 || args.length > 2) {\r\n    failExit(\"Incorrect usage! See README for usage information.\")\r\n}\r\n\r\nvar urlImages = \"https://api.imgur.com/3/album/\" + getAlbumHash(args[0]); //Get the url argument for the images themselves.\r\n\r\nvar optionsImages = {\r\n    url: urlImages,\r\n    headers: {\r\n        'authorization': 'Client-ID ' + clientID\r\n    }\r\n}\r\n\r\n/**\r\n * @desc Get the hash from an album by splitting the url.\r\n * @param {string} url the url to get the album has from. \r\n * @return {string} the album hash.\r\n */\r\nfunction getAlbumHash(url) {\r\n    return url.split(\"/\")[url.split(\"/\").length - 1]\r\n}\r\n\r\n/**\r\n * @desc Parse the images for important information to get the title and links from them.\r\n * @param {error} err passing an error if the images are invalid. \r\n * @param {string} resp the response from the HTTP get req.\r\n * @param {string} body the original body from the req.\r\n */\r\nfunction parseImages(err, resp, body) {\r\n    if (err != null) {\r\n        failExit(err);\r\n    }\r\n\r\n    var imgTitles = [];\r\n    var imgLinks = [];\r\n\r\n    JSON.parse(body, (key, val) => {\r\n        if (key == \"title\") {\r\n            imgTitles.push(val); //Push titles to array.\r\n        }\r\n\r\n        if (key == \"link\") {\r\n            imgLinks.push(val); //Push links to array.\r\n        }\r\n    });\r\n\r\n    if (!customPath) {\r\n        //The title to the album will always be the first element.\r\n        var dirTitle = removeSpecialCharacters(imgTitles[0]); //Remove unsuable directory characters.\r\n        fs.mkdir(dirTitle); //Create the directory for the folders.\r\n    } else {\r\n        var dirTitle = pathArg; //Just set that to the directory.\r\n    }\r\n\r\n    imgLinks = imgLinks.slice(1, imgLinks.length); //Get rid of the album elements.\r\n\r\n    //Loop through all\r\n    for (image = 0; image < imgLinks.length; image++) {\r\n        var filename = imgLinks[image].split(\"/\")[3];\r\n        download(imgLinks[image], filename, dirTitle); //Send a request to download them.\r\n    }\r\n\r\n    console.log(\"Album is located at --> '\" + dirTitle + \"'\");\r\n}\r\n\r\n/**\r\n * @desc Remove special characters from the directory name to prevent invalid naming.\r\n * @param {string} dir the directory name.\r\n * @return {string} the directory name without invalid characters. \r\n */\r\nfunction removeSpecialCharacters(dir) {\r\n    var newDir = \"\"; //The newDir with removed invalid characters.\r\n\r\n    for (letter = 0; letter < dir.length; letter++) {\r\n        if (unallowChar.indexOf(dir.charAt(letter)) === -1) { //If the char is valid.\r\n            newDir += dir.charAt(letter); //If the character is valid add it to the newDir.\r\n        }\r\n    }\r\n\r\n    return newDir;\r\n}\r\n\r\n/**\r\n * @desc Sends an HTTP get request and pipes it to a write stream.\r\n * @param {*} link the link we're sending the req to.\r\n * @param {*} filename the filename we're writing to.\r\n * @param {*} dir the drectory name we're writing to.\r\n */\r\nfunction download(link, filename, dir) {\r\n    request(link).pipe(fs.createWriteStream(dir + \"/\" + filename));\r\n}\r\n\r\n/**\r\n * @desc Fail the program and display why.\r\n * @param {err/string} why the reason the program failed if a reason is given. \r\n */\r\nfunction failExit(why) {\r\n    console.log(why);\r\n    process.exit(1);\r\n}\r\n\r\n/* Send the requests to Imgur API */\r\nrequest(optionsImages, parseImages);\r\n"]}