From 26bef76aaa80e0170164ba4184923c76aa33a280 Mon Sep 17 00:00:00 2001 From: Ramadan <90788933+mu-ramadan@users.noreply.github.com> Date: Thu, 14 Jul 2022 18:00:47 +0400 Subject: [PATCH] Update matterport-dl.py --- matterport-dl.py | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/matterport-dl.py b/matterport-dl.py index 64890c498..ee2577958 100644 --- a/matterport-dl.py +++ b/matterport-dl.py @@ -1,8 +1,10 @@ #!/usr/bin/env python3 + ''' Downloads virtual tours from matterport. Usage is either running this program with the URL/pageid as an argument or calling the initiateDownload(URL/pageid) method. ''' + import uuid import requests import json @@ -21,6 +23,7 @@ from http.server import HTTPServer, SimpleHTTPRequestHandler import decimal + # Weird hack accessurls = [] SHOWCASE_INTERNAL_NAME = "showcase-internal.js" @@ -229,12 +232,8 @@ def setAccessURLs(pageid): def downloadInfo(pageid): -<<<<<<< Updated upstream - assets = [f"api/v1/jsonstore/model/highlights/{pageid}", f"api/v1/jsonstore/model/Labels/{pageid}", f"api/v1/jsonstore/model/mattertags/{pageid}", f"api/v1/jsonstore/model/measurements/{pageid}", f"api/v1/player/models/{pageid}/thumb?width=1707&dpr=1.5&disable=upscale", f"api/v1/player/models/{pageid}/", f"api/v2/models/{pageid}/sweeps", "api/v2/users/current", f"api/player/models/{pageid}/files"] -======= assets = [f"api/v1/jsonstore/model/highlights/{pageid}", f"api/v1/jsonstore/model/Labels/{pageid}", f"api/v1/jsonstore/model/mattertags/{pageid}", f"api/v1/jsonstore/model/measurements/{pageid}", f"api/v1/player/models/{pageid}/thumb?width=1707&dpr=1.5&disable=upscale", f"api/v1/player/models/{pageid}/", f"api/v2/models/{pageid}/sweeps", "api/v2/users/current", f"api/player/models/{pageid}/files", f"api/v1/jsonstore/model/trims/{pageid}"] ->>>>>>> Stashed changes with concurrent.futures.ThreadPoolExecutor(max_workers=16) as executor: for asset in assets: local_file = asset @@ -272,18 +271,6 @@ def downloadModel(pageid, accessurl): downloadSweeps(accessurl, modeldata["sweeps"]) -def progressbar(it, prefix="", size=60, out=sys.stdout): # Python3.6+ - count = len(it) - def show(j): - x = int(size*j/count) - print(f"{prefix}[{u'█'*x}{('.'*(size-x))}] {j}/{count}", end='\r', file=out, flush=True) - show(0) - for i, item in enumerate(it): - yield item - show(i+1) - print("\n", flush=True, file=out) - - # Patch showcase.js to fix expiration issue def patchShowcase(): global SHOWCASE_INTERNAL_NAME @@ -455,18 +442,12 @@ def downloadPage(pageid): # Automatic redirect if GET param isn't correct -<<<<<<< Updated upstream - injectedjs = 'if (window.location.search != "?m=' + pageid + '") { document.location.search = "?m=' + pageid + '"; }' - content = r.text.replace(staticbase,".").replace('"https://cdn-1.matterport.com/','`${window.location.origin}${window.location.pathname}` + "').replace('"https://mp-app-prod.global.ssl.fastly.net/','`${window.location.origin}${window.location.pathname}` + "').replace("window.MP_PREFETCHED_MODELDATA",f"{injectedjs};window.MP_PREFETCHED_MODELDATA").replace('"https://events.matterport.com/', '`${window.location.origin}${window.location.pathname}` + "') - content = re.sub(r"validUntil\":\s*\"20[\d]{2}-[\d]{2}-[\d]{2}T","validUntil\":\"2099-01-01T",content) -======= injectedjs = 'if (window.location.search != "?m=' + pageid + \ '") { document.location.search = "?m=' + pageid + '"; }' content = r.text.replace(staticbase, ".").replace('"https://cdn-1.matterport.com/', '`${window.location.origin}${window.location.pathname}` + "').replace('"https://mp-app-prod.global.ssl.fastly.net/', '`${window.location.origin}${window.location.pathname}` + "').replace( "window.MP_PREFETCHED_MODELDATA", f"{injectedjs};window.MP_PREFETCHED_MODELDATA").replace('"https://events.matterport.com/', '`${window.location.origin}${window.location.pathname}` + "').replace('"https://cdn-2.matterport.com/', '`${window.location.origin}${window.location.pathname}` + "') content = re.sub( r"validUntil\":\s*\"20[\d]{2}-[\d]{2}-[\d]{2}T", "validUntil\":\"2099-01-01T", content) ->>>>>>> Stashed changes with open("index.html", "w", encoding="UTF-8") as f: f.write(content) @@ -644,4 +625,4 @@ def getCommandLineArg(name, has_value): (sys.argv[2], int(sys.argv[3])), OurSimpleHTTPRequestHandler) httpd.serve_forever() else: - print(f"Usage:\n\tFirst Download: matterport-dl.py [url_or_page_id]\n\tThen launch the server 'matterport-dl.py [url_or_page_id] 127.0.0.1 8080' and open http://127.0.0.1:8080 in a browser\n\t--proxy 127.0.0.1:1234 -- to have it use this web proxy\n\t--advanced-download -- Use this option to try and download the cropped files for dollhouse/floorplan support") \ No newline at end of file + print(f"Usage:\n\tFirst Download: matterport-dl.py [url_or_page_id]\n\tThen launch the server 'matterport-dl.py [url_or_page_id] 127.0.0.1 8080' and open http://127.0.0.1:8080 in a browser\n\t--proxy 127.0.0.1:1234 -- to have it use this web proxy\n\t--advanced-download -- Use this option to try and download the cropped files for dollhouse/floorplan support")