Dropbox per-file extraction utility (headless browser)
Browse files- dbx_extract.py +91 -0
dbx_extract.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Extract the authors' blank-image intervention results.csv (51 MB) from their
|
| 2 |
+
~110 GB Dropbox folder share without downloading the whole zip.
|
| 3 |
+
|
| 4 |
+
Method: headless Chromium (playwright) opens the shared-folder page, the folder
|
| 5 |
+
listing is fetched in-page via the page's own XHR endpoint
|
| 6 |
+
(POST https://www.dropbox.com/list_shared_link_folder_entries with the session
|
| 7 |
+
`t` cookie token, link_key, link_type=c, per-level secure_hash taken from each
|
| 8 |
+
entry's href, and sub_path), the walk descends
|
| 9 |
+
coco/n5k/llava1.5-13b/260821_165830/intervene_outputs_blank_image/<ts>/model_outputs,
|
| 10 |
+
and the file is downloaded by navigating to its per-file href with dl=1 and
|
| 11 |
+
capturing the download event (a direct ctx.request.get returns an empty body).
|
| 12 |
+
|
| 13 |
+
Edit FOLDER_URL / PATH_WANT to pull a different run. Requires: pip install playwright && playwright install chromium.
|
| 14 |
+
"""
|
| 15 |
+
# Full working implementation as used on 2026-12-01 (dbx_dl4.py in the sandbox):
|
| 16 |
+
import json, re, os, sys, urllib.parse
|
| 17 |
+
from playwright.sync_api import sync_playwright
|
| 18 |
+
|
| 19 |
+
FOLDER_URL = "https://www.dropbox.com/scl/fo/5tehguwaibysgx0w9k2eu/AItuSz66ezdheipHP_inaxo?rlkey=vofik4ofetrzd9gp5es26qu4v&st=j2iskvkc&dl=0"
|
| 20 |
+
LINK_KEY = "5tehguwaibysgx0w9k2eu"
|
| 21 |
+
RLKEY = "vofik4ofetrzd9gp5es26qu4v"
|
| 22 |
+
OUT = "/work/raw/blank"
|
| 23 |
+
os.makedirs(OUT, exist_ok=True)
|
| 24 |
+
# None = "first directory entry" (the run-timestamp folders)
|
| 25 |
+
PATH_WANT = ["coco", "n5k", "llava1.5-13b", None, "intervene_outputs_blank_image", None, "model_outputs"]
|
| 26 |
+
|
| 27 |
+
def hash_from(href):
|
| 28 |
+
m = re.search(r"/scl/fo/[^/]+/([^/?&]+)", href or "")
|
| 29 |
+
return m.group(1) if m else None
|
| 30 |
+
|
| 31 |
+
with sync_playwright() as p:
|
| 32 |
+
browser = p.chromium.launch(headless=True, args=["--no-sandbox"])
|
| 33 |
+
ctx = browser.new_context(accept_downloads=True, viewport={"width": 1600, "height": 1000})
|
| 34 |
+
page = ctx.new_page()
|
| 35 |
+
page.goto(FOLDER_URL, wait_until="domcontentloaded", timeout=60000)
|
| 36 |
+
try:
|
| 37 |
+
page.wait_for_load_state("networkidle", timeout=30000)
|
| 38 |
+
except Exception:
|
| 39 |
+
pass
|
| 40 |
+
page.wait_for_timeout(8000)
|
| 41 |
+
t = next((c["value"] for c in ctx.cookies() if c["name"] == "t"), "")
|
| 42 |
+
|
| 43 |
+
def list_dir(secure_hash, sub_path):
|
| 44 |
+
body = urllib.parse.urlencode({"is_xhr": "true", "t": t, "link_key": LINK_KEY,
|
| 45 |
+
"link_type": "c", "secure_hash": secure_hash, "sub_path": sub_path, "rlkey": RLKEY})
|
| 46 |
+
r = page.evaluate("""async (body) => {
|
| 47 |
+
const r = await fetch('/list_shared_link_folder_entries', {
|
| 48 |
+
method: 'POST', headers: {'content-type': 'application/x-www-form-urlencoded'},
|
| 49 |
+
body: body, credentials: 'same-origin'});
|
| 50 |
+
return {status: r.status, body: await r.text()};
|
| 51 |
+
}""", body)
|
| 52 |
+
try:
|
| 53 |
+
return r["status"], json.loads(r["body"])
|
| 54 |
+
except Exception:
|
| 55 |
+
return r["status"], {"raw": r["body"][:200]}
|
| 56 |
+
|
| 57 |
+
secure_hash = "AItuSz66ezdheipHP_inaxo" # the folder key segment of the share URL
|
| 58 |
+
sub_path = ""
|
| 59 |
+
tgt = None
|
| 60 |
+
for step in range(len(PATH_WANT) + 2):
|
| 61 |
+
st, j = list_dir(secure_hash, sub_path)
|
| 62 |
+
entries = j.get("entries")
|
| 63 |
+
if st != 200 or not isinstance(entries, list):
|
| 64 |
+
print("FAIL at", repr(sub_path), st, str(j)[:300]); sys.exit(1)
|
| 65 |
+
dirs = [e for e in entries if e.get("is_dir")]
|
| 66 |
+
files = [e for e in entries if not e.get("is_dir")]
|
| 67 |
+
if step == len(PATH_WANT):
|
| 68 |
+
tgt = next((e for e in files if e.get("filename") == "results.csv"), None)
|
| 69 |
+
if not tgt:
|
| 70 |
+
print("no results.csv"); sys.exit(1)
|
| 71 |
+
break
|
| 72 |
+
want = PATH_WANT[step]
|
| 73 |
+
nxt = (dirs[0] if dirs else None) if want is None else next((e for e in dirs if e.get("filename") == want), None)
|
| 74 |
+
if not nxt:
|
| 75 |
+
print("cannot find", want, "at", repr(sub_path)); sys.exit(1)
|
| 76 |
+
sub_path = (sub_path + "/" + nxt["filename"]) if sub_path else nxt["filename"]
|
| 77 |
+
secure_hash = hash_from(nxt.get("href")) or secure_hash
|
| 78 |
+
|
| 79 |
+
href = tgt.get("href") or ""
|
| 80 |
+
print("HREF:", href[:160])
|
| 81 |
+
dl_url = href.replace("dl=0", "dl=1")
|
| 82 |
+
path = os.path.join(OUT, "results.csv")
|
| 83 |
+
with page.expect_download(timeout=300000) as dlinfo:
|
| 84 |
+
try:
|
| 85 |
+
page.goto(dl_url, wait_until="commit", timeout=60000)
|
| 86 |
+
except Exception as e:
|
| 87 |
+
print("goto note:", str(e)[:150]) # expected: "Download is starting"
|
| 88 |
+
d = dlinfo.value
|
| 89 |
+
d.save_as(path)
|
| 90 |
+
print("SAVED", os.path.getsize(path), "bytes")
|
| 91 |
+
browser.close()
|