1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| npm install megajs compressing rm -f run.js || true # rm -f pixiv*.zip || true rm -rf pixiv || true mkdir pixiv cat>>run.js<<-EOF const readline = require('readline'); const mega = require("megajs"); const fs = require("fs"); const compressing = require("compressing"); var y, z = 0; var email = "", password = ""; var folderToDownload = "Pixiv";
console.log("+-----------------------------------------------------------+"); console.log("| |"); console.log("| Download Specific Folder From Mega And Pack Up to Zip |"); console.log("| |"); console.log("+-----------------------------------------------------------+");
console.log("ATTENTION: Password will be shown - Do not let any others see");
Date.prototype.format = function (fmt) { var date = this; var o = { "M+": date.getMonth() + 1, "d+": date.getDate(), "h+": date.getHours(), "m+": date.getMinutes(), "s+": date.getSeconds(), "q+": Math.floor((date.getMonth() + 3) / 3), "S": date.getMilliseconds() }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.\$1, (date.getFullYear() + "").substr(4 - RegExp.\$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.\$1, (RegExp.\$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; }
console.log("Input email: ");
var rl = readline.createInterface({ input: process.stdin, output: process.stdout });
new Promise((resolve, reject) => { rl.on('line', function(line){ email = line; rl.close(); resolve(); }); }).then(() => {
console.log("Input password: ");
new Promise((resolve, reject) => { var rl2 = readline.createInterface({ input: process.stdin, output: process.stdout });
rl2.stdoutMuted = true;
rl2._writeToOutput = function _writeToOutput(stringToWrite) { if (rl2.stdoutMuted) rl2.output.write("*"); else rl2.output.write(stringToWrite); }; rl2.on('line', function(line){ password = line; rl2.close(); resolve(); }); }).then(async () => {
console.clear();
var storage; console.log("Logging " + email + " in ...");
new Promise((resolve, reject) => { storage = mega({email: email, password: password}, () => { resolve(); }); }).then(() => {
var folder = storage.root.children.find(x => x.name == folderToDownload);
console.log("To Download " + folderToDownload); console.log("Total Files: " + folder.children.length);
for (var x in folder.children) { folder.children[x].download({}, function () { console.log((Number(z) + 1) + "/" + folder.children.length + " finished"); z++; if (z >= folder.children.length) { console.log("begin packing"); compressing.zip.compressDir('pixiv', 'pixiv' + new Date().format("yyyyMMddhhmmss") + '.zip').then(() => { console.log('Packing complete!!!'); console.log('NOTE: If you want to download from "Download as Zip" in the upper right menu, you must rename this zip file to something else, in the menu next to the zip file, in the file list on the left hand side. Otherwise the zip wont contain the zip you want. This is a ReplIt bug months ago.'); console.log('Zip file wont be deleted by the nodejs script. As the downloaded zip would preserve the zip file just deleted. The previous zip file is strongly suggested to delete manually in the file list on the left hand side.'); console.log('Program ends'); process.exit(); }) .catch(err => { console.error(err); }); } }).pipe(fs.createWriteStream("./pixiv/" + folder.children[x].name)); console.log((Number(x) + 1) + "/" + folder.children.length + " started"); }
});
}); });
EOF clear node run.js rm -f run.js rm -rf pixiv
|