Created
October 14, 2019 20:17
-
-
Save maxjoehnk/28c08669bd2f4729529a0a386750cb26 to your computer and use it in GitHub Desktop.
Download all Adobe Creative Cloud files in one go
This file contains 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
#!/usr/bin/env node | |
const fetch = require('node-fetch'); | |
const { createWriteStream } = require('fs'); | |
const fs = require('fs').promises; | |
const path = require('path'); | |
const folderId = process.argv[2]; | |
const target = path.resolve(process.cwd(), process.argv[3]); | |
const logFile = createWriteStream("cc-download.log", "utf8"); | |
downloadFolder(target, `https://public.adobecc.com/files/${folderId}`); | |
process.on('exit', () => { | |
try { | |
logFile.close(); | |
}catch (err) {} | |
}); | |
process.on('beforeExit', () => { | |
try { | |
logFile.close(); | |
}catch (err) {} | |
}); | |
async function downloadFolder(path, baseUrl) { | |
logFile.write(`[Folder] ${baseUrl} => ${path}\n`); | |
await fs.mkdir(path, { recursive: true }); | |
const res = await fetch(encodeURI(baseUrl)); | |
const body = await res.json(); | |
const jobs = []; | |
for (const item of body.children) { | |
if (item.type === "application/vnd.adobe.directory+json") { | |
const url = `${baseUrl}/${item.name}`; | |
jobs.push(downloadFolder(`${path}/${item.name}`, url).catch(err => { | |
console.error(err); | |
logFile.write(`[Folder] Error: ${url}:\n`); | |
logFile.write(`${err.toString()}\n`); | |
})); | |
}else { | |
const url = `${baseUrl}/${item.name}`; | |
jobs.push(downloadFile(`${path}/${item.name}`, url).catch(err => { | |
console.error(err); | |
logFile.write(`[File] Error: ${url}:\n`); | |
logFile.write(`${err.toString()}\n`); | |
})); | |
} | |
} | |
await Promise.all(jobs); | |
} | |
async function downloadFile(path, url) { | |
logFile.write(`[File] ${url} => ${path} (Start)\n`); | |
const out = createWriteStream(path); | |
const res = await fetch(encodeURI(url)); | |
res.body.pipe(out); | |
res.body.on('end', () => { | |
logFile.write(`[File] ${url} => ${path} (Stop)\n`); | |
}); | |
res.body.on('error', err => { | |
console.error(err); | |
logFile.write(`[File] Error: ${url}\n`); | |
logFile.write(`${err.toString()}\n`); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment