diff --git a/downloadall.py b/downloadall.py new file mode 100755 index 0000000..b5466fd --- /dev/null +++ b/downloadall.py @@ -0,0 +1,38 @@ +#! /usr/bin/env python3 +import subprocess +import os, sys +import requests, json + +# Define a little write() helper +def fwrite(path:str, data, mode="w"): + with open(path, mode=mode) as f: + f.write(data) + +# Check argv +if len(sys.argv) < 3: + os.write(2, f"Usage: {argv[0]} \n") + sys.exit(1); +destpath = sys.argv[1] + +# Try accessing/writing to given path +os.listdir(destpath) +fwrite(destpath + "/rwtest", "It works!") +os.remove(destpath + "/rwtest") + +# Run program +proc = subprocess.Popen([os.path.dirname(os.path.abspath(__file__))+'/bin/CommSyFuse', 'json'] + sys.argv[2:], stdout=subprocess.PIPE) + +# Generate folder/file structure +os.chdir(destpath) +for entry in json.load(proc.stdout): + # Create and switch to new directory + os.mkdir(entry["name"]) + os.chdir(entry["name"]) + # Write description + fwrite("info.txt", entry["meta"] + "\n\n" + entry["description"]) + # Download files + for file in entry["files"]: + print("Downloading:", file["url"]) + fwrite(file["name"], requests.get(file["url"], cookies=dict(SID=sys.argv[2])).content, mode="wb") + # Switch back + os.chdir("..") diff --git a/main.cpp b/main.cpp index 9d8c08f..92bf375 100644 --- a/main.cpp +++ b/main.cpp @@ -381,12 +381,12 @@ int mode_tmpl(mode_json) { jsonroot[it]["name"] = postsmap_numname[it]; jsonroot[it]["meta"] = postsmap_nummeta[it]; jsonroot[it]["description"] = postsmap_numdesc[it]; - jsonroot[it]["url"] = postsmap_numurl[it]; + jsonroot[it]["url"] = server_url + postsmap_numurl[it]; jsonroot[it]["files"] = json::array(); for (unsigned long it2 = 0; it2 != postsmap_numfileurls[it].size(); it2++) { jsonroot[it]["files"][it2] = json::object(); jsonroot[it]["files"][it2]["name"] = postsmap_numfilenames[it][it2]; - jsonroot[it]["files"][it2]["url"] = postsmap_numfileurls[it][it2]; + jsonroot[it]["files"][it2]["url"] = server_url + postsmap_numfileurls[it][it2]; } } // Serialise to cout...